Skip to content

Commit

Permalink
tests for hgvs parsed plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Aug 29, 2024
1 parent 3ef5c5f commit 5e6662e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions countess/plugins/hgvs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def process_dict(self, data: dict):
if self.guides_str:
guides += self.guides_str.value.split(";")

if m := re.match(r"([\w.]+):([ncg].)(.*)", value):
output["reference"] = m.group(1)
if m := re.match(r"(?:([\w.]+):)?([ncg]\.)(.*)", value):
output["reference"] = m.group(1) or ''
output["prefix"] = m.group(2)
value = m.group(3)

Expand Down
20 changes: 15 additions & 5 deletions tests/plugins/test_hgvs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_hgvs_parser_split_and_multi():
assert df["loc"].iloc[1] == "43124111"


df2 = pd.DataFrame([{"fnords": "whatever"}, {"hgvs": None}, {"hgvs": "g.="}, {"hgvs": "g.[1A>T;2G>C;3C>T;4A>T;5A>T]"}])
df2 = pd.DataFrame([{"fnords": "whatever"}, {"hgvs": None}, {"hgvs": "g.[1A>T;2G>C;3C>T;4A>T;5A>T]"}])


def test_hgvs_parser_bad():
Expand All @@ -85,7 +85,17 @@ def test_hgvs_parser_bad():
df = plugin.process_dataframe(df2)

print(df)
assert np.isnan(df["var_1"].iloc[0])
assert np.isnan(df["var_1"].iloc[1])
assert df["var_1"].iloc[2] == "g.="
assert np.isnan(df["var_1"].iloc[3])
assert all(np.isnan(df["var_1"]))
#assert np.isnan(df["var_1"].iloc[0])
#assert np.isnan(df["var_1"].iloc[1])
#assert np.isnan(df["var_1"].iloc[2])


def test_hgvs_parser_very_bad():
plugin = HgvsParserPlugin()
plugin.set_parameter("column", "hgvs")

dfi = pd.DataFrame([{'a': 1}])
dfo = plugin.process_dataframe(dfi)

assert all(dfo == dfi)

0 comments on commit 5e6662e

Please sign in to comment.