+ /**
+ * Get list of positions inserted to the reference sequence
+ *
+ * @param it
+ * @return
+ */
+ private SortedMap<Integer, Integer> getInsertions(Iterator<SAMRecord> it)
+ {
+ SortedMap<Integer, Integer> insertions = new TreeMap<>();
+ while (it.hasNext())
+ {
+ // check each record for insertions in the CIGAR string
+ SAMRecord rec = it.next();
+ Iterator<CigarElement> cit = rec.getCigar().getCigarElements()
+ .iterator();
+ int next = 0;
+ while (cit.hasNext())
+ {
+ CigarElement el = cit.next();
+ switch (el.getOperator())
+ {
+ case I:
+ // add to insertions list, and move along the read
+ int refLocation = rec.getReferencePositionAtReadPosition(next);
+ insertions.put(refLocation, el.getLength());
+ next += el.getLength();
+ break;
+ case M:
+ // match to reference, move along the read
+ next += el.getLength();
+ break;
+ default:
+ // deletions, introns etc don't consume any residues from the read
+ break;
+ }
+ }
+
+ }
+ return insertions;
+ }
+