I've currently got a list of tuples (though I control creation of the list and tuples, so they could be altered in type if needed). Each tuple has a start and end integer and a string with an ID for that range's source. What I'm trying to do is identify all of the overlapping ranges within the tuples.
Currently I have
a = [(0, 98, '122:R'),
(100, 210, '124:R'),
(180, 398, '125:R'),
(200, 298, '123:R')]
highNum = 0
highNumItem = ''
for item in a:
if item[0] < highNum:
print(highNumItem + ' overlaps ' + item[2])
if item[1] > highNum:
highNum = item[1]
highNumItem = item[2]
# 124:R overlaps 125:R
# 125:R overlaps 123:R
Which outputs enough information that overlaps should be able to be manually review and fixed. But, it misses identifying some sets of overlaps. I can't help thinking there's a relatively obvious solution I'm just missing or not using the right search terms to find examples of. But ideally I'd like the output to actually be
124:R overlaps 125:R & 123:R
125:R overlaps 123:R
But using my comparison method, I can't see a way to catch the rare instance where an overlap spans more than just 2 adjacent ranges. If anyone could point me to a function or comparison method appropriate to this, I'd greatly appreciate.
Also, if it matters, I'm currently stuck with python 2.7, but need to be able to port solution to 3.x when 3rd party applications allow it.
a
one single time.