def buildOffsets(variants, phased=True, contig=None):
    '''collect coordinate offsets.

    This methods takes a set of variants and computes
    coordinates offsets based on indels.

    Conflicting variants will be removed. 

    Returns a list of variants, a list of removed variants and a list of offsets.
    '''

    variants.sort()
    offset0, offset1 = 0, 0
    offsets0, offsets1 = [(0, 0)], [(0, 0)]

    def addDeletion(offsets, start, end, offset, variantseq):

        for x, c in enumerate(variantseq):
            if c != "-":
                offset -= 1
                offsets.append((start + x + 1, offset))

        return offset

    last_end = 0

    removed_variants, kept_variants = [], []
    for variant in variants:

        start, end, reference, action, has_wildtype, variantseqs = variant

        if action == "=":
            kept_variants.append(variant)
            # ignore substitutions
            continue

        if last_end >= start:
            removed_variants.append(variant)
            continue

        kept_variants.append(variant)
        is_homozygous = len(variantseqs) == 1 and not has_wildtype

        last_end = end
        if action == "-":
            if phased:
                offset0 = addDeletion(
                    offsets0, start, end, offset0, variantseqs[0])
                offset1 = addDeletion(
                    offsets1, start, end, offset1, variantseqs[1])
            elif is_homozygous:
                offset0 = addDeletion(
                    offsets0, start, end, offset0, variantseqs[0])
                offset1 = addDeletion(
                    offsets1, start, end, offset1, variantseqs[0])
            else:
                if has_wildtype:
                    offset1 = addDeletion(
                        offsets1, start, end, offset1, variantseqs[0])
                else:
                    offset0 = addDeletion(
                        offsets0, start, end, offset0, variantseqs[0])
                    offset1 = addDeletion(
                        offsets1, start, end, offset1, variantseqs[1])

        elif action == "+":

            if phased:
                offset0 += len(variantseqs[0]) - variantseqs[0].count("-")
                offset1 += len(variantseqs[1]) - variantseqs[1].count("-")
            elif is_homozygous:
                offset0 += len(variantseqs[0])
                offset1 += len(variantseqs[0])
            else:
                if has_wildtype:
                    offset1 += len(variantseqs[0])
                else:
                    offset0 += len(variantseqs[0]) - variantseqs[0].count("-")
                    offset1 += len(variantseqs[1]) - variantseqs[1].count("-")
            offsets0.append((end * 1, offset0))
            offsets1.append((end - 1, offset1))

        elif action == ">":
            offset0 += len(variantseqs[0]) - variantseqs[0].count("-")
            offsets0.append((end - 1, offset0))
            offset1 = addDeletion(
                offsets1, start, end, offset1, variantseqs[1])

        elif action == "<":
            offset0 = addDeletion(
                offsets0, start, end, offset0, variantseqs[0])
            offset1 += len(variantseqs[1]) - variantseqs[1].count("-")
            offsets1.append((end - 1, offset1))

        if E.global_options.loglevel >= 8:
            print "# variant=", start, end, reference, action, has_wildtype, variantseqs
            print "# offsets:", offsets0[-1], offsets1[-1]
        # add offsets - applies to the end of the variant

    return (kept_variants, removed_variants, (offsets0, offsets1))
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Variants.py/buildOffsets/operator `-` -> `*`