# Path: dark/sam.py
# CONSUMES_REFERENCE = {CMATCH, CDEL, CREF_SKIP, CEQUAL, CDIFF}


from pysam import CINS, CSOFT_CLIP, CHARD_CLIP
from dark.sam import CONSUMES_REFERENCE
       C{read.get_aligned_pairs} where the read is returned by the pysam
       C{fetch} method.
    @param cigarOperations: A C{list} of pysam CIGAR operations.
    @return: A 2-tuple containing a C{bool} and the C{int} reference offset of
        the base after the insertion. The C{bool} indicates whether we needed
        to look back in the sequence to find a reference base.
    """
    assert cigarOperations[offset] == CINS
    assert pairs[offset][1] is None

    # Look back.
    for pair, cigarOperation in zip(pairs[offset::-1],
                                    cigarOperations[offset::-1]):
        if cigarOperation != CINS:
            _, referenceOffset = pair
            # If we have a reference offset, then we've found our
            # answer. Otherwise, check as above.
            if referenceOffset is None:
                assert cigarOperation not in CONSUMES_REFERENCE
            else:
                return True, referenceOffset + 1

    # Look ahead.
    for pair, cigarOperation in zip(pairs[offset:], cigarOperations[offset:]):
        if cigarOperation != CINS:
            _, referenceOffset = pair
            # If we have a reference offset, then we've found our
            # answer. Otherwise, check that this is something that does not
            # consume reference bases.
            if referenceOffset is None:

# Path: dark/sam.py
# CONSUMES_REFERENCE = {CMATCH, CDEL, CREF_SKIP, CEQUAL, CDIFF}


# Path: dark/cigar.py
from pysam import CINS, CSOFT_CLIP, CHARD_CLIP
from dark.sam import CONSUMES_REFERENCE

       C{read.get_aligned_pairs} where the read is returned by the pysam
       C{fetch} method.
    @param cigarOperations: A C{list} of pysam CIGAR operations.
    @return: A 2-tuple containing a C{bool} and the C{int} reference offset of
        the base after the insertion. The C{bool} indicates whether we needed
        to look back in the sequence to find a reference base.
    """
    assert cigarOperations[offset] == CINS
    assert pairs[offset][1] is None

    # Look back.
    for pair, cigarOperation in zip(pairs[offset::-1],
                                    cigarOperations[offset::-1]):
        if cigarOperation != CINS:
            _, referenceOffset = pair
            # If we have a reference offset, then we've found our
            # answer. Otherwise, check as above.
            if referenceOffset is None:
                assert cigarOperation not in CONSUMES_REFERENCE
            else:
                return True, referenceOffset + 1

    # Look ahead.
    for pair, cigarOperation in zip(pairs[offset:], cigarOperations[offset:]):
        if cigarOperation != CINS:
            _, referenceOffset = pair
            # If we have a reference offset, then we've found our
            # answer. Otherwise, check that this is something that does not
            # consume reference bases.
            if referenceOffset is None:

                assert cigarOperation not in CONSUMES_REFERENCE