Now has methods that allow to 1) check if a location is within the bounds of the reference view; 2) expand reference view (i.e. expand the bounds and reload the reference sequence) in order to accomodate specified location. The second method can be called directly since it performs a check and if the location is already within the bounds, then returns immediately. The costly ref sequence reloading occurs only when the location is not fully contained within the current bounds.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2542 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
asivache 2010-01-07 22:35:17 +00:00
parent 7f91b4d824
commit e9bc85c188
1 changed files with 28 additions and 1 deletions

View File

@ -41,7 +41,7 @@ public class LocusReferenceView extends ReferenceView {
/**
* Bound the reference view to make sure all accesses are within the shard.
*/
private final GenomeLoc bounds;
private GenomeLoc bounds;
/**
* Start of the expanded window for which the reference context should be provided,
@ -104,6 +104,33 @@ public class LocusReferenceView extends ReferenceView {
}
}
/** Returns true if the specified location is fully within the bounds of the reference window loaded into
* this LocusReferenceView object.
*/
public boolean isLocationWithinBounds(GenomeLoc loc) {
return bounds.containsP(loc);
}
/** Ensures that specified location is within the bounds of the reference window loaded into this
* LocusReferenceView object. If the location loc is within the current bounds (or if it is null), then nothing is done.
* Otherwise, the bounds are expanded on either side, as needed, to accomodate the location, and the reference seuqence for the
* new bounds is reloaded (can be costly!).
* @param loc
*/
public void expandBoundsToAccomodateLoc(GenomeLoc loc) {
if ( bounds==null || loc==null) return; // can bounds be null actually???
if ( isLocationWithinBounds(loc) ) return;
if ( loc.getContigIndex() != bounds.getContigIndex() )
throw new StingException("Illegal attempt to expand reference view bounds to accomodate location on a different contig.");
bounds = GenomeLocParser.createGenomeLoc(bounds.getContigIndex(),
Math.min(bounds.getStart(),loc.getStart()),
Math.max(bounds.getStop(),loc.getStop()));
long expandedStart = getWindowStart( bounds );
long expandedStop = getWindowStop( bounds );
initializeReferenceSequence(GenomeLocParser.createGenomeLoc(bounds.getContig(), expandedStart, expandedStop));
}
/**
* Initialize reference sequence data using the given locus.
* @param locus