From d2944461efe5c8d511987921cad41921096524bf Mon Sep 17 00:00:00 2001 From: asivache Date: Mon, 22 Mar 2010 17:36:29 +0000 Subject: [PATCH] We also have to allow the window to be (partially) outside the bounds and trimming to the contig size is not enough (thanks to shards). Now we trim to the current bounds too (i.e. if the interval is not completely within current bounds, we create reference context that contains only bases from the overlap between the interval and the bounds). git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3057 348d0f76-0448-11de-a6fe-93d51630548a --- .../datasources/providers/LocusReferenceView.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 0fad47c70..cc8d003c0 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java @@ -157,9 +157,15 @@ public class LocusReferenceView extends ReferenceView { this.referenceSequence = reference.getSubsequenceAt( locus.getContig(), locus.getStart(), locus.getStop() ); } + protected GenomeLoc trimToBounds(GenomeLoc l) { + if ( l.getStart() < bounds.getStart() ) l = GenomeLocParser.setStart(l, bounds.getStart()); + if ( l.getStop() > bounds.getStop() ) l = GenomeLocParser.setStop(l, bounds.getStop()); + return l; + } + /** - * Gets the reference context associated with this particular point on the genome. - * @param genomeLoc Region for which to retrieve the base. GenomeLoc must represent a 1-base region. + * Gets the reference context associated with this particular point or extended interval on the genome. + * @param genomeLoc Region for which to retrieve the base(s). If region spans beyond contig end or beoynd current bounds, it will be trimmed down. * @return The base at the position represented by this genomeLoc. */ public ReferenceContext getReferenceContext( GenomeLoc genomeLoc ) { @@ -169,6 +175,7 @@ public class LocusReferenceView extends ReferenceView { char[] bases = null; if(bounds != null) { + window = trimToBounds(window); bases = StringUtil.bytesToString( referenceSequence.getBases(), (int)(window.getStart() - getWindowStart(bounds)), (int)window.size() ).toCharArray(); } else {