*
* @param cigar the original cigar
* @return an object with the shifts (see CigarShift class)
*/
private CigarShift cleanHardClippedCigar(final Cigar cigar) {
final Cigar cleanCigar = new Cigar();
int shiftFromStart = 0;
int shiftFromEnd = 0;
Stack<CigarElement> cigarStack = new Stack<CigarElement>();
final Stack<CigarElement> inverseCigarStack = new Stack<CigarElement>();
for (final CigarElement cigarElement : cigar.getCigarElements())
cigarStack.push(cigarElement);
for (int i = 1; i <= 2; i++) {
int shift = 0;
int totalHardClip = 0;
boolean readHasStarted = false;
boolean addedHardClips = false;
while (!cigarStack.empty()) {
CigarElement cigarElement = cigarStack.pop();
if (!readHasStarted &&
cigarElement.getOperator() != CigarOperator.DELETION &&
cigarElement.getOperator() != CigarOperator.SKIPPED_REGION &&
cigarElement.getOperator() != CigarOperator.HARD_CLIP)
readHasStarted = true;
else if (!readHasStarted && cigarElement.getOperator() == CigarOperator.HARD_CLIP)
totalHardClip += cigarElement.getLength();
else if (!readHasStarted && cigarElement.getOperator() == CigarOperator.DELETION)
totalHardClip += cigarElement.getLength();
else if (!readHasStarted && cigarElement.getOperator() == CigarOperator.SKIPPED_REGION)
totalHardClip += cigarElement.getLength();
if (readHasStarted) {
if (i == 1) {
if (!addedHardClips) {
if (totalHardClip > 0)
inverseCigarStack.push(new CigarElement(totalHardClip, CigarOperator.HARD_CLIP));
addedHardClips = true;
}
inverseCigarStack.push(cigarElement);
} else {
if (!addedHardClips) {
if (totalHardClip > 0)
cleanCigar.add(new CigarElement(totalHardClip, CigarOperator.HARD_CLIP));
addedHardClips = true;
}
cleanCigar.add(cigarElement);
}
}
}
// first pass (i=1) is from end to start of the cigar elements
if (i == 1) {