Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix docs for format_source #19330

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/galaxy/tool_util/xsd/galaxy.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3801,7 +3801,7 @@ In output filters sections are represented as dictionary with the same name as t
In order to reference parameters in sections from tags in the `<outputs>` section, e.g. in the `format_source` attribute of `<data>` tags, the syntax is currently:

```
<data name="output" format_source="parameter_name" metadata_source="parameter_name"/>
<data name="output" format_source="section|parameter_name" metadata_source="section|parameter_name"/>
```

Note that references to other parameters in the `<inputs>` section are only possible if the reference is in the same section or its parents (and is defined earlier), therefore only `parameter_name` is used.
Expand Down Expand Up @@ -5949,7 +5949,7 @@ discovered data sets on Galaxy versions prior to 24.0 and should be specified us
</xs:attribute>
<xs:attribute name="format_source" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">This sets the data type of the output dataset(s) to be the same format as that of the specified tool input.</xs:documentation>
<xs:documentation xml:lang="en">This sets the data type of the output dataset(s) to be the same format as that of the specified tool input. References to parameters in sections or conditionals must be qualified using ``|`` syntax. Elements of collection parameters can be referred to by pythons element access syntax.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="label" type="xs:string">
Expand Down Expand Up @@ -6063,8 +6063,10 @@ same as that of the input dataset selected (and named ``input1``) for the tool.

The following will create datasets in the history panel, setting the output data
type to be the same as that of an input dataset named by the ``format_source``
attribute. Note that a conditional name is not included, so 2 separate
conditional blocks should not contain parameters with the same name.
attribute. If the parameter is contained in sections or conditionals they need
to be listed separated by ``|``. If the referred parameter is a collection, collection
elements can be referred python's element access syntax, e.g. ``input_collection["forward"]``
would refer to the forward dataset of a paired collection.

```xml
<inputs>
Expand All @@ -6085,7 +6087,7 @@ conditional blocks should not contain parameters with the same name.
<outputs>
<data format_source="fasta" name="trim_fasta"
label="${tool.name} on ${on_string}: trim.fasta"/>
<data format_source="qfile" name="trim_qual"
<data format_source="qual|qfile" name="trim_qual"
label="${tool.name} on ${on_string}: trim.qual">
<filter>qual['add'] == 'yes'</filter>
</data>
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/tools/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ def determine_output_format(
pass
ext = random_input_ext
format_source = output.format_source
log.error(f"{format_source=} {input_datasets=} {format_source in input_datasets=}")
if format_source is not None and format_source in input_datasets:
try:
input_dataset = input_datasets[output.format_source]
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/tools/parameters/wrapped.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from collections import UserDict
from typing import (
Any,
Expand Down Expand Up @@ -30,6 +31,7 @@
split_flattened_repeat_key,
)

log = logging.getLogger(__name__)
PARAMS_UNWRAPPED = object()


Expand All @@ -47,11 +49,13 @@ def set_legacy_alias(self, new_key: str, old_key: str):
self._legacy_mapping[old_key] = new_key

def __getitem__(self, key):
# log.error(f"__getitem__ {key=} {self.data=} {self._legacy_mapping=}")
if key not in self.data and key in self._legacy_mapping:
return super().__getitem__(self._legacy_mapping[key])
return super().__getitem__(key)

def __contains__(self, key: object) -> bool:
log.error(f"__contains__ {key=} {self.data=} {self._legacy_mapping=}")
if super().__contains__(key):
return True
return key in self._legacy_mapping
Expand Down
20 changes: 15 additions & 5 deletions test/functional/tools/format_source_in_conditional.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<tool id="format_source_in_conditional" name="format source in conditional" version="0.1.0">
<command>cp '$input1' '$output1'</command>
<command><![CDATA[
cp '$input1' '$output1' &&
cp '$input1' '$output2' &&
cp '$input1' '$output3'
]]></command>
<inputs>
<conditional name="cond">
<param name="select" type="select">
Expand All @@ -15,14 +19,16 @@
<option value="value">the only option</option>
</param>
<when value="value">
<param name="input1" type="data" format="txt"/>
<param name="input1" type="data" format="tsv"/>
</when>
</conditional>
</when>
</conditional>
</inputs>
<outputs>
<data name="output1" format_source="cond|input1"/>
<data name="output1" format_source="cond|input1"/><!-- format_source should work for both cases -->
<data name="output2" format_source="cond|inner_cond|input1"/><!-- format_source should only work for "extra_nesting" -->
<data name="output3" format_source="input1"/><!-- format_source with legacy behavior -->
</outputs>
<tests>
<test>
Expand All @@ -31,15 +37,19 @@
<param name="input1" value="1.tabular" ftype="tabular"/>
</conditional>
<output name="output1" value="1.tabular" ftype="tabular" lines_diff="2"/>
<output name="output2" value="1.tabular" ftype="data" lines_diff="2"/>
<output name="output3" value="1.tabular" ftype="tabular" lines_diff="2"/>
</test>
<test>
<conditional name="cond">
<param name="select" value="extra_nesting"/>
<conditional name="inner_cond">
<param name="input1" value="1.txt" ftype="txt"/>
<param name="input1" value="1.tabular" ftype="tsv"/>
</conditional>
</conditional>
<output name="output1" value="1.txt" ftype="txt"/>
<output name="output1" value="1.tabular" ftype="tsv" lines_diff="2"/>
<output name="output2" value="1.tabular" ftype="tsv" lines_diff="2"/>
<output name="output3" value="1.tabular" ftype="data" lines_diff="2"/>
</test>
</tests>
</tool>
Loading