From 181f901126dba8a92539aebdaf111c4b1999c3c5 Mon Sep 17 00:00:00 2001 From: ebanks Date: Fri, 22 Oct 2010 14:38:26 +0000 Subject: [PATCH] Fix for Ryan: don't pull reference sequence for the portions of reads that extend beyond the contig boundaries git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4551 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/walkers/genotyper/UnifiedGenotyperEngine.java | 4 ++-- .../org/broadinstitute/sting/utils/sam/AlignmentUtils.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/genotyper/UnifiedGenotyperEngine.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/genotyper/UnifiedGenotyperEngine.java index 641761670..76e4617a5 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/genotyper/UnifiedGenotyperEngine.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/genotyper/UnifiedGenotyperEngine.java @@ -453,9 +453,9 @@ public class UnifiedGenotyperEngine { bitset.set(i); } - // if a read is too long for the reference context, extend the context + // if a read is too long for the reference context, extend the context (being sure not to extend past the end of the chromosome) if ( record.getAlignmentEnd() > refContext.getWindow().getStop() ) { - GenomeLoc window = GenomeLocParser.createGenomeLoc(refContext.getLocus().getContig(), refContext.getWindow().getStart(), record.getAlignmentEnd()); + GenomeLoc window = GenomeLocParser.createGenomeLoc(refContext.getLocus().getContig(), refContext.getWindow().getStart(), Math.min(record.getAlignmentEnd(), referenceReader.getSequenceDictionary().getSequence(refContext.getLocus().getContig()).getSequenceLength())); byte[] bases = referenceReader.getSubsequenceAt(window.getContig(), window.getStart(), window.getStop()).getBases(); StringUtil.toUpperCase(bases); refContext = new ReferenceContext(refContext.getLocus(), window, bases); diff --git a/java/src/org/broadinstitute/sting/utils/sam/AlignmentUtils.java b/java/src/org/broadinstitute/sting/utils/sam/AlignmentUtils.java index 45cca9eec..f04440368 100644 --- a/java/src/org/broadinstitute/sting/utils/sam/AlignmentUtils.java +++ b/java/src/org/broadinstitute/sting/utils/sam/AlignmentUtils.java @@ -285,9 +285,9 @@ public class AlignmentUtils { if ( currentReadPos++ < readStartPos ) continue; - if ( refIndex >= refBases.length ) { - throw new IllegalStateException("When calculating mismatches, we somehow don't have enough trailing reference context for read " + read.getReadName() + " at position " + ref.getLocus()); - } + // this is possible if reads extend beyond the contig end + if ( refIndex >= refBases.length ) + break; byte refChr = refBases[refIndex]; byte readChr = readBases[readIndex];