Added hardClipBothEndsByReferenceCoordinates UnitTest for the ReadClipper

This commit is contained in:
Mauricio Carneiro 2011-12-16 14:36:27 -05:00
parent 1994c3e3bc
commit c26295919e
1 changed files with 26 additions and 21 deletions

View File

@ -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<Cigar> 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<readLength/2; i++) {
GATKSAMRecord clippedRead = (new ReadClipper(read)).hardClipBothEndsByReferenceCoordinates(alnStart + i, alnEnd - i);
Assert.assertTrue(clippedRead.getAlignmentStart() >= 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<quals.length; i++)
Assert.assertFalse(quals[i] <= low_qual, String.format("Found low qual (%d) base after hard clipping. Position: %d -- %s", low_qual, i, read.getCigarString()));
}
}
@Test(enabled = true)
public void testHardClipSoftClippedBases() {
@ -239,4 +234,14 @@ public class ReadClipperUnitTest extends BaseTest {
// logger.warn(String.format("Cigar %s -> %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<quals.length; i++)
Assert.assertFalse(quals[i] <= low_qual, String.format("Found low qual (%d) base after hard clipping. Position: %d -- %s", low_qual, i, read.getCigarString()));
}
}
}