Fix ClippingOp bug when performing multiple hardclip ops

bug: When performing multiple hard clip operations in a read that has indels, if the N+1 hardclip requests to clip inside an indel that has been removed by one of the (1..N) previous hardclips, the hard clipper would go out of bounds.

fix: dynamically adjust the boundaries according to the new hardclipped read length. (this maintains the current contract that hardclipping will never return a read starting or ending in indels).
This commit is contained in:
Mauricio Carneiro 2011-12-14 15:34:11 -05:00
parent de5928ac5a
commit c85100ce9c
3 changed files with 10 additions and 3 deletions

View File

@ -168,7 +168,14 @@ public class ReadClipper {
try {
GATKSAMRecord clippedRead = (GATKSAMRecord) read.clone();
for (ClippingOp op : getOps()) {
clippedRead = op.apply(algorithm, clippedRead);
//check if the clipped read can still be clipped in the range requested
if (op.start < clippedRead.getReadLength()) {
ClippingOp fixedOperation = op;
if (op.stop > clippedRead.getReadLength())
fixedOperation = new ClippingOp(op.start, clippedRead.getReadLength() - 1);
clippedRead = fixedOperation.apply(algorithm, clippedRead);
}
}
wasClipped = true;
ops.clear();

View File

@ -48,7 +48,7 @@ public class ClipReadsTestUtils {
Assert.assertTrue(read.isEmpty());
}
private static byte[] subtractToArray(byte[] array, int n) {
public static byte[] subtractToArray(byte[] array, int n) {
if (array == null)
return null;

View File

@ -231,7 +231,7 @@ public class ReadClipperUnitTest extends BaseTest {
@Test(enabled = true)
public void testHardClipLowQualEnds() {
// Needs a thorough redesign
logger.warn("Executing testHardClipByReferenceCoordinates");
logger.warn("Executing testHardClipLowQualEnds");
//Clip whole read
Assert.assertEquals(readClipper.hardClipLowQualEnds((byte) 64), new GATKSAMRecord(readClipper.read.getHeader()));