From 05575e2e56ee3131b1e0a2fbefbd2db6e6f67cad Mon Sep 17 00:00:00 2001 From: hanna Date: Wed, 13 Jan 2010 17:03:54 +0000 Subject: [PATCH] Better bounding for the locus window. Don't make the locus window calculation blow up if the GenomeLoc ends up being outside the reference. Force the blowup elsewhere. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2573 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/datasources/providers/LocusReferenceView.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 6f4ff7266..1efa70d78 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java @@ -176,9 +176,6 @@ public class LocusReferenceView extends ReferenceView { * @param genomeLoc location to verify. */ private void validateLocation( GenomeLoc genomeLoc ) throws InvalidPositionException { -// if( !genomeLoc.isSingleBP() ) -// throw new InvalidPositionException( -// String.format("Requested position larger than one base; start = %d, stop = %d", genomeLoc.getStart(), genomeLoc.getStop())); if( bounds != null && !bounds.containsP(genomeLoc) ) throw new InvalidPositionException( String.format("Requested position %s not within interval %s", genomeLoc, bounds)); @@ -190,6 +187,8 @@ 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(); return Math.max( locus.getStart() + windowStart, 1 ); } @@ -199,6 +198,9 @@ public class LocusReferenceView extends ReferenceView { * @return The expanded window. */ private long getWindowStop( GenomeLoc locus ) { - return Math.min( locus.getStop() + windowStop, reference.getSequenceDictionary().getSequence(locus.getContig()).getSequenceLength() ); + // If the locus is not within the bounds of the contig it allegedly maps to, don't expand the locus at all. + long sequenceLength = reference.getSequenceDictionary().getSequence(locus.getContig()).getSequenceLength(); + if(locus.getStop() > sequenceLength) return locus.getStop(); + return Math.min( locus.getStop() + windowStop, sequenceLength ); } }