def parse_cigar_pairs(result):
    """
    Extract the cigar from the parasail sw_trace_align or nw_trace_align result and turn it into cigar pairs
    :param result:
    :return: list of pairs of (match/mismatch type, length)
    """
    #M   alignment match (can be a sequence match or mismatch)
    #I   insertion to the reference
    #D   deletion from the reference
    #N   skipped region from the reference
    #S   soft clipping (clipped sequences present in SEQ)
    #H   hard clipping (clipped sequences NOT present in SEQ)
    #P   padding (silent deletion from padded reference)
    #=   sequence match
    #X   sequence mismatch
    pairs = []
    cigar = result.cigar.decode.decode('UTF-8')
    last_position = 0
    current_position = 0
    for c in cigar:
        if not c.isdigit():
            pairs.append((c,int(cigar[last_position:current_position])))
            last_position = current_position+1
        current_position += 1
    return pairs