Skip to content

Commit

Permalink
fix for saving & restoring ColumnOrStringParam value
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Apr 5, 2024
1 parent 1c32a04 commit c960dcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
18 changes: 6 additions & 12 deletions countess/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,21 +417,15 @@ def get_column_name(self):

def get_value(self, data: dict):
if self.value.startswith(self.PREFIX):
return data[self.value[len(self.PREFIX):]]
return data[self.value[len(self.PREFIX) :]]
else:
return self.value


class ColumnOrIntegerParam(ColumnOrStringParam):
def clean_value(self, value):
if isinstance(value, str):
return int("".join(re.split(r"\D+", value)))
else:
return int(value)


class MultipleChoiceParam(ChoiceParam):
pass
def set_choices(self, choices: Iterable[str]):
self.choices = list(choices)
if self._value is not None and self._value.startswith(self.PREFIX) and self._value not in self.choices:
self._value = self.DEFAULT_VALUE
self._choice = None


class ArrayParam(BaseParam):
Expand Down
1 change: 1 addition & 0 deletions countess/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def update(self):
elif isinstance(self.parameter, ChoiceParam):
choices = self.parameter.choices or [""]
self.entry["values"] = choices
self.var.set(self.parameter.value)
elif isinstance(self.parameter, BooleanParam):
self.set_checkbox_value()
elif isinstance(self.parameter, TextParam):
Expand Down
22 changes: 21 additions & 1 deletion tests/plugins/test_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@

logger = MultiprocessLogger()

def test_variant_ref_value():
input_df = pd.DataFrame(
[{"seq": "TGAAGTAGAGG"}, {"seq": "AGAAGTTGTGG"}, {"seq": "ATAAGAAGAGG"}]
)
plugin = VariantPlugin()
plugin.set_parameter("column", "seq")
plugin.set_parameter("reference", "AGAAGTAGAGG")
plugin.set_parameter("output", "out")

plugin.prepare(["test"], None)

output_df = plugin.process_dataframe(input_df, logger)

output = output_df.to_records()

assert output[0]["out"] == "g.1A>T"
assert output[1]["out"] == "g.[7A>T;9A>T]"
assert output[2]["out"] == "g.[2G>T;6T>A]"



def test_variant_ref_column():
input_df = pd.DataFrame(
Expand All @@ -14,7 +34,7 @@ def test_variant_ref_column():

plugin = VariantPlugin()
plugin.set_parameter("column", "seq")
plugin.set_parameter("reference", "ref")
plugin.set_parameter("reference", "ref")
plugin.set_parameter("output", "out")

plugin.prepare(["test"], None)
Expand Down

0 comments on commit c960dcf

Please sign in to comment.