Skip to content

Commit

Permalink
Use hda representative agent if collections are parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Aug 1, 2016
1 parent 7b2d71e commit b34757b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3299,6 +3299,10 @@ def type_id( cls ):
return (( type_coerce( cls.content_type, types.Unicode ) + u'-' +
type_coerce( cls.id, types.Unicode ) ).label( 'type_id' ))

def to_hda_agent( self ):
if len( self.collection.dataset_elements ) > 0:
return self.collection.dataset_elements[ 0 ].dataset_instance

def to_dict( self, view='collection' ):
dict_value = dict(
hid=self.hid,
Expand Down
27 changes: 19 additions & 8 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,11 +1187,17 @@ def get_column_list( self, trans, other_values ):
"""
# Get the value of the associated data reference (a dataset)
dataset = other_values.get( self.data_ref, None )

# Check if a dataset is selected
if not dataset:
return []

column_list = None
for dataset in util.listify( dataset ):
# Use representative dataset if a dataset collection is parsed
if isinstance( dataset, trans.app.model.HistoryDatasetCollectionAssociation ):
dataset = dataset.to_hda_agent()

# Columns can only be identified if metadata is available
if not hasattr( dataset, 'metadata' ) or not hasattr( dataset.metadata, 'columns' ) or not dataset.metadata.columns:
return []
Expand Down Expand Up @@ -1659,17 +1665,23 @@ def _parse_options( self, input_source ):
self.is_dynamic = self.options is not None

def get_initial_value( self, trans, other_values ):
"""
NOTE: This is wasteful since to_dict is called twice when populating the tool model.
"""
if trans.workflow_building_mode is workflow_building_modes.ENABLED or trans.app.name == 'tool_shed':
return RuntimeValue()
if self.optional:
return None
d = self.to_dict( trans, other_values=other_values )
src = 'hda' if isinstance( self, DataToolParameter ) else 'hdca'
if 'options' in d and src in d[ 'options'] and len( d[ 'options' ][ src ] ) > 0:
return d[ 'options' ][ src ][ 0 ]
history = trans.history
if history is not None:
dataset_matcher = DatasetMatcher( trans, self, None, other_values )
if isinstance( self, DataToolParameter ):
for hda in reversed( history.active_datasets_children_and_roles ):
match = dataset_matcher.hda_match( hda )
if match:
return match.hda
else:
dataset_collection_matcher = DatasetCollectionMatcher( dataset_matcher )
for hdca in reversed( history.active_dataset_collections ):
if dataset_collection_matcher.hdca_match( hdca, reduction=self.multiple ):
return hdca

def to_json( self, value, app ):
def single_to_json( value ):
Expand All @@ -1684,7 +1696,6 @@ def single_to_json( value ):
src = 'hda'
if src is not None:
return { 'id' : app.security.encode_id( value.id ), 'src' : src }

if value not in [ None, '', 'None' ]:
if isinstance( value, list ) and len( value ) > 0:
values = [ single_to_json( v ) for v in value ]
Expand Down
5 changes: 4 additions & 1 deletion lib/galaxy/workflow/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,10 @@ def callback( input, prefixed_name, context, **kwargs ):
output_step = next( output_step for output_step in steps if connection.output_step_id == output_step.id )
if output_step.type.startswith( 'data' ):
output_inputs = output_step.module.get_runtime_inputs()
return output_inputs[ 'input' ].get_initial_value( self.trans, context )
output_value = output_inputs[ 'input' ].get_initial_value( self.trans, context )
if isinstance( input, DataToolParameter ) and isinstance( output_value, self.trans.app.model.HistoryDatasetCollectionAssociation ):
output_value = output_value.to_hda_agent()
return output_value
return RuntimeValue()
else:
return input.get_initial_value( self.trans, context )
Expand Down

0 comments on commit b34757b

Please sign in to comment.