From 9053406798e1118d563be0d06882758f5ad211af Mon Sep 17 00:00:00 2001 From: asivache Date: Mon, 22 Mar 2010 15:59:15 +0000 Subject: [PATCH] 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 --- .../sting/gatk/contexts/ReferenceContext.java | 4 ++-- .../datasources/providers/LocusReferenceView.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java index 87dd0f04f..76d093ac0 100644 --- a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java @@ -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; diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java index 993918b0f..0fad47c70 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java @@ -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 ); } }