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


from operator import itemgetter
from crumbs.utils.tags import START, END
import random
import copy
def get_longest_complementary_segment(segments, seq_len):
    'Given a seq and the locations it returns the longest region not covered'

    segments = merge_overlaping_segments(segments)

    # we want the non-matched locations
    segments = get_complementary_segments(segments, seq_len)

    # now we return the longest one
    return get_longest_segment(segments)


def merge_overlaping_segments(segments, merge_segments_closer=1):
    '''Given a list of segments it returns the overlapped segments.

       segments 1  -------        ----->    -----------
       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)

# 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

def get_longest_complementary_segment(segments, seq_len):
    'Given a seq and the locations it returns the longest region not covered'

    segments = merge_overlaping_segments(segments)

    # we want the non-matched locations
    segments = get_complementary_segments(segments, seq_len)

    # now we return the longest one
    return get_longest_segment(segments)


def merge_overlaping_segments(segments, merge_segments_closer=1):
    '''Given a list of segments it returns the overlapped segments.

       segments 1  -------        ----->    -----------
       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)