Skip to content

Commit

Permalink
Added tests for ShigaPass
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkc committed May 30, 2024
1 parent a0cdbcd commit 100da62
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Fixtures"""

from .ecoli import *
from .shigella import *
from .saureus import *
from .mtuberculosis import *
9 changes: 9 additions & 0 deletions tests/fixtures/shigella/__init__.py
Original file line number Diff line number Diff line change
@@ -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"))
5 changes: 5 additions & 0 deletions tests/fixtures/shigella/shigapass.csv
Original file line number Diff line number Diff line change
@@ -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;;
69 changes: 69 additions & 0 deletions tests/parse/test_shigapass.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 100da62

Please sign in to comment.