Skip to content

Commit 5e7f622

Browse files
committed
Implement CWL valueFrom for multiple inputs and non-File inputs.
1 parent 2bf91f3 commit 5e7f622

File tree

4 files changed

+64
-20
lines changed

4 files changed

+64
-20
lines changed

lib/galaxy/tools/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,9 +2368,9 @@ def exec_before_job( self, app, inp_data, out_data, param_dict=None ):
23682368

23692369
command_line = " ".join([shellescape.quote(arg) if needs_shell_quoting(arg) else arg for arg in cwl_command_line])
23702370
if cwl_stdin:
2371-
command_line += '< "' + cwl_stdin + '"'
2371+
command_line += ' < "' + cwl_stdin + '"'
23722372
if cwl_stdout:
2373-
command_line += '> "' + cwl_stdout + '"'
2373+
command_line += ' > "' + cwl_stdout + '"'
23742374
cwl_job_state = {
23752375
'args': cwl_command_line,
23762376
'stdin': cwl_stdin,

lib/galaxy/tools/cwl/parser.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,30 @@ def __init__(self, step_proxy, cwl_input):
734734
self._cwl_input = cwl_input
735735
self.step_proxy = step_proxy
736736
cwl_input_id = cwl_input["id"]
737-
cwl_source_id = cwl_input["source"]
738-
step_name, input_name = split_step_references(
739-
cwl_input_id,
740-
multiple=False,
741-
workflow_id=step_proxy.cwl_workflow_id
742-
)
737+
cwl_source_id = cwl_input.get("source", None)
738+
if cwl_source_id is None:
739+
if "valueFrom" not in cwl_input:
740+
raise NotImplementedError("Workflow step input must define a source or a valueFrom value.")
741+
742+
if cwl_source_id is not None:
743+
step_name, input_name = split_step_references(
744+
cwl_input_id,
745+
multiple=False,
746+
workflow_id=step_proxy.cwl_workflow_id
747+
)
748+
self.step_name = step_name
749+
self.input_name = input_name
750+
else:
751+
self.step_name = None
752+
self.input_name = None
753+
743754
self.cwl_input_id = cwl_input_id
744755
self.cwl_source_id = cwl_source_id
745-
self.step_name = step_name
746-
self.input_name = input_name
756+
757+
scatter = False
758+
if self.input_name in listify(step_proxy._step.tool.get("scatter", [])):
759+
scatter = True
760+
self.scatter = scatter
747761

748762
def to_dict(self):
749763
as_dict = {
@@ -752,7 +766,9 @@ def to_dict(self):
752766
if "linkMerge" in self._cwl_input:
753767
as_dict["merge_type"] = self._cwl_input["linkMerge"]
754768
if "scatterMethod" in self.step_proxy._step.tool:
755-
as_dict["scatter_method"] = self.step_proxy._step.tool["scatterMethod"]
769+
as_dict["scatter_type"] = self.step_proxy._step.tool.get("scatterMethod", "dotproduct")
770+
else:
771+
as_dict["scatter_type"] = "dotproduct" if self.scatter else "disabled"
756772
if "valueFrom" in self._cwl_input:
757773
# TODO: Add a table for expressions - mark the type as CWL 1.0 JavaScript.
758774
as_dict["value_from"] = self._cwl_input["valueFrom"]

lib/galaxy/workflow/modules.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -879,10 +879,14 @@ def evaluate_value_from_expressions(self, step, execution_state):
879879
def to_cwl(value):
880880
if isinstance(value, model.HistoryDatasetAssociation):
881881
hda_references.append(value)
882-
return {
883-
"class": "File",
884-
"location": "step_input://%d" % len(hda_references),
885-
}
882+
if value.ext == "expression.json":
883+
with open( value.file_name, "r" ) as f:
884+
return loads(f.read())
885+
else:
886+
return {
887+
"class": "File",
888+
"location": "step_input://%d" % len(hda_references),
889+
}
886890
elif hasattr(value, "collection"):
887891
collection = value.collection
888892
if collection.collection_type == "list":
@@ -983,14 +987,20 @@ def callback( input, prefixed_name, **kwargs ):
983987
message = message_template % (tool.name, k.message)
984988
raise exceptions.MessageException( message )
985989

986-
self.evaluate_value_from_expressions(
987-
step, execution_state
988-
)
990+
extra_step_state = {}
991+
for step_input in step.inputs:
992+
if step_input.name not in execution_state.inputs:
993+
value = progress.replacment_for_step_input( step, step_input )
994+
extra_step_state[step_input.name] = value
989995

990996
unmatched_input_connections = expected_replacement_keys - found_replacement_keys
991997
if unmatched_input_connections:
992998
log.warn("Failed to use input connections for inputs [%s]" % unmatched_input_connections)
993999

1000+
self.evaluate_value_from_expressions(
1001+
step, execution_state
1002+
)
1003+
9941004
param_combinations.append( execution_state.inputs )
9951005

9961006
try:
@@ -1050,11 +1060,15 @@ def _find_collections_to_match( self, tool, progress, step ):
10501060
collections_to_match = matching.CollectionsToMatch()
10511061

10521062
def callback( input, prefixed_name, **kwargs ):
1053-
step_input = step.inputs_by_name[ prefixed_name ]
1063+
step_input = step.inputs_by_name.get( prefixed_name, None )
10541064
scatter_type = "dotproduct"
10551065
if step_input:
10561066
scatter_type = step_input.scatter_type
1057-
assert scatter_type == "dotproduct"
1067+
assert scatter_type in ["dotproduct", "disabled"]
1068+
1069+
log.info("SCATTER_TYPE IS %s" % scatter_type)
1070+
if scatter_type == "disabled":
1071+
return
10581072

10591073
is_data_param = isinstance( input, DataToolParameter )
10601074
if is_data_param and not input.multiple:

test/unit/tools/test_cwl.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ def test_workflow_step_value_from():
214214
assert "value_from" in inputs[0]
215215

216216

217+
def test_workflow_input_without_source():
218+
version = "v1.0"
219+
proxy = workflow_proxy(_cwl_tool_path("%s/step-valuefrom3-wf.cwl" % version))
220+
221+
galaxy_workflow_dict = proxy.to_dict()
222+
assert len(galaxy_workflow_dict["steps"]) == 3
223+
224+
tool_step = galaxy_workflow_dict["steps"][2]
225+
assert "inputs" in tool_step
226+
inputs = tool_step["inputs"]
227+
assert len(inputs) == 3
228+
assert inputs[2].get("value_from")
229+
230+
217231
def test_load_proxy_simple():
218232
cat3 = _cwl_tool_path("draft3/cat3-tool.cwl")
219233
tool_source = get_tool_source(cat3)

0 commit comments

Comments
 (0)