Cache result of getLocation() in Shard so we don't performance expensive calculation over and over

This commit is contained in:
Mark DePristo 2013-01-16 12:09:36 -05:00
parent 4d0e7b50ec
commit ddcb33fcf8
1 changed files with 26 additions and 16 deletions

View File

@ -95,7 +95,10 @@ public abstract class Shard implements HasGenomeLocation {
*/ */
private final Map<SAMReaderID,SAMFileSpan> fileSpans; private final Map<SAMReaderID,SAMFileSpan> fileSpans;
/**
* Lazy-calculated span of all of the genome locs in this shard
*/
private GenomeLoc spanningLocation = null;
/** /**
* Statistics about which reads in this shards were used and which were filtered away. * Statistics about which reads in this shards were used and which were filtered away.
@ -148,13 +151,16 @@ public abstract class Shard implements HasGenomeLocation {
/** /**
* Returns the span of the genomeLocs comprising this shard * Returns the span of the genomeLocs comprising this shard
* @param * @return a GenomeLoc that starts as the first position in getGenomeLocs() and stops at the stop of the last
* @return * position in getGenomeLocs()
*/ */
public GenomeLoc getLocation() { public GenomeLoc getLocation() {
if ( spanningLocation == null ) {
if ( getGenomeLocs() == null ) if ( getGenomeLocs() == null )
return GenomeLoc.WHOLE_GENOME; spanningLocation = GenomeLoc.WHOLE_GENOME;
else if ( getGenomeLocs().size() == 0 ) {
spanningLocation = getGenomeLocs().get(0);
} else {
int start = Integer.MAX_VALUE; int start = Integer.MAX_VALUE;
int stop = Integer.MIN_VALUE; int stop = Integer.MIN_VALUE;
String contig = null; String contig = null;
@ -168,7 +174,11 @@ public abstract class Shard implements HasGenomeLocation {
if ( loc.getStop() > stop ) stop = loc.getStop(); if ( loc.getStop() > stop ) stop = loc.getStop();
} }
return parser.createGenomeLoc(contig, start, stop); spanningLocation = parser.createGenomeLoc(contig, start, stop);
}
}
return spanningLocation;
} }