Skip to content

Commit

Permalink
added more tests for SamLocusIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
magicDGS committed May 17, 2016
1 parent c4c92ae commit 872a3c4
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion src/test/java/htsjdk/samtools/util/SamLocusIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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]);
}
Expand Down

0 comments on commit 872a3c4

Please sign in to comment.