Skip to content

Commit

Permalink
get_workflow_default_param_value is based in step_index_in_current_s…
Browse files Browse the repository at this point in the history
…ection (#269)

* get_workflow_default_param_value uses now step_index_in_current_section

* fixed tests
  • Loading branch information
saragrau authored Oct 12, 2023
1 parent 2ee6ad0 commit 252f8e4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
5 changes: 4 additions & 1 deletion protzilla/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ def delete_step(self, section, index):
def next_step(self, name=None):
if not name:
name = get_workflow_default_param_value(
self.workflow_config, *self.current_run_location(), "output_name"
self.workflow_config,
*self.current_run_location(),
self.step_index_in_current_section(),
"output_name",
)
try:
parameters = self.current_parameters.get(self.calculated_method, {})
Expand Down
7 changes: 6 additions & 1 deletion protzilla/run_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ def get_parameters(run, section, step, method):

for key, param_dict in parameters.items():
workflow_default = get_workflow_default_param_value(
run.workflow_config, section, step, method, key
run.workflow_config,
section,
step,
method,
run.step_index_in_current_section(),
key,
)
if method in run.current_parameters and key in run.current_parameters[method]:
param_dict["default"] = run.current_parameters[method][key]
Expand Down
22 changes: 11 additions & 11 deletions protzilla/workflow_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ def get_parameter_type(workflow_meta, section, step, method, param):
return workflow_meta[section][step][method]["parameters"][param]["type"]


def get_workflow_default_param_value(workflow_config, section, step, method, param):
# TODO 163: this should be based on step_index as there can be multiple steps with the same name
steps = workflow_config["sections"][section]["steps"]
for step_dict in steps:
if step_dict["name"] == step and step_dict["method"] == method:
if param in step_dict["parameters"]:
return step_dict["parameters"][param]
elif param in step_dict:
return step_dict[param]
else:
return None
def get_workflow_default_param_value(
workflow_config, section, step, method, step_index_in_section, param
):
step_dict = workflow_config["sections"][section]["steps"][step_index_in_section]
if step_dict["name"] == step and step_dict["method"] == method:
if param in step_dict["parameters"]:
return step_dict["parameters"][param]
elif param in step_dict:
return step_dict[param]
else:
return None
return None


Expand Down
1 change: 1 addition & 0 deletions tests/protzilla/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def test_name_step(example_workflow_short, tests_folder_name):
"importing",
"ms_data_import",
"max_quant_import",
run.step_index_in_current_section(),
"output_name",
)

Expand Down
4 changes: 3 additions & 1 deletion tests/protzilla/test_run_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import copy
from unittest.mock import MagicMock, Mock
from unittest.mock import MagicMock, Mock, patch

import pandas as pd
import pytest
Expand Down Expand Up @@ -54,6 +54,7 @@ def test_get_parameters():
}
}
}
run.step_index_in_current_section.return_value = 0
expected = {
"param1": {"default": "current1", "type": ""},
"param2": {"default": "config2", "type": ""},
Expand All @@ -67,6 +68,7 @@ def test_get_parameters_no_side_effects(workflow_meta, example_workflow):
run.workflow_meta = copy.deepcopy(workflow_meta)
run.current_parameters = {"strategy": "median"}
run.workflow_config = copy.deepcopy(example_workflow)
run.step_index_in_current_section.return_value = 5
get_parameters(
run, "data_preprocessing", "imputation", "simple_imputation_per_protein"
)
Expand Down
5 changes: 5 additions & 0 deletions tests/protzilla/test_workflow_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,23 @@ def test_get_workflow_default_param_value(example_workflow):
"data_preprocessing",
"filter_proteins",
"samples_missing_filter",
0,
"percentage",
)
output_name = get_workflow_default_param_value(
example_workflow,
"data_preprocessing",
"normalisation",
"median",
5,
"output_name",
)
output_name_t_test = get_workflow_default_param_value(
example_workflow,
"data_analysis",
"differential_expression",
"t_test",
1,
"output_name",
)

Expand All @@ -152,6 +155,7 @@ def test_get_workflow_default_param_value_nonexistent(example_workflow_short):
"data_preprocessing",
"filter_samples",
"protein_intensity_sum_filter",
0,
"threshold",
)

Expand All @@ -165,6 +169,7 @@ def test_test_get_workflow_default_param_value_no_side_effects(example_workflow)
"data_preprocessing",
"filter_proteins",
"samples_missing_filter",
0,
"percentage",
)
assert example_workflow == example_workflow_copy
Expand Down
5 changes: 4 additions & 1 deletion ui/runs/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ def make_name_field(allow_next, form, run, end_of_run):
if end_of_run:
return ""
default = get_workflow_default_param_value(
run.workflow_config, *run.current_run_location(), "output_name"
run.workflow_config,
*run.current_run_location(),
run.step_index_in_current_section(),
"output_name",
)
if not default:
default = ""
Expand Down

0 comments on commit 252f8e4

Please sign in to comment.