Have a look at the Cigar.java source code in Picard. For example:
/**
* @return The number of reference bases that the read covers, including padding.
*/
public int getPaddedReferenceLength() {
int length = 0;
for (final CigarElement element : cigarElements) {
switch (element.getOperator()) {
case M:
case D:
case N:
case EQ:
case X:
case P:
length += element.getLength();
}
}
return length;
}
The bamToBed
program in BEDTools will do this by create BED entries for each BAM alignment where the end end coordinate reflects the CIGAR string. Moreover, if you want to create separate BED entries for "spliced" or "split" alignments (i.e., when there is an "N: CIGAR op present), use the -split
option.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Once you have length, the position of the last base is: end = start + length - 1. Don't forget the minus one, since we're "counting fenceposts" (google it).