mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 10:24:38 +08:00
Add parameter expansion caller and test cases as preparation for workflow api extension
This commit is contained in:
@@ -2,11 +2,68 @@ from galaxy.util import permutations
|
||||
from galaxy import model
|
||||
from galaxy import util
|
||||
from galaxy import exceptions
|
||||
|
||||
import itertools
|
||||
import copy
|
||||
import logging
|
||||
log = logging.getLogger( __name__ )
|
||||
|
||||
|
||||
def expand_workflow_inputs( inputs ):
|
||||
"""
|
||||
Expands incoming encoded multiple payloads, into the set of all individual payload combinations
|
||||
>>> params, param_keys = expand_workflow_inputs( {'1': {'input': {'batch': True, 'product': True, 'values': [{'hid': '1'}, {'hid': '2'}] }}} )
|
||||
>>> print sorted( [ "%s" % ( p[ '1' ][ 'input' ][ 'hid' ] ) for p in params ] )
|
||||
['1', '2']
|
||||
>>> params, param_keys = expand_workflow_inputs( {'1': {'input': {'batch': True, 'values': [{'hid': '1'}, {'hid': '2'}] }}} )
|
||||
>>> print sorted( [ "%s" % ( p[ '1' ][ 'input' ][ 'hid' ] ) for p in params ] )
|
||||
['1', '2']
|
||||
>>> params, param_keys = expand_workflow_inputs( {'1': {'input': {'batch': True, 'values': [{'hid': '1'}, {'hid': '2'}] }}, '2': {'input': {'batch': True, 'values': [{'hid': '3'}, {'hid': '4'}] }}} )
|
||||
>>> print sorted( [ "%s%s" % ( p[ '1' ][ 'input' ][ 'hid' ], p[ '2' ][ 'input' ][ 'hid' ] ) for p in params ] )
|
||||
['13', '24']
|
||||
>>> params, param_keys = expand_workflow_inputs( {'1': {'input': {'batch': True, 'product': True, 'values': [{'hid': '1'}, {'hid': '2'}] }}, '2': {'input': {'batch': True, 'values': [{'hid': '3'}, {'hid': '4'}, {'hid': '5'}] }}} )
|
||||
>>> print sorted( [ "%s%s" % ( p[ '1' ][ 'input' ][ 'hid' ], p[ '2' ][ 'input' ][ 'hid' ] ) for p in params ] )
|
||||
['13', '14', '15', '23', '24', '25']
|
||||
>>> params, param_keys = expand_workflow_inputs( {'1': {'input': {'batch': True, 'product': True, 'values': [{'hid': '1'}, {'hid': '2'}] }}, '2': {'input': {'batch': True, 'product': True, 'values': [{'hid': '3'}, {'hid': '4'}, {'hid': '5'}] }}, '3': {'input': {'batch': True, 'product': True, 'values': [{'hid': '6'}, {'hid': '7'}, {'hid': '8'}] }}} )
|
||||
>>> print sorted( [ "%s%s%s" % ( p[ '1' ][ 'input' ][ 'hid' ], p[ '2' ][ 'input' ][ 'hid' ], p[ '3' ][ 'input' ][ 'hid' ] ) for p in params ] )
|
||||
['136', '137', '138', '146', '147', '148', '156', '157', '158', '236', '237', '238', '246', '247', '248', '256', '257', '258']
|
||||
"""
|
||||
linked_n = None
|
||||
linked = []
|
||||
product = []
|
||||
linked_keys = []
|
||||
product_keys = []
|
||||
for step_id, step in inputs.items():
|
||||
for key, value in step.items():
|
||||
if isinstance( value, dict ) and 'batch' in value and value[ 'batch' ] is True and 'values' in value and isinstance( value[ 'values' ], list ):
|
||||
nval = len( value[ 'values' ] )
|
||||
if 'product' in value and value[ 'product' ] is True:
|
||||
product.append( value[ 'values' ] )
|
||||
product_keys.append( ( step_id, key ) )
|
||||
else:
|
||||
if linked_n is None:
|
||||
linked_n = nval
|
||||
elif linked_n != nval or nval is 0:
|
||||
raise exceptions.RequestParameterInvalidException( 'Failed to match linked batch selections. Please select equal number of data files.' )
|
||||
linked.append( value[ 'values' ] )
|
||||
linked_keys.append( ( step_id, key ) )
|
||||
params = []
|
||||
params_keys = []
|
||||
linked = linked or [ [ None ] ]
|
||||
product = product or [ [ None ] ]
|
||||
linked_keys = linked_keys or [ ( None, None ) ]
|
||||
product_keys = product_keys or [ ( None, None ) ]
|
||||
for linked_values, product_values in itertools.product( *[ zip( *linked ), itertools.product( *product ) ] ):
|
||||
new_params = copy.deepcopy( inputs )
|
||||
new_keys = []
|
||||
for ( step_id, key ), value in zip( linked_keys, linked_values ) + zip( product_keys, product_values ):
|
||||
if step_id is not None:
|
||||
new_params[ step_id ][ key ] = value
|
||||
new_keys.append( value[ 'hid' ] )
|
||||
params_keys.append( new_keys )
|
||||
params.append( new_params )
|
||||
return params, params_keys
|
||||
|
||||
|
||||
def expand_meta_parameters( trans, tool, incoming ):
|
||||
"""
|
||||
Take in a dictionary of raw incoming parameters and expand to a list
|
||||
|
||||
Reference in New Issue
Block a user