mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Implement optional collection params.
Was already parsing optional attribute but I put exactly zero thought into the implementation so these didn't work at all I don't think. This fills out the implementation, adds a test tool, and some cheetah helpers to facilitate this: "#if $collect_param" will fail if input not supplied or collection is empty and "#if $collect_param.is_input_supplied" will fail is input not supplied (i.e. empty collections will pass this check).
This commit is contained in:
@@ -114,6 +114,8 @@ class DefaultToolAction( object ):
|
||||
#allow explicit conversion to be stored in job_parameter table
|
||||
target_dict[ conversion_name ] = conversion_data.id # a more robust way to determine JSONable value is desired
|
||||
elif isinstance( input, DataCollectionToolParameter ):
|
||||
if not value:
|
||||
return
|
||||
for i, v in enumerate( value.collection.dataset_instances ):
|
||||
data = v
|
||||
current_user_roles = trans.get_current_user_roles()
|
||||
|
||||
@@ -269,6 +269,12 @@ class DatasetCollectionWrapper( object, HasDatasets ):
|
||||
def __init__( self, has_collection, dataset_paths=[], **kwargs ):
|
||||
super(DatasetCollectionWrapper, self).__init__()
|
||||
|
||||
if has_collection is None:
|
||||
self.__input_supplied = False
|
||||
return
|
||||
else:
|
||||
self.__input_supplied = True
|
||||
|
||||
if hasattr( has_collection, "name" ):
|
||||
# It is a HistoryDatasetCollectionAssociation
|
||||
collection = has_collection.collection
|
||||
@@ -298,20 +304,37 @@ class DatasetCollectionWrapper( object, HasDatasets ):
|
||||
self.element_instance_list = element_instance_list
|
||||
|
||||
def keys( self ):
|
||||
if not self.__input_supplied:
|
||||
return []
|
||||
return self.element_instances.keys()
|
||||
|
||||
@property
|
||||
def is_collection( self ):
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_input_supplied( self ):
|
||||
return self.__input_supplied
|
||||
|
||||
def __getitem__( self, key ):
|
||||
if not self.__input_supplied:
|
||||
return None
|
||||
if isinstance( key, int ):
|
||||
return self.element_instance_list[ key ]
|
||||
else:
|
||||
return self.element_instances[ key ]
|
||||
|
||||
def __getattr__( self, key ):
|
||||
if not self.__input_supplied:
|
||||
return None
|
||||
return self.element_instances[ key ]
|
||||
|
||||
def __iter__( self ):
|
||||
if not self.__input_supplied:
|
||||
return [].__iter__()
|
||||
return self.element_instance_list.__iter__()
|
||||
|
||||
def __nonzero__( self ):
|
||||
# Fail `#if $param` checks in cheetah is optional input
|
||||
# not specified or if resulting collection is empty.
|
||||
return self.__input_supplied and bool( self.element_instance_list )
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<tool id="collection_optional_param" name="collection_optional_param" version="0.1.0">
|
||||
<command>
|
||||
#if $f1
|
||||
cat $f1.forward $f1['reverse'] >> $out1;
|
||||
#else
|
||||
echo "No input specified." >> $out1;
|
||||
#end if
|
||||
</command>
|
||||
<inputs>
|
||||
<param name="f1" type="data_collection" collection_type="paired" optional="true" />
|
||||
</inputs>
|
||||
<outputs>
|
||||
<data format="txt" name="out1" />
|
||||
</outputs>
|
||||
<tests>
|
||||
<test>
|
||||
<param name="f1">
|
||||
<collection type="paired">
|
||||
<element name="forward" value="simple_line.txt" />
|
||||
<element name="reverse" value="simple_line_alternative.txt" />
|
||||
</collection>
|
||||
</param>
|
||||
<output name="out1">
|
||||
<assert_contents>
|
||||
<has_line line="This is a line of text." />
|
||||
<has_line line="This is a different line of text." />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<output name="out1">
|
||||
<assert_contents>
|
||||
<has_line line="No input specified." />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
</tests>
|
||||
</tool>
|
||||
@@ -22,4 +22,5 @@
|
||||
<tool file="collection_nested_test.xml" />
|
||||
<tool file="collection_mixed_param.xml" />
|
||||
<tool file="collection_two_paired.xml" />
|
||||
<tool file="collection_optional_param.xml" />
|
||||
</toolbox>
|
||||
Reference in New Issue
Block a user