Skip to content

Commit

Permalink
tests & fixes for hgvs parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Aug 25, 2024
1 parent c4b6ed1 commit 746e91c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
9 changes: 5 additions & 4 deletions countess/plugins/hgvs_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import pandas as pd
import numpy as np

from countess import VERSION
from countess.core.parameters import BooleanParam, ColumnChoiceParam, ColumnOrNoneChoiceParam, IntegerParam, StringParam
Expand All @@ -25,10 +26,10 @@ def process_dict(self, data: dict):
try:
value = data[str(self.column)]
except KeyError:
return None
return {}

if value is None:
return None
if type(value) is not str:
return {}

output = {}

Expand Down Expand Up @@ -56,7 +57,7 @@ def process_dict(self, data: dict):
max_variations = int(self.max_var)
variations = [v for v in variations if v not in guides]
if len(variations) > max_variations:
return None
return {}

output_vars: list[Optional[str]] = [None] * max_variations
output_locs: list[Optional[str]] = [None] * max_variations
Expand Down
23 changes: 19 additions & 4 deletions tests/plugins/test_hgvs_parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import sys
from time import sleep

import numpy as np
import pandas as pd
import pytest

from countess.plugins.hgvs_parser import HgvsParserPlugin

Expand Down Expand Up @@ -76,3 +73,21 @@ def test_hgvs_parser_split_and_multi():
assert df["var"].iloc[1] == "A>G"
assert df["loc"].iloc[0] == "43124175"
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]"}]
)

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

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])

0 comments on commit 746e91c

Please sign in to comment.