Skip to content

Commit

Permalink
Parameter models for multiple=true data column data parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 11, 2024
1 parent c6ea4d3 commit 67dc43f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/galaxy/tool_util/parameters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ def _from_input_source_galaxy(input_source: InputSource) -> ToolParameterT:
options=static_options,
)
elif param_type == "data_column":
multiple = input_source.get_bool("multiple", False)
return DataColumnParameterModel(
name=input_source.parse_name(),
multiple=multiple,
)
elif param_type == "group_tag":
multiple = input_source.get_bool("multiple", False)
Expand Down
6 changes: 5 additions & 1 deletion lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,14 @@ def any_drill_down_options_selected(options: List[DrillDownOptionsDict]) -> bool

class DataColumnParameterModel(BaseGalaxyToolParameterModelDefinition):
parameter_type: Literal["gx_data_column"] = "gx_data_column"
multiple: bool

@property
def py_type(self) -> Type:
return StrictInt
py_type: Type = StrictInt
if self.multiple:
py_type = list_type(py_type)
return py_type

def pydantic_template(self, state_representation: StateRepresentationT) -> DynamicModelInformation:
return dynamic_model_information_from_py_type(self, self.py_type)
Expand Down
28 changes: 28 additions & 0 deletions test/functional/tools/parameters/data_column_multiple_optional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<tool id="gx_data_column_multiple_optional" name="gx_data_column_multiple_optional" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" multiple="true" optional="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1,2,3" />
<expand macro="assert_output">
<has_line line="parameter: 1,2,3"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: None"/>
</expand>
</test>
</tests>
</tool>
36 changes: 36 additions & 0 deletions test/functional/tools/parameters/gx_data_column_multiple.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<tool id="gx_data_column_multiple" name="gx_data_column_multiple" version="1.0.0">
<macros>
<import>macros.xml</import>
</macros>
<command><![CDATA[
echo 'parameter: $parameter' >> '$output'
]]></command>
<inputs>
<param name="ref_parameter" type="data" format="tabular" />
<param name="parameter" type="data_column" data_ref="ref_parameter" multiple="true" />
</inputs>
<expand macro="simple_text_output" />
<tests>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
<test>
<param name="ref_parameter" value="2.tabular" />
<param name="parameter" value="1,2,3" />
<expand macro="assert_output">
<has_line line="parameter: 1,2,3"/>
</expand>
</test>
<!-- these parameters are not implicitly optional! -->
<test expect_failure="true">
<param name="ref_parameter" value="2.tabular" />
<expand macro="assert_output">
<has_line line="parameter: 1"/>
</expand>
</test>
</tests>
</tool>
12 changes: 12 additions & 0 deletions test/unit/tool_util/parameter_specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,18 @@ gx_data_column:
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }

gx_data_column_multiple:
request_valid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: [0] }
request_invalid:
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: "0" }
- { ref_parameter: {src: hda, id: abcdabcd}, parameter: ["0"] }
request_internal_valid:
- { ref_parameter: {src: hda, id: 123}, parameter: [0] }
request_internal_invalid:
- { ref_parameter: {src: hda, id: 123}, parameter: "0" }
- { ref_parameter: {src: hda, id: 123}, parameter: 0 }

gx_group_tag:
request_valid:
- { ref_parameter: { src: hdca, id: abcdabcd}, parameter: 'type:matched' }
Expand Down

0 comments on commit 67dc43f

Please sign in to comment.