Cache result of getLocation() in Shard so we don't performance expensive calculation over and over
This commit is contained in:
parent
4d0e7b50ec
commit
ddcb33fcf8
|
|
@ -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,27 +151,34 @@ 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 ( getGenomeLocs() == null )
|
if ( spanningLocation == null ) {
|
||||||
return GenomeLoc.WHOLE_GENOME;
|
if ( getGenomeLocs() == null )
|
||||||
|
spanningLocation = GenomeLoc.WHOLE_GENOME;
|
||||||
|
else if ( getGenomeLocs().size() == 0 ) {
|
||||||
|
spanningLocation = getGenomeLocs().get(0);
|
||||||
|
} else {
|
||||||
|
int start = Integer.MAX_VALUE;
|
||||||
|
int stop = Integer.MIN_VALUE;
|
||||||
|
String contig = null;
|
||||||
|
|
||||||
int start = Integer.MAX_VALUE;
|
for ( GenomeLoc loc : getGenomeLocs() ) {
|
||||||
int stop = Integer.MIN_VALUE;
|
if ( GenomeLoc.isUnmapped(loc) )
|
||||||
String contig = null;
|
// special case the unmapped region marker, just abort out
|
||||||
|
return loc;
|
||||||
|
contig = loc.getContig();
|
||||||
|
if ( loc.getStart() < start ) start = loc.getStart();
|
||||||
|
if ( loc.getStop() > stop ) stop = loc.getStop();
|
||||||
|
}
|
||||||
|
|
||||||
for ( GenomeLoc loc : getGenomeLocs() ) {
|
spanningLocation = parser.createGenomeLoc(contig, start, stop);
|
||||||
if ( GenomeLoc.isUnmapped(loc) )
|
}
|
||||||
// special case the unmapped region marker, just abort out
|
|
||||||
return loc;
|
|
||||||
contig = loc.getContig();
|
|
||||||
if ( loc.getStart() < start ) start = loc.getStart();
|
|
||||||
if ( loc.getStop() > stop ) stop = loc.getStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parser.createGenomeLoc(contig, start, stop);
|
return spanningLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue