From c26295919e6cfb4903c11ea0646d2c93039de4d9 Mon Sep 17 00:00:00 2001 From: Mauricio Carneiro Date: Fri, 16 Dec 2011 14:36:27 -0500 Subject: [PATCH] Added hardClipBothEndsByReferenceCoordinates UnitTest for the ReadClipper --- .../utils/clipreads/ReadClipperUnitTest.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/public/java/test/org/broadinstitute/sting/utils/clipreads/ReadClipperUnitTest.java b/public/java/test/org/broadinstitute/sting/utils/clipreads/ReadClipperUnitTest.java index fc1459ee0..2e2b5f373 100644 --- a/public/java/test/org/broadinstitute/sting/utils/clipreads/ReadClipperUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/clipreads/ReadClipperUnitTest.java @@ -34,7 +34,6 @@ import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils; import org.broadinstitute.sting.utils.sam.GATKSAMRecord; import org.testng.Assert; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.List; @@ -48,10 +47,6 @@ import java.util.List; */ public class ReadClipperUnitTest extends BaseTest { - // TODO: exception testing, make cases that should fail will fail - - // TODO: add indels to all test cases - List cigarList; int maximumCigarSize = 10; @@ -64,6 +59,18 @@ public class ReadClipperUnitTest extends BaseTest { public void testHardClipBothEndsByReferenceCoordinates() { logger.warn("Executing testHardClipBothEndsByReferenceCoordinates"); + for (Cigar cigar : cigarList) { + GATKSAMRecord read = ClipReadsTestUtils.makeReadFromCigar(cigar); + int alnStart = read.getAlignmentStart(); + int alnEnd = read.getAlignmentEnd(); + int readLength = alnStart - alnEnd; + for (int i=0; i= alnStart + i, String.format("Clipped alignment start is less than original read (minus %d): %s -> %s", i, read.getCigarString(), clippedRead.getCigarString())); + Assert.assertTrue(clippedRead.getAlignmentEnd() <= alnEnd + i, String.format("Clipped alignment end is greater than original read (minus %d): %s -> %s", i, read.getCigarString(), clippedRead.getCigarString())); + } + } + } @Test(enabled = true) @@ -116,7 +123,7 @@ public class ReadClipperUnitTest extends BaseTest { // Tests // Make sure the low qualities are gone - testNoLowQualBases(clipLeft, LOW_QUAL); + assertNoLowQualBases(clipLeft, LOW_QUAL); // Can't run this test with the current contract of no hanging insertions //Assert.assertEquals(clipLeft.getReadLength(), readLength - nLowQualBases, String.format("Clipped read size (%d) is different than the number high qual bases (%d) -- Cigars: %s -> %s", clipLeft.getReadLength(), readLength - nLowQualBases, read.getCigarString(), clipLeft.getCigarString())); @@ -131,7 +138,7 @@ public class ReadClipperUnitTest extends BaseTest { // Tests // Make sure the low qualities are gone - testNoLowQualBases(clipRight, LOW_QUAL); + assertNoLowQualBases(clipRight, LOW_QUAL); // Make sure we haven't clipped any high quals -- Can't run this test with the current contract of no hanging insertions //Assert.assertEquals(clipLeft.getReadLength(), readLength - nLowQualBases, String.format("Clipped read size (%d) is different than the number high qual bases (%d) -- Cigars: %s -> %s", clipRight.getReadLength(), readLength - nLowQualBases, read.getCigarString(), clipRight.getCigarString())); @@ -149,7 +156,7 @@ public class ReadClipperUnitTest extends BaseTest { // Tests // Make sure the low qualities are gone - testNoLowQualBases(clipBoth, LOW_QUAL); + assertNoLowQualBases(clipBoth, LOW_QUAL); // Can't run this test with the current contract of no hanging insertions //Assert.assertEquals(clipLeft.getReadLength(), readLength - nLowQualBases, String.format("Clipped read size (%d) is different than the number high qual bases (%d) -- Cigars: %s -> %s", clipRight.getReadLength(), readLength - (2*nLowQualBases), read.getCigarString(), clipBoth.getCigarString())); @@ -158,11 +165,7 @@ public class ReadClipperUnitTest extends BaseTest { // logger.warn(String.format("Testing %s for all combinations of low/high qual... PASSED", read.getCigarString())); } - - - - - // ONE OFF Testing clipping that ends inside an insertion + // ONE OFF Testing clipping that ends inside an insertion ( Ryan's bug ) final byte[] BASES = {'A','C','G','T','A','C','G','T'}; final byte[] QUALS = {2, 2, 2, 2, 20, 20, 20, 2}; final String CIGAR = "1S1M5I1S"; @@ -179,14 +182,6 @@ public class ReadClipperUnitTest extends BaseTest { ClipReadsTestUtils.assertEqualReads(lowQualClipper.hardClipLowQualEnds((byte) 2), expected); } - private void testNoLowQualBases(GATKSAMRecord read, byte low_qual) { - if (!read.isEmpty()) { - byte [] quals = read.getBaseQualities(); - for (int i=0; i %s -- PASSED!", read.getCigarString(), clippedRead.getCigarString())); } } + + private void assertNoLowQualBases(GATKSAMRecord read, byte low_qual) { + if (!read.isEmpty()) { + byte [] quals = read.getBaseQualities(); + for (int i=0; i