mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #13039 from bernt-matthias/topic/filter-param-value-multiple
Allow param_value filter to refer to parameters with multiple values
This commit is contained in:
@@ -157,6 +157,7 @@ class DataMetaFilter(Filter):
|
||||
self.column = d_option.column_spec_to_index(self.column)
|
||||
self.multiple = string_as_bool(elem.get("multiple", "False"))
|
||||
self.separator = elem.get("separator", ",")
|
||||
log.error(f"data_meta.init: ref_name {self.ref_name} key {self.key} column {self.column} multiple {self.multiple} separator {self.separator}")
|
||||
|
||||
def get_dependency_name(self):
|
||||
return self.ref_name
|
||||
@@ -271,14 +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)
|
||||
ref = str(ref)
|
||||
if ref is None:
|
||||
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] == ref):
|
||||
if self.keep == (fields[self.column] in ref_values):
|
||||
rval.append(fields)
|
||||
return rval
|
||||
|
||||
@@ -666,10 +684,10 @@ class DynamicOptions:
|
||||
try:
|
||||
datasets = _get_ref_data(other_values, self.dataset_ref_name)
|
||||
except KeyError: # no such dataset
|
||||
log.warning(f"could not create dynamic options from_dataset: {self.dataset_ref_name} unknown")
|
||||
log.warning(f"Parameter {self.tool_param.name}: could not create dynamic options from_dataset: {self.dataset_ref_name} unknown")
|
||||
return []
|
||||
except ValueError: # not a valid dataset
|
||||
log.warning(f"could not create dynamic options from_dataset: {self.dataset_ref_name} not a data or collection parameter")
|
||||
log.warning(f"Parameter {self.tool_param.name}: could not create dynamic options from_dataset: {self.dataset_ref_name} not a data or collection parameter")
|
||||
return []
|
||||
|
||||
options = []
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
hg19_value hg19 hg19_name hg19_path
|
||||
hg18_value hg18 hg18_name hg18_path
|
||||
mm10_value mm10 mm10_name mm10_path
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<tool id="filter_param_value" name="filter_param_value" version="0.1.0">
|
||||
<description>Filter input with the param_value</description>
|
||||
<command><![CDATA[
|
||||
echo $select1 > '$output' &&
|
||||
echo $select2 >> '$output'
|
||||
]]></command>
|
||||
<inputs>
|
||||
<!-- define 2 selects that are initialised with entries from a data table
|
||||
and use param_value filters to ensure that disjoint elements are
|
||||
selected (one of them is multiple="true" to ensure that also list of
|
||||
elements can be used in the filter) -->
|
||||
<param name="select1" type="select" multiple="true">
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<!-- unfortunatelly this does not work (bug?): at the moment ane can
|
||||
not refer to other inputs that are defined below)
|
||||
<filter type="param_value" column="0" ref="select2" keep="false"/> -->
|
||||
</options>
|
||||
</param>
|
||||
<param name="select2" type="select">
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<filter type="param_value" column="0" ref="select1" keep="false"/>
|
||||
</options>
|
||||
</param>
|
||||
</inputs>
|
||||
|
||||
<outputs>
|
||||
<data format="txt" name="output" />
|
||||
</outputs>
|
||||
|
||||
<tests>
|
||||
<test expect_failure="false">
|
||||
<param name="select1" value="hg18_value,hg19_value"/>
|
||||
<param name="select2" value="mm10_value" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_line line="hg18_value,hg19_value" />
|
||||
<has_line line="mm10_value" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="select1" value="hg18_value,hg19_value"/>
|
||||
<param name="select2" value="hg18_value" />
|
||||
</test>
|
||||
</tests>
|
||||
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
@@ -0,0 +1,116 @@
|
||||
<tool id="filter_param_value_ref_attribute" name="filter_param_value_ref_attribute" version="0.1.0">
|
||||
<description>Filter input with the param_value</description>
|
||||
<command><![CDATA[
|
||||
#if $select_single
|
||||
echo $select_single >> '$output' &&
|
||||
#end if
|
||||
#if $select_mult
|
||||
echo $select_mult >> '$output' &&
|
||||
#end if
|
||||
#if $select_coll
|
||||
echo $select_coll >> '$output' &&
|
||||
#end if
|
||||
true
|
||||
]]></command>
|
||||
<inputs>
|
||||
<!-- this tests the param_value filter with the ref_attribute attribute
|
||||
(so ref is dataset(s) or a dataset collection), the following pairs
|
||||
test param_value filter refering:
|
||||
- dataset
|
||||
- multiple datasets
|
||||
- a collection
|
||||
|
||||
in each case the data and the select input are optional to allow
|
||||
to test them separately -->
|
||||
|
||||
<!-- 1. dataset (here with non-default keep) -->
|
||||
<param name="data_single" type="data" format="bed" optional="true"/>
|
||||
<param name="select_single" type="select" multiple="true" optional="true">
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<filter type="param_value" column="1" ref="data_single" ref_attribute="metadata.dbkey" keep="false"/>
|
||||
</options>
|
||||
</param>
|
||||
|
||||
<!-- 2. same, but with a data input accepting multiple datasets
|
||||
(which may have different dbkeys .. but we can not specify them in a test) -->
|
||||
<param name="data_mult" format="bed" type="data" multiple="true" optional="true"/>
|
||||
<param name="select_mult" type="select" multiple="true" optional="true">
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<filter type="param_value" column="1" ref="data_mult" ref_attribute="metadata.dbkey"/>
|
||||
</options>
|
||||
</param>
|
||||
|
||||
<!-- 3. same, but with a collection input (elements may have different dbkeys) -->
|
||||
<param name="data_coll" format="bed" type="data_collection" collection_type="list" optional="true"/>
|
||||
<param name="select_coll" type="select" multiple="true" optional="true">
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<filter type="param_value" column="1" ref="data_coll" ref_attribute="metadata.dbkey"/>
|
||||
</options>
|
||||
</param>
|
||||
</inputs>
|
||||
|
||||
<outputs>
|
||||
<data format="txt" name="output" />
|
||||
</outputs>
|
||||
|
||||
<tests>
|
||||
<test expect_failure="false">
|
||||
<param name="data_single" value="1.bed" ftype="bed" dbkey="hg19"/>
|
||||
<param name="select_single" value="hg18_value,mm10_value"/>
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_line line="hg18_value,mm10_value"/>
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="data_single" value="1.bed" ftype="bed" dbkey="hg19"/>
|
||||
<param name="select_single" value="hg19_value"/>
|
||||
</test>
|
||||
<test expect_failure="false">
|
||||
<param name="data_mult" value="1.bed,2.bed" dbkey="hg19"/>
|
||||
<param name="select_mult" value="hg19_value"/>
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_line line="hg19_value"/>
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="data_mult" value="1.bed,2.bed" dbkey="hg19"/>
|
||||
<param name="select_mult" value="hg18_value"/>
|
||||
</test>
|
||||
<test expect_failure="false">
|
||||
<param name="data_coll">
|
||||
<collection type="list">
|
||||
<element name="element1" ftype="bed" value="1.bed" dbkey="hg18"/>
|
||||
<element name="element2" ftype="bed" value="2.bed" dbkey="hg19"/>
|
||||
</collection>
|
||||
</param>
|
||||
<param name="select_coll" value="hg18_value,hg19_value"/>
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_line line="hg18_value,hg19_value"/>
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_failure="true">
|
||||
<param name="data_coll">
|
||||
<collection type="list">
|
||||
<element name="element1" ftype="bed" value="1.bed" dbkey="hg18"/>
|
||||
<element name="element2" ftype="bed" value="2.bed" dbkey="hg19"/>
|
||||
</collection>
|
||||
</param>
|
||||
<param name="select_coll" value="mm10_value"/>
|
||||
</test>
|
||||
</tests>
|
||||
|
||||
<help>
|
||||
</help>
|
||||
</tool>
|
||||
@@ -47,6 +47,8 @@
|
||||
<tool file="inputs_as_json_with_paths.xml" />
|
||||
<tool file="inputs_as_json_with_staging_path_and_source_path.xml" />
|
||||
<tool file="filter_multiple_splitter.xml" />
|
||||
<tool file="filter_param_value.xml" />
|
||||
<tool file="filter_param_value_ref_attribute.xml" />
|
||||
<tool file="filter_static_regexp.xml" />
|
||||
<tool file="select_from_dataset.xml" />
|
||||
<tool file="select_from_dataset_optional.xml" />
|
||||
|
||||
Reference in New Issue
Block a user