Skip to content

Commit 13ac470

Browse files
committed
Account for scaffolds with gaps at their ends
1 parent 4257492 commit 13ac470

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tola-agp-tpf-utils"
7-
version = "1.3.2"
7+
version = "1.3.3"
88
readme = "README.md"
99
requires-python = ">=3.11"
1010
dependencies = [

src/tola/assembly/indexed_assembly.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ def find_overlaps(self, bait: Fragment) -> OverlapResult | None:
7474
return None
7575
i_ovr, j_ovr = rng
7676

77-
# Walk start and end pointers back to ignore Gaps on the ends
77+
# Walk start and end pointers inwards to ignore any Gaps on the ends
78+
# of the match.
79+
last_i = len(scffld.rows) - 1
7880
while isinstance(scffld.rows[i_ovr], Gap):
81+
if i_ovr == last_i:
82+
return None
7983
i_ovr += 1
8084
while isinstance(scffld.rows[j_ovr], Gap):
85+
if j_ovr == 0:
86+
return None
8187
j_ovr -= 1
8288
if not i_ovr <= j_ovr:
8389
return None

tests/indexed_assembly_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,45 @@ def test_create():
5454
x = i3.find_overlaps(Fragment("scaffold_1", 1, 100, 1))
5555

5656

57+
def test_gaps_at_scaffold_ends():
58+
frag = Fragment("ctg_1", 1, 1000, 1)
59+
ia1 = IndexedAssembly(
60+
"gaps at ends",
61+
scaffolds=[
62+
Scaffold(
63+
"scffld_1",
64+
rows=[
65+
Gap(200, "scaffold"),
66+
frag,
67+
Gap(50, "scaffold"),
68+
],
69+
),
70+
],
71+
)
72+
found1 = ia1.find_overlaps(Fragment("scffld_1", 1, 1250, 1))
73+
assert found1.rows == [frag]
74+
75+
found2 = ia1.find_overlaps(Fragment("scffld_1", 1, 2, 1))
76+
assert found2 is None
77+
78+
ia2 = IndexedAssembly(
79+
"all gaps",
80+
scaffolds=[
81+
Scaffold(
82+
"scffld_1",
83+
rows=[
84+
Gap(200, "scaffold"),
85+
Gap(100, "scaffold"),
86+
Gap(50, "scaffold"),
87+
],
88+
),
89+
],
90+
)
91+
92+
found3 = ia2.find_overlaps(Fragment("scffld_1", 1, 350, 1))
93+
assert found3 is None
94+
95+
5796
def test_find_overlapping():
5897
"""
5998
IndexedAssembly: Random assembly

0 commit comments

Comments
 (0)