Skip to content

Commit

Permalink
Merge pull request #14332 from bernt-matthias/topic/options-var
Browse files Browse the repository at this point in the history
[22.01] fix `startswith` attribute of `<options>`
  • Loading branch information
mvdbeek authored Jul 24, 2022
2 parents 21a7ad2 + fe06eea commit a20d796
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 17 deletions.
15 changes: 12 additions & 3 deletions lib/galaxy/tool_util/xsd/galaxy.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ exclusively use ``filter``s to populate options.
* ``from_dataset`` - The options for the select list are dynamically obtained
from input dataset selected for the tool from the current history.
* ``from_file`` - The options for the select list are dynamically obtained from
a file. This mechanis is discourage in favor of the more generic
a file. This mechanism is discouraged in favor of the more generic
``from_data_table``.
* ``from_parameter`` - The options for the select list are dynamically obtained
from a parameter.
Expand Down Expand Up @@ -4013,6 +4013,10 @@ Starting from Galaxy v21.01, ``meta_file_key`` can be used together with
medadata file that the ``meta_file_key`` implies, instead of the dataset
itself.
Note that in any case only the first mega byte of the referred dataset (or file)
is considered. Lines starting with ``#`` are ignored. By using the ``startswith``
attribute also lines starting with other strings can be ignored.
```xml
<param name="input" type="data" format="maf" label="MAF File"/>
<param name="species" type="select" optional="False" label="Select species for the input dataset" multiple="True">
Expand Down Expand Up @@ -4087,7 +4091,7 @@ used to generate dynamic options.
</xs:sequence>
<xs:attribute name="from_dataset" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">Determine options from the dataset given in the referred input parameter. If 'meta_file_key' is given, the options are determined from the data in the metadata file of the input.</xs:documentation>
<xs:documentation xml:lang="en">Determine options from (the first MB of) the dataset given in the referred input parameter. If 'meta_file_key' is given, the options are determined from (the first MB of) the data in the metadata file of the input.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="from_file" type="xs:string">
Expand Down Expand Up @@ -4117,14 +4121,19 @@ used to generate dynamic options.
</xs:attribute>
<xs:attribute name="startswith" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">Ignore lines starting with the given character.</xs:documentation>
<xs:documentation xml:lang="en">Ignore lines starting with the given string.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="meta_file_key" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">Works with from_dataset only. See [docs](#from-dataset)</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="separator" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="en">Split tabular data with this character (default is tab)</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
<xs:group name="OptionsElement">
<xs:choice>
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tools/parameters/dynamic_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def parse_file_fields(self, reader):
rval = []
field_count = None
for line in reader:
if line.startswith('#') or (self.line_startswith and not line.startswith(self.line_startswith)):
if line.startswith("#") or (self.line_startswith and line.startswith(self.line_startswith)):
continue
line = line.rstrip("\n\r")
if line:
Expand Down
39 changes: 26 additions & 13 deletions test/functional/tools/options_from_metadata_file.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
<tool id="options_from_metadata_file" name="Test for options from dataset metadata file" version="1.0.0" profile="21.01">
<command><![CDATA[
echo '${species}' > '${output}';
echo '${species_comma}' >> '${output}';
echo '${species_2}' >> '${output}'
]]></command>
<inputs>
<param name="input" type="data" format="maf" label="MAF File"/>
<!-- test meta_file_key to define options-->
<param name="species" type="select" optional="false" label="Select species for the input dataset" multiple="true">
<options from_dataset="input" meta_file_key="species_chromosomes" >
<column name="name" index="0"/>
<column name="value" index="0"/>
<options from_dataset="input" meta_file_key="species_chromosomes">
<column name="name" index="0"/>
<column name="value" index="0"/>
</options>
</param>
<!-- test meta_file_key in combination with separator to define options
(since the metadata file does not contain commas each line gets an option)-->
<param name="species_comma" type="select" optional="false" label="Select species for the input dataset">
<options from_dataset="input" meta_file_key="species_chromosomes" separator=",">
<column name="name" index="0"/>
<column name="value" index="0"/>
</options>
</param>
<param name="input_2" type="data_collection" collection_type="list" format="maf" label="MAF Collection" multiple="true" />
<!-- test meta_file_key referring a collection to define options-->
<param name="input_2" type="data_collection" collection_type="list" format="maf" label="MAF Collection" multiple="true"/>
<param name="species_2" type="select" optional="false" label="Select species for the input dataset" multiple="true">
<options from_dataset="input_2" meta_file_key="species_chromosomes" >
<options from_dataset="input_2" meta_file_key="species_chromosomes">
<column name="name" index="0"/>
<column name="value" index="0"/>
<filter type="unique_value" name="unique_param" column="0"/>
</options>
</param>
</inputs>
<outputs>
<data format="txt" name="output" />
<data format="txt" name="output"/>
</outputs>
<tests>
<test>
<param name="input" value="3.maf" ftype="maf" />
<param name="species" value="hg17,canFam1" />
<param name="input" value="3.maf" ftype="maf"/>
<param name="species" value="hg17,canFam1"/>
<param name="species_comma" value="hg17&#009;chr7"/>
<param name="input_2">
<collection type="list">
<element name="e1" value="3.maf" />
<element name="e2" value="4.maf" />
<element name="e1" value="3.maf"/>
<element name="e2" value="4.maf"/>
</collection>
</param>
<param name="species_2" value="panTro1,rn3,bosTau2" />
<param name="species_2" value="panTro1,rn3,bosTau2"/>
<output name="output" ftype="txt">
<assert_contents>
<has_line line="hg17,canFam1" />
<has_line line="panTro1,rn3,bosTau2" />
<has_line line="hg17,canFam1"/>
<has_line line="hg17__tc__chr7"/>
<has_line line="panTro1,rn3,bosTau2"/>
</assert_contents>
</output>
</test>
Expand Down
1 change: 1 addition & 0 deletions test/functional/tools/samples_tool_conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<tool file="filter_param_value_ref_attribute.xml" />
<tool file="filter_static_regexp.xml" />
<tool file="select_from_dataset.xml" />
<tool file="select_from_csvdataset.xml" />
<tool file="select_from_dataset_optional.xml" />
<tool file="dbkey_filter_input.xml" />
<tool file="dbkey_filter_multi_input.xml" />
Expand Down
40 changes: 40 additions & 0 deletions test/functional/tools/select_from_csvdataset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<tool id="select_from_csvdataset" name="select_from_csvdataset" version="0.1.0">
<description>Create dynamic options from CSV data sets</description>
<command><![CDATA[
echo select_single '$select_single' > '$output'
]]></command>
<inputs>
<param name="single" type="data" format="csv" label="single"/>
<param name="select_single" type="select" label="select_single">
<options from_dataset="single" separator="," startswith="Transaction_date">
<column name="name" index="1"/>
<column name="value" index="2"/>
<validator type="no_options" message="No data is available in single" />
</options>
</param>
</inputs>

<outputs>
<data name="output" format="txt" />
</outputs>

<tests>
<!-- test that csv can be selected, i.e. if the separator attribute of <options> works-->
<test>
<param name="single" value="1.csv" />
<param name="select_single" value="Product1" />
<output name="output">
<assert_contents>
<has_text text="select_single 1200" />
</assert_contents>
</output>
</test>
<!-- test that data from "comment" lines can not be selected, i.e. if the startswith attribute of <options> works-->
<test expect_failure="true">
<param name="single" value="1.csv" />
<param name="select_single" value="Product" />
</test>
</tests>
<help>
</help>
</tool>

0 comments on commit a20d796

Please sign in to comment.