From 67d4148b32b18af06518f8644bc01bc34a251436 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Thu, 9 Aug 2012 15:58:18 -0400 Subject: [PATCH] Fixing but reported by Thomas in the forum where reads were soft-clipped beyond the limits of the contig and ReduceReads was failing with a NoSuchElement exception. Now we hard clip anything that goes beyond the boundaries of the contig. --- .../walkers/compression/reducereads/ReduceReads.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java index 93d8319b7..177050667 100644 --- a/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java +++ b/protected/java/src/org/broadinstitute/sting/gatk/walkers/compression/reducereads/ReduceReads.java @@ -251,7 +251,7 @@ public class ReduceReads extends ReadWalker, ReduceRea LinkedList mappedReads; totalReads++; if (!debugRead.isEmpty() && read.getReadName().contains(debugRead)) - System.out.println("Found debug read!"); + System.out.println("Found debug read!"); if (debugLevel == 1) System.out.printf("\nOriginal: %s %s %d %d\n", read, read.getCigar(), read.getAlignmentStart(), read.getAlignmentEnd()); @@ -260,7 +260,14 @@ public class ReduceReads extends ReadWalker, ReduceRea // attribute hash so we can determine later if we need to write down the alignment shift to the reduced BAM file read.setTemporaryAttribute(GATKSAMRecord.REDUCED_READ_ORIGINAL_ALIGNMENT_START_SHIFT, read.getAlignmentStart()); read.setTemporaryAttribute(GATKSAMRecord.REDUCED_READ_ORIGINAL_ALIGNMENT_END_SHIFT, read.getAlignmentEnd()); - + + // Check if the read goes beyond the boundaries of the chromosome, and hard clip those boundaries. + int chromosomeLength = ref.getGenomeLocParser().getContigInfo(read.getReferenceName()).getSequenceLength(); + if (read.getSoftStart() < 0) + read = ReadClipper.hardClipByReadCoordinates(read, 0, -read.getSoftStart() - 1); + if (read.getSoftEnd() > chromosomeLength) + read = ReadClipper.hardClipByReadCoordinates(read, chromosomeLength - read.getSoftStart() + 1, read.getReadLength() - 1); + if (!DONT_SIMPLIFY_READS) read.simplify(); // Clear all unnecessary attributes if (!DONT_CLIP_ADAPTOR_SEQUENCES)