def _collapse_consecutive_gaps(a, b):
    """Collapse consecutive gaps in an alignment between two sequences.

    For example, the alignment
        ATC----GA
        ATCATCGGA
    would become
        ATC-GA
        ATCAGA

    Args:
        a, b: two aligned sequences

    Returns:
        tuple (a', b') where a' and b' represents an alignment of a
        and b, with gaps collapsed
    """
    assert len(a) == len(b)
    a_ccg, b_ccg = a[0], b[0]
    for i in range(1, len(a)):
        if a[i-1] == '-':
            if a[i] == '-':
                # Skip this position; we are already in a gap
                continue
            else:
                # We are out of the gap for a; be sure to include
                # this position
                a_ccg += a[i]
                b_ccg += b[i]
        elif b[i-1] == '-':
            if b[i] == '-':
                # Skip this position; we are already in a gap
                continue
            else:
                # We are out of the gap for b; be sure to include
                # this position
                a_ccg += a[i]
                b_ccg += b[i]
        else:
            a_ccg += a[i]
            b_ccg += b[i]
    return (a_ccg, b_ccg)