def iterator_target_overlap(infile, merge_distance):

    last_sbjct_id = None
    start = None
    end = None
    matches = []
    processed_contigs = set()

    while 1:

        match = infile.next()

        if match is None:
            break

        if match.mSbjctId != last_sbjct_id or match.mSbjctFrom >= (end + merge_distance):
            if last_sbjct_id:
                yield matches
            matches = []
            if last_sbjct_id != match.mSbjctId and match.mSbjctId in processed_contigs:
                raise ValueError("input not sorted by target (contig,start): already encountered %s\n%s" %
                                 (match.mSbjctId, str(match)))

            processed_contigs.add(last_sbjct_id)

            last_sbjct_id = match.mSbjctId
            start = match.mSbjctFrom
            end = match.mSbjctTo

        if match.mSbjctFrom < start:
            raise ValueError("input not sorted by target (contig,start): %i < %i\n%s" %
                             (match.mSbjctFrom, start, str(match)))

        end = max(match.mSbjctTo, end)
        matches.append(match)

    if last_sbjct_id:
        yield matches
Resource Header for Guided Tour
dataset/ETHPy150Open CGATOxford/cgat/obsolete/BlatTest.py/iterator_target_overlap--crossover with--dataset/ETHPy150Open sahana/eden/modules/s3db/tour.py/tour_rheader