Skip to content

Commit

Permalink
Striving for clarity in overlap arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrg committed Oct 18, 2024
1 parent 6a93692 commit 6f0ce23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/tola/assembly/build_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def qc_sub_fragments(
abut_count = 0
overlap_count = 0
lgth = len(sub_fragments)
pairs_with_gaps = []
for i in range(0, lgth):
frag_a = sub_fragments[i]
for j in range(i + 1, lgth):
Expand All @@ -169,6 +170,9 @@ def qc_sub_fragments(
abut_count += 1
if frag_a.overlaps(frag_b):
overlap_count += 1
if g := frag_a.gap_between(frag_b):
pairs_with_gaps.append((frag_a, frag_b))


sub_frags_length = sum(f.length for f in sub_fragments)

Expand Down
10 changes: 5 additions & 5 deletions src/tola/assembly/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def overlap_length(self, othr):
if self.name != othr.name:
return None

ovr_end = max(self.start, othr.start)
ovr_start = min(self.end, othr.end)
if ovr_start < ovr_end:
ovr_start = max(self.start, othr.start)
ovr_end = min(self.end, othr.end)
if ovr_start > ovr_end:
return None
else:
return ovr_start - ovr_end + 1
return ovr_end - ovr_start + 1

def abuts(self, othr):
if self.name != othr.name:
Expand All @@ -130,8 +130,8 @@ def gap_between(self, othr):
if self.name != othr.name:
return None

gap_end = max(self.start, othr.start)
gap_start = min(self.end, othr.end)
gap_end = max(self.start, othr.start)
if gap_start < gap_end:
return gap_end - gap_start - 1
else:
Expand Down

0 comments on commit 6f0ce23

Please sign in to comment.