import re


def getAlignmentLength(cigar):
    """
    Computes the alignment length given a cigar string. Needed for Start + End calculation.

    @type  cigar: string
    @param cigar: Cigar string (SAM)

    @rtype:   int
    @return:  alignmentlength
    """
    # I - insertions do not extend the alignment
    # S - does not extend...
    # P - does not extend...
    # H - does not extend...
    match = re.findall("(\d+)[MDN]", cigar)
    sumOfMatches = 0
    for item in match:
        sumOfMatches += int(item)
    return (sumOfMatches)