mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
make param_value filter work with multi data inputs
ie data with multiple=true and collections
This commit is contained in:
@@ -272,19 +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)
|
||||
if ref is None:
|
||||
ref = []
|
||||
elif isinstance(ref, list):
|
||||
ref = [str(_) for _ in ref]
|
||||
else:
|
||||
ref = [str(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] in ref):
|
||||
if self.keep == (fields[self.column] in ref_values):
|
||||
rval.append(fields)
|
||||
return rval
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
<options from_data_table="test_fasta_indexes">
|
||||
<column name="value" index="0"/>
|
||||
<column name="name" index="1"/>
|
||||
<!-- <filter type="param_value" column="0" ref="select2" keep="false"/> -->
|
||||
<!-- 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">
|
||||
<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"/>
|
||||
|
||||
@@ -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>
|
||||
@@ -48,6 +48,7 @@
|
||||
<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