Add a SelectToolParameterWrapper object and a wrap method to Tool.execute() that allows for things like the following in tool configs:

<outputs>
  <data format="input" name="output" label="Blat on {<input_param>.value_label}" />
</outputs>

Also replace EOL chars with <br> in a tool's output data.info so that they are displayed in HTML.
This commit is contained in:
Greg Von Kuster
2009-01-14 17:20:22 -05:00
parent 6976c383ad
commit 87a77c62f2
3 changed files with 48 additions and 5 deletions
+2 -1
View File
@@ -132,7 +132,8 @@ class Data( object ):
def display_info(self, dataset):
"""Returns formated html of dataset info"""
try:
return escape(dataset.info)
# Change new line chars to html
return escape( dataset.info ).replace( "\r", "\n" ).replace( "\n", "<br>" )
except:
return "info unavailable"
def validate(self, dataset):
+19 -4
View File
@@ -1072,10 +1072,11 @@ class Tool:
datatypes_registry = self.app.datatypes_registry,
tool = self,
name = input.name )
elif isinstance( input, SelectToolParameter ):
input_values[ input.name ] = SelectToolParameterWrapper( input, input_values[ input.name ], self.app )
else:
input_values[ input.name ] = \
InputValueWrapper( input, input_values[ input.name ], param_dict )
# HACK: only wrap if check_values is false, this deals with external
input_values[ input.name ] = InputValueWrapper( input, input_values[ input.name ], param_dict )
# HACK: only wrap if check_values is not false, this deals with external
# tools where the inputs don't even get passed through. These
# tools (e.g. UCSC) should really be handled in a special way.
if self.check_values:
@@ -1416,7 +1417,21 @@ class InputValueWrapper( object ):
return self.input.to_param_dict_string( self.value, self._other_values )
def __getattr__( self, key ):
return getattr( self.value, key )
class SelectToolParameterWrapper( object ):
"""
Wraps a SelectTooParameter so that __str__ returns the selected value, but all other
attributes are accessible.
"""
def __init__( self, input, value, app ):
self.input = input
self.value = value
self.input.value_label = input.value_to_display_text( value, app )
def __str__( self ):
return self.input.to_param_dict_string( self.value )
def __getattr__( self, key ):
return getattr( self.input, key )
class DatasetFilenameWrapper( object ):
"""
Wraps a dataset so that __str__ returns the filename, but all other
+27
View File
@@ -1,9 +1,11 @@
from galaxy.util.bunch import Bunch
from galaxy.tools.parameters import *
from galaxy.tools.parameters.grouping import *
from galaxy.util.template import fill_template
from galaxy.util.none_like import NoneDataset
from galaxy.web import url_for
from galaxy.jobs import JOB_OK
import galaxy.tools
import logging
log = logging.getLogger( __name__ )
@@ -65,6 +67,26 @@ class DefaultToolAction( object ):
return input_datasets
def execute(self, tool, trans, incoming={}, set_output_hid=True ):
def wrap_values( inputs, input_values ):
# Wrap tool inputs as necessary
for input in inputs.itervalues():
if isinstance( input, Repeat ):
for d in input_values[ input.name ]:
wrap_values( input.inputs, d )
elif isinstance( input, Conditional ):
values = input_values[ input.name ]
current = values["__current_case__"]
wrap_values( input.cases[current].inputs, values )
elif isinstance( input, DataToolParameter ):
input_values[ input.name ] = \
galaxy.tools.DatasetFilenameWrapper( input_values[ input.name ],
datatypes_registry = trans.app.datatypes_registry,
tool = tool,
name = input.name )
elif isinstance( input, SelectToolParameter ):
input_values[ input.name ] = galaxy.tools.SelectToolParameterWrapper( input, input_values[ input.name ], tool.app )
else:
input_values[ input.name ] = galaxy.tools.InputValueWrapper( input, input_values[ input.name ], incoming )
out_data = {}
# Collect any input datasets from the incoming parameters
inp_data = self.collect_input_datasets( tool, incoming, trans )
@@ -151,6 +173,11 @@ class DefaultToolAction( object ):
# Set output label
if output.label:
params = dict( incoming )
# wrapping the params allows the tool config to contain things like
# <outputs>
# <data format="input" name="output" label="Blat on ${<input_param>.name}" />
# </outputs>
wrap_values( tool.inputs, params )
params['tool'] = tool
params['on_string'] = on_text
data.name = fill_template( output.label, context=params )