diff --git a/tests/fixtures/__init__.py b/tests/fixtures/__init__.py index 44a6771..a029185 100644 --- a/tests/fixtures/__init__.py +++ b/tests/fixtures/__init__.py @@ -1,5 +1,6 @@ """Fixtures""" from .ecoli import * +from .shigella import * from .saureus import * from .mtuberculosis import * diff --git a/tests/fixtures/shigella/__init__.py b/tests/fixtures/shigella/__init__.py new file mode 100644 index 0000000..567f6dd --- /dev/null +++ b/tests/fixtures/shigella/__init__.py @@ -0,0 +1,9 @@ +"""Fixtures for Shigella.""" +import pytest + +from ..fixtures import data_path + +@pytest.fixture() +def shigella_shigapass_path(data_path): + """Get path for Shigapass results for shigella.""" + return str(data_path.joinpath("shigella", "shigapass.csv")) \ No newline at end of file diff --git a/tests/fixtures/shigella/shigapass.csv b/tests/fixtures/shigella/shigapass.csv new file mode 100644 index 0000000..ab765fc --- /dev/null +++ b/tests/fixtures/shigella/shigapass.csv @@ -0,0 +1,5 @@ +Name;rfb;rfb_hits,(%);MLST;fliC;CRISPR;ipaH;Predicted_Serotype;Predicted_FlexSerotype;Comments +ERR5888634;C2;79,(48.2%);ST145;ShH57(ShH3cplx);A-var2;ipaH+;SB2;; +ERR5952732;B1-5;139,(93.3%);ST245;ShH2(ShH2cplx);A-var3,x,16;ipaH+;SF1-5;1b; +ERR5976293;D;202,(70.6%);ST152;ShH25(ShH1cplx);A-var0,27;ipaH+;SS;; +ERR5982186;A2;100,(61.7%);ST147;none;A-var1,12,3,5,11-var1;ipaH+;SD2;; diff --git a/tests/parse/test_shigapass.py b/tests/parse/test_shigapass.py new file mode 100644 index 0000000..199ae38 --- /dev/null +++ b/tests/parse/test_shigapass.py @@ -0,0 +1,69 @@ +"""Test functions for parsing Shigapass results.""" + +import pytest +from prp.parse.phenotype.shigapass import parse_shigapass_pred, _extract_percentage + + +@pytest.mark.parametrize( + "input,expected", + [ + ("79,(48.2%)", 48.2), + ("79,(48.0%)", 48.0), + ("79,(48%)", 48.0), + ("NA,(0.0%)", 0.0), + ("NA,(0%)", 0.0), + ], +) +def test_extract_percentage(input, expected): + """ + Test that the percentage can be extracted from rfb_hits. + + "foo, (12%)" -> 12% + """ + result = _extract_percentage(input) + assert result == expected + + +def test_parse_shigapass_results(ecoli_shigapass_path, shigella_shigapass_path): + """Test parsing of shigapass result files.""" + + # test parsing the output of an ecoli. + result = parse_shigapass_pred(ecoli_shigapass_path) + expected_ecoli = { + "type": "shigatype", + "software": "shigapass", + "result": { + "rfb": None, + "rfb_hits": 0.0, + "mlst": None, + "flic": None, + "crispr": None, + "ipah": "ipaH-", + "predicted_serotype": "Not Shigella/EIEC", + "predicted_flex_serotype": None, + "comments": None, + }, + } + # check if data matches + assert expected_ecoli == result[0].model_dump() + + # test parsing the output with a shigella. + result = parse_shigapass_pred(shigella_shigapass_path) + expected_shigella = { + "type": "shigatype", + "software": "shigapass", + "result": { + "rfb": "C2", + "rfb_hits": 48.2, + "mlst": "ST145", + "flic": "ShH57(ShH3cplx)", + "crispr": "A-var2", + "ipah": "ipaH+", + "predicted_serotype": "SB2", + "predicted_flex_serotype": None, + "comments": None, + }, + } + + # check if data matches + assert expected_shigella == result[0].model_dump()