From 165b936fcd6160bfd82da79c36ef2e32765006fd Mon Sep 17 00:00:00 2001 From: Eric Banks Date: Mon, 24 Jun 2013 14:06:21 -0400 Subject: [PATCH] Fixing the 'header is negative' problem in Reduce Reads... again. Previous fixes and tests only covered trailing soft-clips. Now that up front hard-clipping is working properly though, we were failing on those in the tool. Added a patch for this as well as a separate test independent of the soft-clips to make sure that it's working properly. --- .../reducereads/SlidingWindowUnitTest.java | 17 +++++++++++++++-- .../sting/utils/sam/ReadUtils.java | 6 +++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindowUnitTest.java b/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindowUnitTest.java index c9bb2f084..bf45fc298 100644 --- a/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindowUnitTest.java +++ b/protected/java/test/org/broadinstitute/sting/gatk/walkers/compression/reducereads/SlidingWindowUnitTest.java @@ -94,7 +94,7 @@ public class SlidingWindowUnitTest extends BaseTest { ////////////////////////////////////////////////////////////////////////////////////// @Test(enabled = true) - public void testLeadingClipThenInsertion() { + public void testLeadingSoftClipThenInsertion() { final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "foo", 0, 1, 10); read.setReadBases(Utils.dupBytes((byte) 'A', 10)); @@ -104,8 +104,21 @@ public class SlidingWindowUnitTest extends BaseTest { final SlidingWindow slidingWindow = new SlidingWindow("1", 0, 1); slidingWindow.addRead(read); - Pair, CompressionStash> result = slidingWindow.close(null); + slidingWindow.close(null); + } + @Test(enabled = true) + public void testLeadingHardClipThenInsertion() { + + final GATKSAMRecord read = ArtificialSAMUtils.createArtificialRead(header, "foo", 0, 1, 8); + read.setReadBases(Utils.dupBytes((byte) 'A', 8)); + read.setBaseQualities(Utils.dupBytes((byte)30, 8)); + read.setMappingQuality(30); + read.setCigarString("2H2I6M"); + + final SlidingWindow slidingWindow = new SlidingWindow("1", 0, 10, header, new GATKSAMReadGroupRecord("test"), 0, 0.05, 0.05, 0.05, 20, 20, 100, ReduceReads.DownsampleStrategy.Normal, false); + slidingWindow.addRead(read); + slidingWindow.close(null); } ////////////////////////////////////////////////////////////////////////////////////// diff --git a/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java b/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java index cf1c9cb8e..f9393cc4b 100644 --- a/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java +++ b/public/java/src/org/broadinstitute/sting/utils/sam/ReadUtils.java @@ -613,15 +613,15 @@ public class ReadUtils { * Checks if a read starts with an insertion. * * @param cigarForRead the CIGAR to evaluate - * @param ignoreClipOps should we ignore S and H operators when evaluating whether an I operator is at the beginning? + * @param ignoreSoftClipOps should we ignore S operators when evaluating whether an I operator is at the beginning? Note that H operators are always ignored. * @return the element if it's a leading insertion or null otherwise */ - public static CigarElement readStartsWithInsertion(final Cigar cigarForRead, final boolean ignoreClipOps) { + public static CigarElement readStartsWithInsertion(final Cigar cigarForRead, final boolean ignoreSoftClipOps) { for ( final CigarElement cigarElement : cigarForRead.getCigarElements() ) { if ( cigarElement.getOperator() == CigarOperator.INSERTION ) return cigarElement; - else if ( !ignoreClipOps || (cigarElement.getOperator() != CigarOperator.HARD_CLIP && cigarElement.getOperator() != CigarOperator.SOFT_CLIP) ) + else if ( cigarElement.getOperator() != CigarOperator.HARD_CLIP && ( !ignoreSoftClipOps || cigarElement.getOperator() != CigarOperator.SOFT_CLIP) ) break; } return null;