From 2e33be78acf4a7a0bf343d78b4f52b9a6edc88a3 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Thu, 9 Dec 2021 23:11:02 +0100 Subject: [PATCH] make param_value filter work with multi data inputs ie data with multiple=true and collections --- .../tools/parameters/dynamic_options.py | 30 +++-- test/functional/tools/filter_param_value.xml | 6 +- .../filter_param_value_ref_attribute.xml | 116 ++++++++++++++++++ test/functional/tools/samples_tool_conf.xml | 1 + 4 files changed, 142 insertions(+), 11 deletions(-) create mode 100644 test/functional/tools/filter_param_value_ref_attribute.xml diff --git a/lib/galaxy/tools/parameters/dynamic_options.py b/lib/galaxy/tools/parameters/dynamic_options.py index fcf17f71569..b10af39e191 100644 --- a/lib/galaxy/tools/parameters/dynamic_options.py +++ b/lib/galaxy/tools/parameters/dynamic_options.py @@ -272,19 +272,31 @@ class ParamValueFilter(Filter): if trans is not None and trans.workflow_building_mode: return [] ref = other_values.get(self.ref_name, None) - for ref_attribute in self.ref_attribute: - if not hasattr(ref, ref_attribute): - return [] # ref does not have attribute, so we cannot filter, return empty list - ref = getattr(ref, ref_attribute) if ref is None: ref = [] - elif isinstance(ref, list): - ref = [str(_) for _ in ref] - else: - ref = [str(ref)] + + # - for HDCAs the list of contained HDAs is extracted + # - single values are transformed in a single eleent list + # - remaining cases are already lists (select and data parameters with multiple=true) + if isinstance(ref, HistoryDatasetCollectionAssociation): + ref = ref.to_hda_representative(multiple=True) + elif not isinstance(ref, list): + ref = [ref] + + ref_values = [] + for r in ref: + for ref_attribute in self.ref_attribute: + # ref does not have attribute, so we cannot filter, + # but other refs might have it + if not hasattr(r, ref_attribute): + break + r = getattr(r, ref_attribute) + ref_values.append(r) + ref_values = [str(_) for _ in ref_values] + rval = [] for fields in options: - if self.keep == (fields[self.column] in ref): + if self.keep == (fields[self.column] in ref_values): rval.append(fields) return rval diff --git a/test/functional/tools/filter_param_value.xml b/test/functional/tools/filter_param_value.xml index 248d07976b7..9dc13e8a5a3 100644 --- a/test/functional/tools/filter_param_value.xml +++ b/test/functional/tools/filter_param_value.xml @@ -13,11 +13,13 @@ - + - + diff --git a/test/functional/tools/filter_param_value_ref_attribute.xml b/test/functional/tools/filter_param_value_ref_attribute.xml new file mode 100644 index 00000000000..68439df520f --- /dev/null +++ b/test/functional/tools/filter_param_value_ref_attribute.xml @@ -0,0 +1,116 @@ + + Filter input with the param_value + > '$output' && + #end if + #if $select_mult + echo $select_mult >> '$output' && + #end if + #if $select_coll + echo $select_coll >> '$output' && + #end if + true + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/functional/tools/samples_tool_conf.xml b/test/functional/tools/samples_tool_conf.xml index f62d6acbbaf..92870be5a6e 100644 --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -48,6 +48,7 @@ +