From bf75275a6140d7aaa37fc614179c0967416ba74f Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 21 Nov 2013 19:17:13 -0600 Subject: [PATCH] Tree-like input specification in tool XML file. Allow nestable and statements in test tool definitions. For instance, imagine a tool with a repeat statement like: 3 test instances overidding int_param default in all three, but leaving the float_param default in place for the first and last can specified as follows: Likewise, can be used analogously though this is for grouping and disambiguation - does not allow multiple instances to specified obviously. --- lib/galaxy/tools/test.py | 47 +++++++++++++++++++ .../functional/tools/disambiguate_repeats.xml | 17 +++++++ 2 files changed, 64 insertions(+) diff --git a/lib/galaxy/tools/test.py b/lib/galaxy/tools/test.py index 44e829bf3f1..99fa94f648d 100644 --- a/lib/galaxy/tools/test.py +++ b/lib/galaxy/tools/test.py @@ -127,6 +127,7 @@ class ToolTestBuilder( object ): # features or workarounds. self.interactor = test_elem.get( 'interactor', default_interactor ) + self.__preprocess_input_elems( test_elem ) self.__parse_inputs_elems( test_elem, i ) self.__parse_output_elems( test_elem ) @@ -134,6 +135,9 @@ class ToolTestBuilder( object ): self.error = True self.exception = e + def __preprocess_input_elems( self, test_elem ): + expand_input_elems( test_elem ) + def __parse_inputs_elems( self, test_elem, i ): # Composite datasets need a unique name: each test occurs in a fresh # history, but we'll keep it unique per set of tests - use i (test #) @@ -385,3 +389,46 @@ class RootParamContext(object): def get_index( self ): return 0 + + +def expand_input_elems( root_elem, prefix="" ): + __append_prefix_to_params( root_elem, prefix ) + + repeat_elems = root_elem.findall( 'repeat' ) + indices = {} + for repeat_elem in repeat_elems: + name = repeat_elem.get( "name" ) + if name not in indices: + indices[ name ] = 0 + index = 0 + else: + index = indices[ name ] + 1 + indices[ name ] = index + + new_prefix = __prefix_join( prefix, name, index=index ) + expand_input_elems( repeat_elem, new_prefix ) + __pull_up_params( root_elem, repeat_elem ) + root_elem.remove( repeat_elem ) + + cond_elems = root_elem.findall( 'conditional' ) + for cond_elem in cond_elems: + new_prefix = __prefix_join( prefix, cond_elem.get( "name" ) ) + expand_input_elems( cond_elem, new_prefix ) + __pull_up_params( root_elem, cond_elem ) + root_elem.remove( cond_elem ) + + +def __append_prefix_to_params( elem, prefix ): + for param_elem in elem.findall( 'param' ): + param_elem.set( "name", __prefix_join( prefix, param_elem.get( "name" ) ) ) + + +def __pull_up_params( parent_elem, child_elem ): + for param_elem in child_elem.findall( 'param' ): + parent_elem.append( param_elem ) + child_elem.remove( param_elem ) + + +def __prefix_join( prefix, name, index=None ): + name = name if index is None else "%s_%d" % ( name, index ) + return name if not prefix else "%s|%s" % ( prefix, name ) diff --git a/test/functional/tools/disambiguate_repeats.xml b/test/functional/tools/disambiguate_repeats.xml index b6ff72584eb..a97f7510c86 100644 --- a/test/functional/tools/disambiguate_repeats.xml +++ b/test/functional/tools/disambiguate_repeats.xml @@ -24,5 +24,22 @@ + + + + + + + + + + + + + + + + +