def updateGeneName(dFN,
                   fFN,
                   wigDir,
                   chrom,
                   strand,
                   prefix,
                   switchStrand=False):

    NX = Nexus(dFN, fFN)
    NX.load(['geneNames', 'tcc'])

    if switchStrand:
        strand = -strand

    strand = str(strand)
    coord_gName = cgWig.loadSingleWigTranscript(wigDir, chrom, strand, prefix)

    while NX.nextID():

        chrom, strand, start, end = bioLibCG.tccSplit(NX.tcc)

        overlappingGenes = coord_gName.get(start, ".")
        if overlappingGenes == "NONE":
            NX.geneNames = []
        else:
            NX.geneNames = overlappingGenes.split(',')

    NX.save()
def updateTranscriptOverlap(oFN, wigDir, chrom, strand, rn = None, tn = None):
        
        oNX = cgNexusFlat.Nexus(oFN, cgDegPeak.Peak)
        oNX.load(['tOverlap', 'tcc'], [rn, tn])

        #load the AS wig file for this degradome strand
        if strand == '1':
                strand = '-1'
        else:
                strand = '1'
        
        coord_transcripts = cgWig.loadSingleWigTranscript(wigDir, chrom, strand, 'transcript')

        for oID in oNX.tOverlap:

                
                tChrom, tStrand, start, end = bioLibCG.tccSplit(oNX.tcc[oID])
                if tStrand == '1':
                        tStrand = '-1'
                else:
                        tStrand = '1'

                if tChrom != chrom or tStrand != strand: continue
                
                oNX.tOverlap[oID] = False
                for i in xrange(start, end + 1):
                        if i in coord_transcripts:
                                oNX.tOverlap[oID] = True
                                break
        

        oNX.save()
def updateTranscriptOverlap(oFN, wigDir, chrom, strand, rn=None, tn=None):

    oNX = cgNexusFlat.Nexus(oFN, cgDegPeak.Peak)
    oNX.load(['tOverlap', 'tcc'], [rn, tn])

    #load the AS wig file for this degradome strand
    if strand == '1':
        strand = '-1'
    else:
        strand = '1'

    coord_transcripts = cgWig.loadSingleWigTranscript(wigDir, chrom, strand,
                                                      'transcript')

    for oID in oNX.tOverlap:

        tChrom, tStrand, start, end = bioLibCG.tccSplit(oNX.tcc[oID])
        if tStrand == '1':
            tStrand = '-1'
        else:
            tStrand = '1'

        if tChrom != chrom or tStrand != strand: continue

        oNX.tOverlap[oID] = False
        for i in xrange(start, end + 1):
            if i in coord_transcripts:
                oNX.tOverlap[oID] = True
                break

    oNX.save()
def updateGeneName(dFN, fFN, wigDir, chrom, strand, prefix, switchStrand = False):

    NX = Nexus(dFN, fFN)
    NX.load(['geneNames', 'tcc'])

    if switchStrand:
        strand = -strand

    strand = str(strand)
    coord_gName = cgWig.loadSingleWigTranscript(wigDir, chrom, strand, prefix)

    while NX.nextID():

        chrom, strand, start, end = bioLibCG.tccSplit(NX.tcc)
        
        overlappingGenes = coord_gName.get(start, ".")
        if overlappingGenes == "NONE":
            NX.geneNames = []
        else:
            NX.geneNames = overlappingGenes.split(',')

    NX.save()