Skip to content

Commit

Permalink
fixed index issue with insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
magicDGS committed Dec 15, 2015
1 parent 1946f9e commit b48aa0a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/java/htsjdk/samtools/util/SamLocusIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
* Iterator that traverses a SAM File, accumulating information on a per-locus basis.
Expand Down Expand Up @@ -444,6 +445,7 @@ private void accumulateIndels(final SAMRecord rec) {
// 0-based offset into the read of the current base
int readBase = 0;
// 0-based offset for the reference of the current base
// the accumulator could have the previous position because an indel is accumulating
int refBase = 0;
// iterate over the cigar element
for (int elementIndex = 0; elementIndex < cigar.size(); elementIndex++) {
Expand All @@ -466,8 +468,8 @@ private void accumulateIndels(final SAMRecord rec) {
break; // matches consumes both ref and read bases
case I:
// insertions are included in the previous base
int accumulatorIndex = refBase;
accumulator.get(refBase).addInsertion(rec, readBase);
final int accIndex = (refBase == 0) ? 0 : refBase - 1;
accumulator.get(accIndex).addInsertion(rec, readBase);
readBase += e.getLength();
break;
case D:
Expand Down

0 comments on commit b48aa0a

Please sign in to comment.