LocusReferenceView: If the locus a view is requested for spans beyond the reference contig ends, create the actual window bounded by contig ends (so that the locus will not be fully contained in the window!!).

ReferenceContext: constructor does not throw an excepion anymore when locus is not fully contained inside the window. So now we can have a reference context associated with a locus such that the window/actual bases do not cover the whole locus. Scary. I am not sure I like this...

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3056 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
asivache 2010-03-22 15:59:15 +00:00
parent 439c34ed38
commit 9053406798
2 changed files with 10 additions and 8 deletions

View File

@ -63,8 +63,8 @@ public class ReferenceContext {
}
public ReferenceContext( GenomeLoc locus, GenomeLoc window, char[] bases ) {
if( !window.containsP(locus) )
throw new StingException("Invalid locus or window; window does not contain locus");
// if( !window.containsP(locus) )
// throw new StingException("Invalid locus or window; window does not contain locus");
this.locus = locus;
this.window = window;

View File

@ -116,7 +116,8 @@ public class LocusReferenceView extends ReferenceView {
/** 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!).
* new bounds is reloaded (can be costly!). If loc spans beyond the current contig, the expansion is performed
* to the start/stop of that contig only.
* @param loc
*/
public void expandBoundsToAccomodateLoc(GenomeLoc loc) {
@ -162,7 +163,7 @@ public class LocusReferenceView extends ReferenceView {
* @return The base at the position represented by this genomeLoc.
*/
public ReferenceContext getReferenceContext( GenomeLoc genomeLoc ) {
validateLocation( genomeLoc );
//validateLocation( genomeLoc );
GenomeLoc window = GenomeLocParser.createGenomeLoc( genomeLoc.getContig(), getWindowStart(genomeLoc), getWindowStop(genomeLoc) );
char[] bases = null;
@ -204,8 +205,9 @@ public class LocusReferenceView extends ReferenceView {
* @return The expanded window.
*/
private long getWindowStart( GenomeLoc locus ) {
// If the locus is not within the bounds of the contig it allegedly maps to, don't expand the locus at all.
if(locus.getStart() < 1) return locus.getStart();
// If the locus is not within the bounds of the contig it allegedly maps to, expand only as much as we can.
if(locus.getStart() < 1) return 1;
// if(locus.getStart() < 1) return locus.getStart();
return Math.max( locus.getStart() + windowStart, 1 );
}
@ -215,9 +217,9 @@ public class LocusReferenceView extends ReferenceView {
* @return The expanded window.
*/
private long getWindowStop( GenomeLoc locus ) {
// If the locus is not within the bounds of the contig it allegedly maps to, don't expand the locus at all.
// If the locus is not within the bounds of the contig it allegedly maps to, expand only as much as we can.
long sequenceLength = reference.getSequenceDictionary().getSequence(locus.getContig()).getSequenceLength();
if(locus.getStop() > sequenceLength) return locus.getStop();
if(locus.getStop() > sequenceLength) return sequenceLength;
return Math.min( locus.getStop() + windowStop, sequenceLength );
}
}