diff --git a/lib/galaxy/tools/dynamic_options.py b/lib/galaxy/tools/dynamic_options.py index a0783e1bf03..f7c7822f937 100644 --- a/lib/galaxy/tools/dynamic_options.py +++ b/lib/galaxy/tools/dynamic_options.py @@ -1,11 +1,13 @@ import sys, os, logging +import parameters log = logging.getLogger(__name__) class DynamicOptions( object ): """Handles dynamically generated SelectToolParameter options""" - def __init__( self, elem ): + def __init__( self, elem, parameter_type = None ): + self.parameter_type = parameter_type self.from_file_data = None # FIXME: Pushing these things in as options ends up being pretty ugly. # We should find a way to make this work through the validation mechanism. @@ -185,6 +187,8 @@ class DynamicOptions( object ): return self.generate_from_dataset( file_name, value_col, sep ) elif key == 'build': build = filters[ 'data_meta' ][ 'value' ] + if self.parameter_type == parameters.DataToolParameter: + return key, build build_col = int( filters[ 'columns' ][ 'build_col' ].strip() ) name_col = int( filters[ 'columns' ][ 'name_col' ] ) value_col = int( filters[ 'columns' ][ 'value_col' ] ) diff --git a/lib/galaxy/tools/parameters.py b/lib/galaxy/tools/parameters.py index d217620b3b5..e1398ce2a26 100644 --- a/lib/galaxy/tools/parameters.py +++ b/lib/galaxy/tools/parameters.py @@ -740,8 +740,18 @@ class DataToolParameter( ToolParameter ): self.formats = tuple( formats ) self.multiple = str_bool( elem.get( 'multiple', False ) ) self.optional = str_bool( elem.get( 'optional', False ) ) + #TODO: Enhance dynamic options for DataToolParameters + #Currently, only the special case key='build' of type='data_meta' is a valid filter + options = elem.find( 'options' ) + if options is None: + self.options = None + else: + self.options = dynamic_options.DynamicOptions( options, parameter_type = type( self ) ) def get_html_field( self, trans=None, value=None, other_values={} ): + filter_key = filter_value = None + if self.options: + filter_key, filter_value = self.options.get_options( trans, other_values ) assert trans is not None, "DataToolParameter requires a trans" history = trans.history assert history is not None, "DataToolParameter requires a history" @@ -756,6 +766,8 @@ class DataToolParameter( ToolParameter ): else: hid = str( data.hid ) if isinstance( data.datatype, self.formats) and not data.deleted and data.state not in [data.states.ERROR]: + if self.options and filter_key == 'build' and data.get_dbkey() != filter_value: + continue selected = ( value and ( data in value ) ) field.add_option( "%s: %s" % ( hid, data.name[:30] ), data.id, selected ) # Also collect children via association object @@ -786,9 +798,14 @@ class DataToolParameter( ToolParameter ): assert history is not None, "DataToolParameter requires a history" history = trans.history most_recent_dataset = [None] + filter_key = filter_value = None + if self.options: + filter_key, filter_value = self.options.get_options( trans, context ) def dataset_collector( datasets ): for i, data in enumerate( datasets ): if isinstance( data.datatype, self.formats) and not data.deleted and data.state not in [data.states.ERROR]: + if self.options and filter_key == 'build' and data.get_dbkey() != filter_value: + continue most_recent_dataset[0] = data # Also collect children via association object dataset_collector( [ assoc.child for assoc in data.children ] )