Skip to content

Commit

Permalink
Cigar tools: fix strips of empty queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Nov 14, 2023
1 parent 98e9240 commit 38f8833
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions micall/tests/test_cigar_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,35 @@ def test_cigar_hit_strip_combines_with_connect(hit, cut_point):
assert left.connect(right).coordinate_mapping == hit.coordinate_mapping


@pytest.mark.parametrize('hit', [x[0] for x in cigar_hit_ref_cut_cases])
def test_cigar_hit_strip_never_crashes(hit):
hit.rstrip_query().lstrip_query()
hit.lstrip_query().rstrip_query()
hit.lstrip_query().lstrip_query()
hit.rstrip_query().rstrip_query()


@pytest.mark.parametrize('hit', [x[0] for x in cigar_hit_ref_cut_cases])
def test_cigar_hit_strip_is_idempotent(hit):
h1 = hit.rstrip_query()
assert h1 == h1.rstrip_query() == h1.rstrip_query().rstrip_query()

h1 = hit.lstrip_query()
assert h1 == h1.lstrip_query() == h1.lstrip_query().lstrip_query()

h1 = hit.lstrip_query().rstrip_query()
assert h1 == h1.lstrip_query() == h1.rstrip_query()

h1 = hit.rstrip_query().lstrip_query()
assert h1 == h1.rstrip_query() == h1.lstrip_query()


@pytest.mark.parametrize('hit', [x[0] for x in cigar_hit_ref_cut_cases])
def test_cigar_hit_strips_are_commutative(hit):
assert hit.rstrip_query().lstrip_query() \
== hit.lstrip_query().rstrip_query()


@pytest.mark.parametrize('hit, cut_point', [(x[0], x[1]) for x in cigar_hit_ref_cut_cases
if not isinstance(x[2], Exception)
and not 'N' in str(x[0].cigar)])
Expand Down
4 changes: 2 additions & 2 deletions micall/utils/cigar_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def cut_reference(self, cut_point: float) -> Tuple['CigarHit', 'CigarHit']:
def lstrip_query(self) -> 'CigarHit':
""" Return a copy of the CigarHit with leading (unmatched) query elements removed. """

if self.query_length == 0:
if len(self.coordinate_mapping.ref_to_query) == 0:
return self

closest_ref = self.coordinate_mapping.ref_to_query.closest_key(self.r_st - 1)
Expand All @@ -591,7 +591,7 @@ def lstrip_query(self) -> 'CigarHit':
def rstrip_query(self) -> 'CigarHit':
""" Return a copy of the CigarHit with trailing (unmatched) query elements removed. """

if self.query_length == 0:
if len(self.coordinate_mapping.ref_to_query) == 0:
return self

closest_ref = self.coordinate_mapping.ref_to_query.closest_key(self.r_ei + 1)
Expand Down

0 comments on commit 38f8833

Please sign in to comment.