Add the option for a second DataToolParameter to be restricted to datasets with the same build as a previous input.

i.e. if input1 has a dbkey of hg18, input2 will be restricted to showing only those files which also have a dbkey of hg18 (and are of the proper type).  An example to follow.
This commit is contained in:
Daniel Blankenberg
2008-02-18 21:19:06 +00:00
parent 9aadc3afb7
commit fde22e3c6a
2 changed files with 22 additions and 1 deletions
+5 -1
View File
@@ -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' ] )
+17
View File
@@ -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 ] )