def normalize(pos, ref, alt, left_only=False):
    """simplify a ref/alt a la vt normalize so that ref=CC, alt=CCT becomes
    ref=C, alt=CT. this helps in annotating variants.

    This code relies on the observation by Eric Minikel that many annotation
    misses can be addressed by removing common suffix and prefixes.
    (http://www.cureffi.org/2014/04/24/converting-genetic-variants-to-their-minimal-representation/)

    >>> normalize(123, 'T', 'C')
    (123, 'T', 'C')

    >>> normalize(123, 'CC', 'CCT')
    (124, 'C', 'CT')

    >>> normalize(123, 'TCCCCT', 'CCCCT')
    (123, 'TC', 'C')

    >>> normalize(123, 'TCCCCTA', 'CCCCT')
    (123, 'TCCCCTA', 'CCCCT')

    >>> normalize(123, 'TCCCCTA', 'CCCCTA')
    (123, 'TC', 'C')

    >>> normalize(123, 'AAATCCCCTA', 'AAACCCCTA')
    (125, 'AT', 'A')

    >>> normalize(123, 'CAAATCCCCTAG', 'AAACCCCTA')
    (123, 'CAAATCCCCTAG', 'AAACCCCTA')
    """
    if len(ref) == len(alt) == 1:
        return pos, ref, alt

    # logic for trimming from either end is the same so we just reverse the
    # string to trim the suffix (i == 0) and correct position when doing prefix
    # (i == 1). To support alleles that have already been right-trimmed from
    # _leftalign, we allow the left_only argument to just do prefix-trimming.
    if left_only:
        sides = (1,)
    else:
        sides = (0, 1)
    for i in sides:
        if i == 0: # suffix so flip
            ref, alt = ref[::-1], alt[::-1]

        n, min_len = 0, min(len(ref), len(alt))
        while n + 1 < min_len and alt[n] == ref[n]:
            n += 1

        alt, ref = alt[n:], ref[n:]
        if i == 0: # flip back
            ref, alt = ref[::-1], alt[::-1]
        else: # add to position since we stripped the prefix
            pos += n

    return pos, ref, alt