def testBoundingRegionsChrInUnsortedOrder(self): self._setUpShelve() brTuples = [BoundingRegionTuple(GenomeRegion('TestGenome', 'chrM', 1000, 2000), 5), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 1000000), 10), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 2000000, 2500000), 20)] self._brShelve.storeBoundingRegions(brTuples, ['chr21', 'chrM'], sparse=True)
def _decorateGESource(self, geSource): brRegionList = geSource.getBoundingRegionTuples() if self._countElsInBoundingRegions: brTuples = [BoundingRegionTuple(region, 0) for region in brRegionList] return GEBoundingRegionElementCounter(geSource, brTuples) else: brTuples = [BoundingRegionTuple(region, len(region)) for region in self._brRegionList] return BrTuplesGESourceWrapper(geSource, brTuples)
def testBoundingRegionsUnsortedInChr(self): self._setUpShelve() brTuples = [BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 2000000, 2500000), 20),\ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 1000000), 10)] self.assertRaises(InvalidFormatError, self._brShelve.storeBoundingRegions, brTuples, ['chr21'], sparse=True)
def testBoundingRegionIncorrectCountDense(self): self._setUpShelve() brTuples = [BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 1000000), 1000000), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 2000000, 2500000), 500000), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chrM', 1000, 2000), 500)] self.assertRaises(InvalidFormatError, self._brShelve.storeBoundingRegions, brTuples, ['chr21', 'chrM'], sparse=False)
def _getIter(elList, valDataType, valDim, edgeWeightDataType, edgeWeightDim, brList=[]): geIter = MyGeIter(valDataType, valDim, edgeWeightDataType, edgeWeightDim) for i in xrange(len(elList)): ge = GenomeElement(genome=elList[i][0], chr=elList[i][1], start=elList[i][2], end=elList[i][3]) if len(elList[i]) == 5: for prefix in elList[i][4]: setattr(ge, prefix, elList[i][4][prefix]) geIter.iter.append(ge) for i in xrange(len(brList)): br = GenomeRegion(genome=brList[i][0], chr=brList[i][1], start=brList[i][2], end=brList[i][3]) geIter.boundingRegionTuples.append( BoundingRegionTuple(br, brList[i][4])) return geIter
def _appendBoundingRegionTuple(self): #if self._genomeElement.chr is not None: # brRegion = GenomeRegion(self._genome, self._genomeElement.chr, 0, self._elCount) if self._chr is not None: brRegion = GenomeRegion(self._genome, self._chr, 0, self._elCount) self._boundingRegionTuples.append( BoundingRegionTuple(brRegion, self._elCount))
def _appendBoundingRegionTuple(self): boundingRegion = GenomeRegion(genome=self._genome, chr=self._chr, start=self._start, \ end=self._getEnd(self._getFixedStepCurElStart())) elCount = self._curElCountInBoundingRegion + (1 if self._isStepFunction else 0) self._boundingRegionTuples.append( BoundingRegionTuple(boundingRegion, elCount))
def testBoundingRegionsNotPositive(self): self._setUpShelve() brTuples = [ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 0), 1) ] self.assertRaises(InvalidFormatError, self._brShelve.storeBoundingRegions, brTuples, ['chr21'], sparse=True)
def getBoundingRegionTuples(self): if self._boundingRegionTuples is None: track = self._getTrack() self._boundingRegionTuples = [] for region,tv in ((region, self._getTrackView(track, region)) for region in self._boundingRegions): self._boundingRegionTuples.append(BoundingRegionTuple(region, tv.getNumElements())) #self._removeBoundingRegionTuplesIfFullChrsAndNotFixedGapSize() return self._boundingRegionTuples
def testGetBoundingInfoEmptyBoundingRegionSparse(self): self._setUpShelve() brTuples = [BoundingRegionTuple(GenomeRegion('TestGenome', 'chrM', 1000, 2000), 0), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 1000000), 10), \ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 2000000, 2500000), 20)] self._brShelve.storeBoundingRegions(brTuples, ['chr21'], sparse=True) self.assertEquals( BoundingRegionInfo(0, 1000000, 0, 30, 0, 470), self._brShelve.getBoundingRegionInfo( GenomeRegion('TestGenome', 'chr21', 50000, 52000))) self.assertEquals( BoundingRegionInfo(2000000, 2500000, 0, 30, 0, 470), self._brShelve.getBoundingRegionInfo( GenomeRegion('TestGenome', 'chr21', 2050000, 2052000))) self.assertEquals( BoundingRegionInfo(1000, 2000, 0, 0, 0, 0), self._brShelve.getBoundingRegionInfo( GenomeRegion('TestGenome', 'chrM', 1000, 2000)))
def getBoundingRegionTuples(self): boundingRegionTuples = [x for x in self._getBoundingRegionTuples() \ if x.region.chr is not None] if len(boundingRegionTuples) == 0: from gtrackcore.input.core.GenomeElementSource import BoundingRegionTuple from gtrackcore.track.core.GenomeRegion import GenomeRegion from gtrackcore.metadata.GenomeInfo import GenomeInfo geChrList = self.getAllChrs() boundingRegionTuples = [BoundingRegionTuple( \ GenomeRegion(chr=chr, start=0, end=GenomeInfo.getChrLen(self._geSource.genome, chr)), \ self.getNumElementsForChr(chr) ) \ for chr in geChrList] self._boundingRegionsAndGEsCorrespond = False else: self._boundingRegionsAndGEsCorrespond = True return boundingRegionTuples
def getBoundingRegionTuples(self): return [ BoundingRegionTuple( GenomeRegion(genome='TestGenome', chr='chr21', start=0, end=1), 1) ]
tv = self._getTrackView(trackName, region, allowOverlaps) self.assertEquals(chrElCountDict[chr], len([x for x in tv])) def _getTrackView(self, trackName, region, allowOverlaps): track = Track(trackName) track.addFormatReq(TrackFormatReq(allowOverlaps=allowOverlaps)) return track.getTrackView(region) def _getBoundingRegionTupleList(self, case, sortedAssertElList): boundingRegions = [ br for br in sorted(case.boundingRegionsAssertList) if br.region.chr is not None ] if len(boundingRegions) > 0: return [BoundingRegionTuple(GenomeRegion(self.GENOME, chr=br.region.chr, \ start=br.region.start if br.region.start is not None else 0, \ end=br.region.end if br.region.end is not None else \ GenomeInfo.getChrLen(self.GENOME, br.region.chr)), br.elCount) for br in boundingRegions] else: totChrList = [ge.chr for ge in sortedAssertElList] chrBrList = OrderedDict([(i, totChrList.count(i)) for i in sorted(set(totChrList))]) return [BoundingRegionTuple(GenomeRegion(self.GENOME, chr=chr, start=0, \ end=GenomeInfo.getChrLen(self.GENOME, chr)), elCount) \ for chr, elCount in chrBrList.iteritems()] def _getCaseTrackView(self, case, br, allowOverlaps): return self._getTrackView(self.TRACK_NAME_PREFIX + case.trackName, \ GenomeRegion(genome=self.GENOME, chr=br.chr, start=br.start, end=br.end), \ allowOverlaps=allowOverlaps)
def _commonStoreBoundingRegions(self, sparse): brTuples = [BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 0, 1000000), 10 if sparse else 1000000),\ BoundingRegionTuple(GenomeRegion('TestGenome', 'chr21', 2000000, 2500000), 20 if sparse else 500000),\ BoundingRegionTuple(GenomeRegion('TestGenome', 'chrM', 1000, 2000), 5 if sparse else 1000)] self._brShelve.storeBoundingRegions(brTuples, ['chr21', 'chrM'], sparse)
def getBoundingRegionTuples(self): if self._boundingRegionTuples is None: self._boundingRegionTuples = [BoundingRegionTuple(tv.genomeAnchor, tv.getNumElements()) for tv in self._trackViewDict.values()] #self._removeBoundingRegionTuplesIfFullChrsAndNotFixedGapSize() return self._boundingRegionTuples