Skip to content

Commit

Permalink
Merge pull request #202 from medema-group/hotfix/legacy-extend
Browse files Browse the repository at this point in the history
fix reverse extend target index popping
  • Loading branch information
nlouwen authored Oct 30, 2024
2 parents 9758f67 + dd3e34a commit 78d2ba7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions big_scape/comparison/extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def score_extend(
if not match_after_lcs:
score += mismatch

if score > max_score:
if score >= max_score:
max_score = score
query_cds_idx = query_index[query_domain_start + hsp_idx]
query_exp = query_cds_idx + 1 - query_start
Expand Down Expand Up @@ -498,16 +498,17 @@ def score_extend_rev(
if domain_idx < last_domain_idx:
last_domain_idx = domain_idx

# remove the current target index from the index
target_index[hsp.domain].pop(dict_idx)
# remove the current target index from the index, reverse the dict_idx
# since we move through the target index domain lists in reverse
target_index[hsp.domain].pop(-dict_idx - 1)

break

if not match_before_lcs:
score += mismatch
continue

if score > max_score:
if score >= max_score:
max_score = score
query_cds_idx = query_index[query_domain_start - hsp_idx]
query_exp = query_start - query_cds_idx
Expand Down
12 changes: 6 additions & 6 deletions test/comparison/test_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def test_extend_forward_mid_cds_target_start(self):

def test_extend_forward_mid_cds_query_start(self):
"""Tests extend when starting in the middle of cds"""
q_domains = {2: ["X", "X"], 3: ["X", "Q"], 4: ["A", "B"], 5: ["C"]}
q_domains = {2: ["X", "X"], 3: ["X", "Q"], 4: ["A", "C"], 5: ["B"]}
t_domains = {0: ["X"], 1: ["X", "X", "Q"], 2: ["A"], 3: ["B", "C"]}
query_dom, target_dom = generate_mock_lcs_region(6, 5, q_domains, t_domains)

Expand Down Expand Up @@ -716,18 +716,18 @@ def test_extend_rev_double_domains(self):

def test_extend_reverse_mid_cds_starts(self):
"""Tests extend when starting in the middle of cds"""
q_domains = {2: ["C"], 3: ["B", "A"], 4: ["Q", "X"], 5: ["X", "A"]}
t_domains = {0: ["B", "C"], 1: ["A"], 2: ["N", "Q", "X"], 3: ["X"]}
q_domains = {2: ["C"], 3: ["B", "A", "A"], 4: ["Q", "X"], 5: ["X"]}
t_domains = {0: ["B", "C"], 1: ["A"], 2: ["N", "Q", "X"], 3: ["X", "A"]}
query_dom, target_dom = generate_mock_lcs_region(6, 5, q_domains, t_domains)

target_index = bs_comp.extend.get_target_indexes(target_dom)
query_index = bs_comp.extend.get_query_indexes(query_dom)

# four matches QABC, one gap: 4*5 - 2 = 18
expected_extends = (2, 4, 2, 5, 18)
# four matches QABC, one gap, one mismatch (extra A): 4*5 - 2 - 3 = 15
expected_extends = (2, 5, 2, 5, 15)

actual_extends = bs_comp.extend.score_extend_rev(
query_dom, query_index, 2, 4, target_index, 2, 5, 5, -3, -2, 10
query_dom, query_index, 2, 5, target_index, 2, 5, 5, -3, -2, 10
)

self.assertEqual(expected_extends, actual_extends)
Expand Down

0 comments on commit 78d2ba7

Please sign in to comment.