<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def blast_to_cigar(query_seq, match_seq, subject_seq, cigar_age='new'):
 """converts BLAST alignment into a old or new CIGAR line Args: query_seq (str):
 Aligned portion of query sequence match_seq (str):
 Alignment sequence subject_seq (str):
 Aligned portion of subject/reference sequence cigar_age (str):
 ['old', 'new'] CIGAR format to use, new is highly detailed while old is fairly minimalistic Returns: str: CIGAR string Raises: ValueError: If query_seq, match_seq, and match_seq not same length Examples: 3=2X2D2=2X3= 5M2D7M """


    if not len(query_seq) == len(match_seq) \
            or not len(query_seq) == len(subject_seq) \
            or not len(subject_seq) == len(match_seq):
        raise ValueError('query_seq, match_seq, and subject_seq not same '
                         'lengths.')

    # Translate XML alignment to CIGAR characters
    cigar_line_raw = []
    for query, match, subject in zip(query_seq, match_seq, subject_seq):
        if query == '-':  # Deletion
            cigar_line_raw.append('D')
            continue
        elif subject == '-':  # Insertion
            cigar_line_raw.append('I')
            continue
        elif match == '+' or match == '|' or match.isalpha():  # Match
            if match != '+' and cigar_age == 'new':  # Positive match
                cigar_line_raw.append('=')
                continue
            elif match == '+' and cigar_age == 'new':  # Mismatch
                cigar_line_raw.append('X')
                continue
            else:
                cigar_line_raw.append('M')
                continue
        elif cigar_age == 'new':
            cigar_line_raw.append('X')
            continue
        else:
            cigar_line_raw.append('M')

    # Replace repeat characters with numbers
    cigar_line = []
    last_position = ''
    repeats = 1
    cigar_len = len(cigar_line_raw)
    for letter in enumerate(cigar_line_raw):
        if letter[1] == last_position:
            repeats += 1
        else:
            if repeats != 1:
                cigar_line.append(str(repeats))
                repeats = 1
            cigar_line.append(last_position)
        if letter[0] == cigar_len - 1:
            if repeats != 1:
                cigar_line.append(str(repeats))
                repeats = 1
            cigar_line.append(letter[1])
        last_position = letter[1]

    return ''.join(cigar_line)