# Path: crumbs/utils/tags.py
# START = 0
# 
# END = 1


from operator import itemgetter
from crumbs.utils.tags import START, END
import random
import copy
       segments 2       ------
       returns     -----------    ------    -----------
       merge_segments_closer is an integer. Segments closer than the given
       number of residues will be merged.
    '''

    # we collect all start and ends
    limits = []
    for segment in segments:
        start = segment[0]
        end = segment[1]
        if start > end:  # a reversed item
            start, end = end, start
        limit_1 = (START, start)
        limit_2 = (END, end)
        limits.append(limit_1)
        limits.append(limit_2)

    # sort by secondary key: start before end
    limits.sort(key=itemgetter(0))
    # sort by location (primary key)
    limits.sort(key=itemgetter(1))

    # merge the ends and start that differ in only one base
    filtered_limits = []
    previous_limit = None
    for limit in limits:
        if previous_limit is None:
            previous_limit = limit
            continue

# Path: crumbs/utils/tags.py
# START = 0
# 
# END = 1


# Path: crumbs/utils/segments_utils.py
from operator import itemgetter
from crumbs.utils.tags import START, END
import random
import copy

       segments 2       ------
       returns     -----------    ------    -----------
       merge_segments_closer is an integer. Segments closer than the given
       number of residues will be merged.
    '''

    # we collect all start and ends
    limits = []
    for segment in segments:
        start = segment[0]
        end = segment[1]
        if start > end:  # a reversed item
            start, end = end, start
        limit_1 = (START, start)
        limit_2 = (END, end)
        limits.append(limit_1)
        limits.append(limit_2)

    # sort by secondary key: start before end
    limits.sort(key=itemgetter(0))
    # sort by location (primary key)
    limits.sort(key=itemgetter(1))

    # merge the ends and start that differ in only one base
    filtered_limits = []
    previous_limit = None
    for limit in limits:
        if previous_limit is None:
            previous_limit = limit
            continue

        if (previous_limit[0] == END and limit[0] == START and