diff --git a/protzilla/run.py b/protzilla/run.py index d75de7c1f..97e6054bd 100644 --- a/protzilla/run.py +++ b/protzilla/run.py @@ -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, {}) diff --git a/protzilla/run_helper.py b/protzilla/run_helper.py index f1eabef1e..ac27d0b34 100644 --- a/protzilla/run_helper.py +++ b/protzilla/run_helper.py @@ -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] diff --git a/protzilla/workflow_helper.py b/protzilla/workflow_helper.py index 02039969f..7fa2c067c 100644 --- a/protzilla/workflow_helper.py +++ b/protzilla/workflow_helper.py @@ -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 diff --git a/tests/protzilla/test_run.py b/tests/protzilla/test_run.py index 3b6911ebb..aea477319 100644 --- a/tests/protzilla/test_run.py +++ b/tests/protzilla/test_run.py @@ -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", ) diff --git a/tests/protzilla/test_run_helper.py b/tests/protzilla/test_run_helper.py index 82f180907..a6b8a2fd4 100644 --- a/tests/protzilla/test_run_helper.py +++ b/tests/protzilla/test_run_helper.py @@ -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 @@ -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": ""}, @@ -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" ) diff --git a/tests/protzilla/test_workflow_helper.py b/tests/protzilla/test_workflow_helper.py index 8f684092f..246b98bb0 100644 --- a/tests/protzilla/test_workflow_helper.py +++ b/tests/protzilla/test_workflow_helper.py @@ -124,6 +124,7 @@ 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( @@ -131,6 +132,7 @@ def test_get_workflow_default_param_value(example_workflow): "data_preprocessing", "normalisation", "median", + 5, "output_name", ) output_name_t_test = get_workflow_default_param_value( @@ -138,6 +140,7 @@ def test_get_workflow_default_param_value(example_workflow): "data_analysis", "differential_expression", "t_test", + 1, "output_name", ) @@ -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", ) @@ -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 diff --git a/ui/runs/fields.py b/ui/runs/fields.py index da8432635..66d3b53cb 100644 --- a/ui/runs/fields.py +++ b/ui/runs/fields.py @@ -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 = ""