Merge pull request #14510 from mvdbeek/fix_metadata_action_default_setting_in_conditional

[22.05] Fix setting metadata elements in conditional tool action
This commit is contained in:
Björn Grüning
2022-08-25 20:14:21 +02:00
committed by GitHub
3 changed files with 31 additions and 28 deletions
+13 -3
View File
@@ -7,6 +7,7 @@ import os.path
import re
from galaxy import util
from galaxy.util.template import fill_template
log = logging.getLogger(__name__)
@@ -81,7 +82,7 @@ class ValueToolOutputActionConditionalWhen(ToolOutputActionConditionalWhen):
def is_case(self, output_dataset, other_values):
ref = self.get_ref(output_dataset, other_values)
return bool(str(ref) == self.value)
return ref == self.value
class DatatypeIsInstanceToolOutputActionConditionalWhen(ToolOutputActionConditionalWhen):
@@ -304,8 +305,17 @@ class MetadataToolOutputAction(ToolOutputAction):
def apply_action(self, output_dataset, other_values):
value = self.option.get_value(other_values)
if value is None and self.default is not None:
value = self.default
# TODO: figure out correct type based on MetadataElementSpec,
# but MetadataElementSpec doesn't actually define a type (but it should).
# That would avoid the ad-hoc comma splitting here for defaults.
if self.default:
# For historical reasons the default value takes preference over value,
# and we only treat the default value as potentially containing cheetah.
value = fill_template(
self.default,
context=other_values,
python_template_version=other_values.get("__python_template_version__"),
).split(",")
if value is not None:
setattr(output_dataset.metadata, self.name, value)
+2 -25
View File
@@ -538,12 +538,9 @@ class DefaultToolAction(ToolAction):
if output.actions:
# Apply pre-job tool-output-dataset actions; e.g. setting metadata, changing format
output_action_params = dict(out_data)
output_action_params.update(incoming)
output_action_params.update(wrapped_params.params)
output_action_params["__python_template_version__"] = tool.python_template_version
output.actions.apply_action(data, output_action_params)
# Also set the default values of actions of type metadata
self.set_metadata_defaults(
output, data, tool, on_text, trans, incoming, history, wrapped_params.params, job_params
)
# Flush all datasets at once.
return data
@@ -913,26 +910,6 @@ class DefaultToolAction(ToolAction):
job_params=job_params,
)
def set_metadata_defaults(self, output, dataset, tool, on_text, trans, incoming, history, params, job_params):
"""
This allows to map names of input files to metadata default values. Example:
.. code-block::
<data format="tabular" name="output" label="Tabular output, aggregates data from individual_inputs" >
<actions>
<action name="column_names" type="metadata" default="${','.join(input.name for input in $individual_inputs)}" />
</actions>
</data>
"""
if output.actions:
for action in output.actions.actions:
if action.tag == "metadata" and action.default:
metadata_new_value = fill_template(
action.default, context=params, python_template_version=tool.python_template_version
).split(",")
dataset.metadata.__setattr__(str(action.name), metadata_new_value)
def _get_default_data_name(
self, dataset, tool, on_text=None, trans=None, incoming=None, history=None, params=None, job_params=None, **kwd
):
@@ -4,6 +4,7 @@
]]></command>
<inputs>
<param name="input" type="data" multiple="false" />
<param name="the_conditional" type="boolean" checked="true" />
</inputs>
<outputs>
<data format="tabular" name="output">
@@ -11,6 +12,18 @@
<action name="column_names" type="metadata" default="First,${input.element_identifier}" />
</actions>
</data>
<data format="tabular" name="output_conditional_metadata">
<actions>
<conditional name="the_conditional">
<when value="true">
<action name="column_names" type="metadata" default="True,${input.element_identifier}" />
</when>
<when value="false">
<action name="column_names" type="metadata" default="False,${input.element_identifier}" />
</when>
</conditional>
</actions>
</data>
</outputs>
<tests>
<test>
@@ -18,6 +31,9 @@
<output name="output">
<metadata name="column_names" value="First,2.tabular"/>
</output>
<output name="output_conditional_metadata">
<metadata name="column_names" value="True,2.tabular" />
</output>
</test>
</tests>
</tool>