import re


def RemoveFrameShiftsFromAlignment(row_ali, col_ali, gap_char="-"):
    """remove frame shifts in an alignment.

    Frameshifts are gaps are 1, 2, 4, or 5 residues long.

    >>> RemoveFrameShiftsFromAlignment("ABC-EFG", "AB-DEFG")
    ('ABEFG', 'ABEFG')

    Arguments
    ---------
    row_ali : string
        Alignment string of row.
    col_ali : string
        Alignment string of column.
    gap_char : string
        Gap character to identify aligments.

    Returns
    -------
    new_row_ali : string
        New alignment string for row
    new_col_ali : string
        New aligment string for column
    """

    match_string = "[^%s]%s+[^%s]" %\
        (gap_char, gap_char, gap_char)

    positions = []
    for x in re.finditer(match_string, row_ali):
        positions.append((x.start() + 1, x.end() - 1))

    for x in re.finditer(match_string, col_ali):
        positions.append((x.start() + 1, x.end() - 1))

    positions.sort()
    # cut and paste new alignment
    new_row_ali = []
    new_col_ali = []
    a = 0
    for first, last in positions:
        if (last - first) % 3:
            new_row_ali.append(row_ali[a:first])
            new_col_ali.append(col_ali[a:first])
            a = last

    new_row_ali.append(row_ali[a:])
    new_col_ali.append(col_ali[a:])

    return "".join(new_row_ali), "".join(new_col_ali)