throw new RuntimeException(e);
}
}
protected Cigar shiftCigarLeft(Cigar cigar, int positionsToShift) {
Cigar newCigar = new Cigar();
for (int i=0; i<cigar.getCigarElements().size(); i++) {
CigarElement elem = cigar.getCigarElement(i);
if (isFirstNonSoftClippedElem(i, cigar)) {
int newLen = elem.getLength() - positionsToShift;
if (newLen > 0) {
CigarElement newElem = new CigarElement(newLen, elem.getOperator());
newCigar.add(newElem);
}
} else if (isLastNonSoftClippedElem(i, cigar)) {
if (elem.getOperator() == CigarOperator.M) {
CigarElement newElem = new CigarElement(elem.getLength() + positionsToShift, CigarOperator.M);
newCigar.add(newElem);
} else {
CigarElement newElem = new CigarElement(positionsToShift, CigarOperator.M);
newCigar.add(elem);
newCigar.add(newElem);
}
} else {
newCigar.add(elem);
}
}
return newCigar;
}