Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/isotools/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,28 @@ def find_orfs(sequence, start_codons=None, stop_codons=None, ref_cds=None):


def has_overlap(r1, r2):
"check the overlap of two intervals"
# assuming start < end
return r1[1] > r2[0] and r2[1] > r1[0]
"""check the overlap of two intervals

Does not distinguish between (start,end) or (end,start) order in coordinates
"""
# Interval objects have lengths >=2, first two elements are coordinates
assert len(r1) >= 2, f"Should be length >=2, instead saw: {str(r1)}"
assert len(r2) >= 2, f"Should be length >=2, instead saw: {str(r2)}"
# Flip coordinates if given as (end, start)
r1_start, r1_end = (r1[0], r1[1]) if r1[0] < r1[1] else (r1[1], r1[0])
r2_start, r2_end = (r2[0], r2[1]) if r2[0] < r2[1] else (r2[1], r2[0])
return r1_end > r2_start and r2_end > r1_start


def get_overlap(r1, r2):
"check the overlap of two intervals"
# assuming start < end
return max(0, min(r1[1], r2[1]) - max(r1[0], r2[0]))
"""get the overlap length of two intervals

Does not distinguish between (start,end) or (end,start) order in coordinates
"""
# Flip coordinates if given as (end, start)
r1_start, r1_end = (r1[0], r1[1]) if r1[0] < r1[1] else (r1[1], r1[0])
r2_start, r2_end = (r2[0], r2[1]) if r2[0] < r2[1] else (r2[1], r2[0])
return max(0, min(r1_end, r2_end) - max(r1_start, r2_start))


def get_intersects(tr1, tr2):
Expand Down