Пример #1
0
    def _createTrackView(self,
                         starts,
                         ends,
                         vals,
                         strands,
                         ids,
                         edges,
                         weights,
                         extras,
                         sourceRegion,
                         allowOverlaps,
                         sliceFull=False):
        genomeAnchor = GenomeRegion(genome=self.genome,
                                    chr=self.chr,
                                    start=sourceRegion[0],
                                    end=sourceRegion[1])

        tv = TrackView(genomeAnchor, \
                       array(starts) if starts is not None else None, \
                       array(ends) if ends is not None else None, \
                       array(vals, dtype='float64') if vals is not None else None, \
                       array(strands) if strands is not None else None, \
                       array(ids) if ids is not None else None, \
                       array(edges) if edges is not None else None, \
                       array(weights) if weights is not None else None, \
                       'crop', allowOverlaps, \
                       extraLists=OrderedDict([(key, array(extra)) for key, extra in extras.iteritems()]) if extras is not None else OrderedDict())
        if sliceFull:
            tv.sliceElementsAccordingToGenomeAnchor()
        return tv
Пример #2
0
 def _createTrackView(self, starts, ends, vals, strands, ids, edges, weights, extras, sourceRegion, allowOverlaps, sliceFull=False):
     genomeAnchor = GenomeRegion(genome=self.genome, chr=self.chr, start=sourceRegion[0], end=sourceRegion[1])
     
     tv = TrackView(genomeAnchor, \
                    array(starts) if starts is not None else None, \
                    array(ends) if ends is not None else None, \
                    array(vals, dtype='float64') if vals is not None else None, \
                    array(strands) if strands is not None else None, \
                    array(ids) if ids is not None else None, \
                    array(edges) if edges is not None else None, \
                    array(weights) if weights is not None else None, \
                    'crop', allowOverlaps, \
                    extraLists=OrderedDict([(key, array(extra)) for key, extra in extras.iteritems()]) if extras is not None else OrderedDict())
     if sliceFull:
         tv.sliceElementsAccordingToGenomeAnchor()
     return tv
Пример #3
0
 def loadTrackView(trackData, region, borderHandling, allowOverlaps, trackName=[]):
     """
     trackData : see TrackSource.getTrackData {'id' : smartmemmap}
     region : see GenomeRegion
     """
     #brShelve = BoundingRegionShelve(region.genome, trackName, allowOverlaps)
     brShelve = trackData.boundingRegionShelve
     brInfo = brShelve.getBoundingRegionInfo(region) if brShelve is not None else None
     
     extraArrayNames = [arrayName for arrayName in trackData if arrayName not in \
                        RESERVED_PREFIXES.keys() + ['leftIndex', 'rightIndex']]
     
     reservedArrays = [TrackViewLoader._getArray(trackData, arrayName, brInfo) for arrayName in RESERVED_PREFIXES]
     extraArrays = [TrackViewLoader._getArray(trackData, arrayName, brInfo) for arrayName in extraArrayNames]
     trackFormat = TrackFormat( *(reservedArrays + [OrderedDict(zip(extraArrayNames, extraArrays))]) )
     
     if trackFormat.reprIsDense():
         if brInfo is None:
             leftIndex = region.start
             rightIndex = region.end
         else:
             leftIndex = region.start - brInfo.start
             rightIndex = region.end - brInfo.start 
     else:
         leftBin = CompBinManager.getBinNumber(region.start)
         rightBin = CompBinManager.getBinNumber(region.end-1)
         #leftBin = region.start/COMP_BIN_SIZE
         #rightBin = (region.end-1)/COMP_BIN_SIZE
         
         if trackData.get('leftIndex') is None or trackData.get('rightIndex') is None:
             raise IOError('Preprocessed track not found. TrackData: ' + ', '.join(trackData.keys()))
         
         leftIndex = TrackViewLoader._getArray(trackData, 'leftIndex', brInfo, leftBin)
         rightIndex = TrackViewLoader._getArray(trackData, 'rightIndex', brInfo, rightBin)
     
     slicedReservedArrays = [(array[leftIndex:rightIndex] if array is not None else None) for array in reservedArrays]
     slicedExtraArrays = [(array[leftIndex:rightIndex] if array is not None else None) for array in extraArrays]
     
     argList = [region] + slicedReservedArrays + [borderHandling, allowOverlaps] + [OrderedDict(zip(extraArrayNames, slicedExtraArrays))]
     tv = TrackView( *(argList) )
     
     if not trackFormat.reprIsDense():
         tv.sliceElementsAccordingToGenomeAnchor()
         #tv._doScatteredSlicing()
     return tv