Example #1
0
 def _brtAndGeIterator(self):
     from gtrackcore_memmap.input.wrappers.GEDependentAttributesHolder import iterateOverBRTuplesWithContainedGEs
     brtAndGeIter = iterateOverBRTuplesWithContainedGEs(self._geSource, returnIterator=True)
     
     while True:
         try:
             brt, geIter = brtAndGeIter.next()
         except StopIteration:
             return
         
         for i, ge in enumerate(geIter):
             yield brt, ge, i
Example #2
0
 def _compose(self, out):
     
     for brt, geList in iterateOverBRTuplesWithContainedGEs(self._geSource):
         chr, startEnd = str(brt.region).split(':')
         print >> out, '>%s %s' % (chr, startEnd)
          
         line = ''
         for i, ge in enumerate(geList):
             line += ge.val
             if (i+1) % 60 == 0:
                 print >> out, line
                 line = ''
         
         if i+1 % 60 != 0:
             print >> out, line
Example #3
0
    def _composeContents(self, out, hbColumns, columns, geSource, onlyNonDefault=True, singleDataLine=False):
        tf = TrackFormat.createInstanceFromGeSource(self._geSource)
        out.write(self._composeHeaderLines(onlyNonDefault))
        out.write(self._composeColSpecLine(columns))

        for br, geList in iterateOverBRTuplesWithContainedGEs(geSource, onlyYieldTwoGEs=singleDataLine):
            if br is not None:
                out.write(self._composeBoundingRegionLine(br))

            for i, ge in enumerate(self._removeStartElementIfApplicable(tf, geList)):
                out.write(self._composeDataLine(ge, hbColumns, i + 1, i + 1 == len(geList)))

                if singleDataLine:
                    break
            if singleDataLine:
                break
Example #4
0
def _getSortedBoundingRegionsAndGenomeElements(geSource):
    geSource = GEDependentAttributesHolder(geSource)
    
    doubleElList = [[brTuple, geList] for brTuple, geList in iterateOverBRTuplesWithContainedGEs(geSource)]
    
    noBoundingRegions = doubleElList[0][0] is None
    if not noBoundingRegions:
        doubleElList.sort(key=lambda x:x[0].region)
    
    for x in doubleElList:
        if len(x[1]) >= 2:
            if x[1][0].reprIsDense():
                break
            x[1].sort()
            
    return doubleElList, geSource
Example #5
0
    def _compose(self, out):
        trackName = self._geSource.getTrackName()
        if trackName is not None:
            name = ':'.join(self._geSource.getTrackName()).replace(' ','_')
        else:
            name = None
        
        print >>out, 'track type=wiggle_0' + (' name=%s' % name if name is not None else '')

        tf = TrackFormat.createInstanceFromGeSource(self._geSource)
        span = self._geSource.getFixedLength()
        step = self._geSource.getFixedGapSize() + span
        
        isFixedStep = (tf.reprIsDense() or step > 1 or (step == 1 and span != 1))
        
        for brt, geList in iterateOverBRTuplesWithContainedGEs(self._geSource):
            if len(geList) == 0:
                continue
            
            if isFixedStep:
                self._composeFixedStepDeclarationLine(out, brt.region, step, span)
            else:
                curChr, curSpan = self._composeVariableStepDeclarationLine(out, geList[0])
            
            for i,ge in enumerate(geList):
                if i==0 and tf.isDense() and tf.isInterval() and \
                    self._geSource.addsStartElementToDenseIntervals():
                    continue
                
                val = self._commonFormatNumberVal(ge.val)
                
                if isFixedStep:
                    cols = [val]
                else:
                    if ge.chr != curChr or self._getVariableSpan(ge) != curSpan:
                        curChr, curSpan = self._composeVariableStepDeclarationLine(out, ge)
                    cols = [str(ge.start+1), val]
                
                print >>out, '\t'.join([str(x) for x in cols])