Skip to content

Commit

Permalink
Merge pull request #454 from jeromekelleher/fix-match-hmm-bug
Browse files Browse the repository at this point in the history
Fix bug in run_hmm
  • Loading branch information
jeromekelleher authored Dec 17, 2024
2 parents 12842dd + cfe1dca commit 900300a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sc2ts/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,10 +1867,12 @@ def run_hmm(
if mismatch_threshold is None:
mismatch_threshold = 100

directions = ["forward", "reverse"]
if direction not in directions:
raise ValueError(f"Direction must be one of {directions}")

ds = _dataset.Dataset(dataset_path)
ts = tszip.load(ts_path)
if len(strains) == 0:
return
progress_title = "Match"
samples = preprocess(
list(strains),
Expand Down
20 changes: 20 additions & 0 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,26 @@ def test_match_recombinant(self, fx_ts_map):
assert m.path[1].right == ts.sequence_length


class TestRunHmm:

@pytest.mark.parametrize("direction", ["F", "R", "forwards", "backwards", "", None])
def test_bad_direction(self, fx_dataset, fx_ts_map, direction):
strain = "SRR11597164"
ts = fx_ts_map["2020-02-01"]
with pytest.raises(ValueError, match="Direction must be one of"):
sc2ts.run_hmm(
fx_dataset.path,
ts.path,
[strain],
direction=direction,
num_mismatches=3,
)

def test_no_strains(self, fx_dataset, fx_ts_map):
ts = fx_ts_map["2020-02-01"]
assert len(sc2ts.run_hmm(fx_dataset.path, ts.path, [], num_mismatches=3)) == 0


class TestCharacteriseRecombinants:

def test_example_1(self, fx_ts_map):
Expand Down

0 comments on commit 900300a

Please sign in to comment.