diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/reads/BinTree.java b/java/src/org/broadinstitute/sting/gatk/datasources/reads/BinTree.java index a379ac761..5f3e246d1 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/reads/BinTree.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/reads/BinTree.java @@ -59,15 +59,6 @@ public class BinTree { this.bins = bins; } - public GATKBin getLowestLevelBin() { - for(int i = bins.length-1; i >= 0; i--) { - if(bins[i] != null) - return bins[i]; - } - return null; - } - - /** * Retrieve the bins from the bin tree. * @return list of bins. @@ -84,6 +75,31 @@ public class BinTree { return bins.length; } + /** + * Returns the start of the region covered by this bin tree. + * @return Start of the region covered by this bin tree. + */ + public int getStart() { + return binTreeStart; + } + + /** + * Returns the end of the region covered by this bin tree. + * @return End of the region covered by this bin tree. + */ + public int getStop() { + return binTreeStop; + } + + /** + * Returns true if the location of this bin tree is before the given position. + * @param locus Locus to test. + * @return True if this bin sits completely before the given locus; false otherwise. + */ + public boolean isBefore(final GenomeLoc locus) { + return binTreeStop < locus.getStart(); + } + /** * Checks overlap between this bin tree and other bin trees. * @param position the position over which to detect overlap. diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/reads/LowMemoryIntervalSharder.java b/java/src/org/broadinstitute/sting/gatk/datasources/reads/LowMemoryIntervalSharder.java index e44261d63..bde5cb9f7 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/reads/LowMemoryIntervalSharder.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/reads/LowMemoryIntervalSharder.java @@ -95,8 +95,8 @@ public class LowMemoryIntervalSharder implements Iterator { GATKBAMIndex index = (GATKBAMIndex)dataSource.getIndex(reader); BinTree binTree = getNextOverlappingBinTree((GATKBAMIndex)dataSource.getIndex(reader),currentLocus); if(binTree != null) { - coveredRegionStart = Math.max(coveredRegionStart,index.getFirstLocusInBin(binTree.getLowestLevelBin().toBin())); - coveredRegionStop = Math.min(coveredRegionStop,index.getLastLocusInBin(binTree.getLowestLevelBin().toBin())); + coveredRegionStart = Math.max(coveredRegionStart,binTree.getStart()); + coveredRegionStop = Math.min(coveredRegionStop,binTree.getStop()); coveredRegion = loci.getGenomeLocParser().createGenomeLoc(currentLocus.getContig(),coveredRegionStart,coveredRegionStop); GATKBAMFileSpan fileSpan = generateFileSpan(index,binTree,currentLocus); @@ -164,7 +164,7 @@ public class LowMemoryIntervalSharder implements Iterator { return null; BinTree binTree = binTreeIterator.peek(); - while(index.getLastLocusInBin(binTree.getLowestLevelBin().toBin()) < locus.getStart()) { + while(binTree.isBefore(locus)) { binTreeIterator.next(); // Before the point of interest. Consume this one. binTree = binTreeIterator.peek(); } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/reads/ReadShardStrategy.java b/java/src/org/broadinstitute/sting/gatk/datasources/reads/ReadShardStrategy.java index 456293134..4b85c61d3 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/reads/ReadShardStrategy.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/reads/ReadShardStrategy.java @@ -96,7 +96,7 @@ public class ReadShardStrategy implements ShardStrategy { this.locations = locations; if(locations != null) - filePointerIterator = IntervalSharder.shardIntervals(this.dataSource,locations); + filePointerIterator = SAMDataSource.TRY_LOW_MEMORY_SHARDING ? new LowMemoryIntervalSharder(this.dataSource,locations) : IntervalSharder.shardIntervals(this.dataSource,locations); else filePointerIterator = filePointers.iterator();