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];