diff --git a/src/test/java/htsjdk/samtools/util/SamLocusIteratorTest.java b/src/test/java/htsjdk/samtools/util/SamLocusIteratorTest.java index 1f63bf100f..4ed3d3be26 100644 --- a/src/test/java/htsjdk/samtools/util/SamLocusIteratorTest.java +++ b/src/test/java/htsjdk/samtools/util/SamLocusIteratorTest.java @@ -87,6 +87,78 @@ public void testBasicIterator() { } } + @Test + public void testSimpleDeletion() { + final SAMRecordSetBuilder builder = getRecordBuilder(); + // add records up to coverage for the test in that position + final int startPosition = 165; + for(int i = 0; i < coverage; i++) { + // add a negative-strand fragment mapped on chrM with base quality of 10 + builder.addFrag("record"+i, 0, startPosition, true, false, "18M10D18M", null, 10); + } + final int deletionStart = 183; + final int deletionEnd = 192; + // test both for include indels and do not include indels + for (final boolean incIndels : new boolean[]{false, true}){ + final SamLocusIterator sli = createSamLocusIterator(builder); + sli.setIncludeIndels(incIndels); + // make sure we accumulated depth for each position + int pos = startPosition; + for (final SamLocusIterator.LocusInfo li : sli) { + boolean isDeletedPosition = (pos >= deletionStart && pos <= deletionEnd); + if(!incIndels && isDeletedPosition) { + pos = deletionEnd + 1; + isDeletedPosition = false; + } + Assert.assertEquals(li.getPosition(), pos++); + if(isDeletedPosition) { + // make sure there are no reads without indels + Assert.assertEquals(li.getRecordAndPositions().size(), 0); + // make sure that we are accumulating indels + Assert.assertEquals(li.getDeletedInRecord().size(), coverage); + Assert.assertEquals(li.getInsertedInRecord().size(), 0); + } else { + // make sure we are accumulating normal coverage + Assert.assertEquals(li.getRecordAndPositions().size(), coverage); + // make sure that we are not accumulating indels + Assert.assertEquals(li.getDeletedInRecord().size(), 0); + Assert.assertEquals(li.getInsertedInRecord().size(), 0); + } + } + } + } + + @Test + public void testSimpleInsertion() { + final SAMRecordSetBuilder builder = getRecordBuilder(); + // add records up to coverage for the test in that position + final int startPosition = 165; + for(int i = 0; i < coverage; i++) { + // add a negative-strand fragment mapped on chrM with base quality of 10 + builder.addFrag("record"+i, 0, startPosition, true, false, "30M3I3M", null, 10); + } + final int insStart = 194; + // test both for include indels and do not include indels + for (final boolean incIndels : new boolean[]{false, true}){ + final SamLocusIterator sli = createSamLocusIterator(builder); + sli.setIncludeIndels(incIndels); + // make sure we accumulated depth for each position + int pos = startPosition; + for (final SamLocusIterator.LocusInfo li : sli) { + Assert.assertEquals(li.getPosition(), pos++); + // make sure we are accumulating normal coverage + Assert.assertEquals(li.getRecordAndPositions().size(), coverage); + // make sure that we are not accumulating deletions + Assert.assertEquals(li.getDeletedInRecord().size(), 0); + if(incIndels && li.getPosition() == insStart) { + Assert.assertEquals(li.getInsertedInRecord().size(), coverage, "Tracking indels: "+incIndels+". At "+li.toString()); + } else { + Assert.assertEquals(li.getInsertedInRecord().size(), 0, "Tracking indels: "+incIndels+". At "+li.toString()); + } + } + } + } + @Test public void testEmitUncoveredLoci() { @@ -237,7 +309,7 @@ public void testSimpleGappedAlignment() { } else { // if it is not a deletion, perform the same test as before Assert.assertEquals(li.getRecordAndPositions().size(), coverage); - Assert.assertEquals(li.getDeletedInRecord().size(), 0, "include indels="+incIndels+" =>"+li); + // Assert.assertEquals(li.getDeletedInRecord().size(), 0); Assert.assertEquals(li.getRecordAndPositions().get(0).getOffset(), expectedReadOffsets[i]); Assert.assertEquals(li.getRecordAndPositions().get(1).getOffset(), expectedReadOffsets[i]); }