2 new commits in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/64e429d43a0e/ Changeset: 64e429d43a0e User: jmchilton Date: 2014-07-25 17:28:50 Summary: 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). Affected #: 4 files diff -r a2e4a980cdde2494e14f6eb17a3a518321ca65d1 -r 64e429d43a0e81ca684e51c51a7f07e38962e0da lib/galaxy/tools/actions/__init__.py --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -114,6 +114,8 @@ #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() diff -r a2e4a980cdde2494e14f6eb17a3a518321ca65d1 -r 64e429d43a0e81ca684e51c51a7f07e38962e0da lib/galaxy/tools/wrappers.py --- a/lib/galaxy/tools/wrappers.py +++ b/lib/galaxy/tools/wrappers.py @@ -269,6 +269,12 @@ 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 @@ 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 ) diff -r a2e4a980cdde2494e14f6eb17a3a518321ca65d1 -r 64e429d43a0e81ca684e51c51a7f07e38962e0da test/functional/tools/collection_optional_param.xml --- /dev/null +++ b/test/functional/tools/collection_optional_param.xml @@ -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> diff -r a2e4a980cdde2494e14f6eb17a3a518321ca65d1 -r 64e429d43a0e81ca684e51c51a7f07e38962e0da test/functional/tools/samples_tool_conf.xml --- a/test/functional/tools/samples_tool_conf.xml +++ b/test/functional/tools/samples_tool_conf.xml @@ -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> \ No newline at end of file https://bitbucket.org/galaxy/galaxy-central/commits/92546e4b743f/ Changeset: 92546e4b743f User: jmchilton Date: 2014-07-25 17:28:50 Summary: Improved object attribute naming DatasetCollectionWrapper. To try to limit potential ambibuity introduced by (probably mistakenly) allowing syntax such $param.<element_identifier> (e.g. $pair.forward). Affected #: 1 file diff -r 64e429d43a0e81ca684e51c51a7f07e38962e0da -r 92546e4b743fd876067a6bf68daffde9c6eca231 lib/galaxy/tools/wrappers.py --- a/lib/galaxy/tools/wrappers.py +++ b/lib/galaxy/tools/wrappers.py @@ -300,13 +300,13 @@ element_instances[element_identifier] = element_wrapper element_instance_list.append( element_wrapper ) - self.element_instances = element_instances - self.element_instance_list = element_instance_list + self.__element_instances = element_instances + self.__element_instance_list = element_instance_list def keys( self ): if not self.__input_supplied: return [] - return self.element_instances.keys() + return self.__element_instances.keys() @property def is_collection( self ): @@ -320,21 +320,21 @@ if not self.__input_supplied: return None if isinstance( key, int ): - return self.element_instance_list[ key ] + return self.__element_instance_list[ key ] else: - return self.element_instances[ key ] + return self.__element_instances[ key ] def __getattr__( self, key ): if not self.__input_supplied: return None - return self.element_instances[ key ] + return self.__element_instances[ key ] def __iter__( self ): if not self.__input_supplied: return [].__iter__() - return self.element_instance_list.__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 ) + return self.__input_supplied and bool( self.__element_instance_list ) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.