Skip to content

Commit d1ad64e

Browse files
committed
[WIP] implement basic CWL scatter semantics...
- count-lines3 scatter just works because it matches Galaxy's semantics without needing additional annotation it seems.
1 parent e6be28a commit d1ad64e

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

lib/galaxy/tools/cwl/parser.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"EnvVarRequirement",
4141
"InlineJavascriptRequirement",
4242
"ShellCommandRequirement",
43+
"ScatterFeatureRequirement",
4344
]
4445

4546

@@ -527,16 +528,25 @@ def jsonld_id_to_label(self, id):
527528
return id.rsplit("#", 1)[-1]
528529

529530
def cwl_input_to_galaxy_step(self, input, i):
530-
assert input["type"] == "File"
531-
return {
531+
input_type = input["type"]
532+
input_as_dict = {
532533
"id": i,
533534
"label": self.jsonld_id_to_label(input["id"]),
534535
"position": {"left": 0, "top": 0},
535-
"type": "data_input", # TODO: dispatch on type obviously...
536536
"annotation": self.cwl_object_to_annotation(input),
537537
"input_connections": {}, # Should the Galaxy API really require this? - Seems to.
538538
}
539539

540+
if input_type == "File":
541+
input_as_dict["type"] = "data_input"
542+
elif isinstance(input_type, dict) and input_type.get("type") == "array" and input_type.get("items") == "File":
543+
input_as_dict["type"] = "data_collection_input"
544+
input_as_dict["collection_type"] = "list"
545+
else:
546+
raise NotImplementedError()
547+
548+
return input_as_dict
549+
540550
def cwl_object_to_annotation(self, cwl_obj):
541551
return cwl_obj.get("doc", None)
542552

test/api/test_workflows_cwl.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,36 @@ def test_count_line2_v1(self):
5757
"""Test simple workflow v1.0/count-lines2-wf.cwl."""
5858
self._run_count_lines_wf("v1.0/count-lines2-wf.cwl")
5959

60+
def test_count_lines3_v1(self):
61+
load_response = self._load_workflow("v1.0/count-lines3-wf.cwl")
62+
self._assert_status_code_is(load_response, 200)
63+
workflow = load_response.json()
64+
workflow_id = workflow["id"]
65+
history_id = self.dataset_populator.new_history()
66+
hdca = self.dataset_collection_populator.create_list_in_history( history_id ).json()
67+
inputs_map = {
68+
"file1": {"src": "hdca", "id": hdca["id"]}
69+
}
70+
workflow_request = dict(
71+
history="hist_id=%s" % history_id,
72+
workflow_id=workflow_id,
73+
inputs=json.dumps(inputs_map),
74+
inputs_by="name",
75+
)
76+
url = "workflows/%s/invocations" % workflow_id
77+
invocation_response = self._post(url, data=workflow_request)
78+
self._assert_status_code_is(invocation_response, 200)
79+
invocation_id = invocation_response.json()["id"]
80+
self.wait_for_invocation_and_jobs(history_id, workflow_id, invocation_id)
81+
hdca = self.dataset_populator.get_history_collection_details(history_id, hid=8)
82+
assert hdca["collection_type"] == "list"
83+
elements = hdca["elements"]
84+
assert len(elements) == 3
85+
element0 = elements[0]["object"]
86+
assert element0["history_content_type"] == "dataset"
87+
assert element0["state"] == "ok"
88+
assert element0["file_ext"] == "expression.json"
89+
6090
def _run_count_lines_wf(self, wf_path):
6191
load_response = self._load_workflow(wf_path)
6292
self._assert_status_code_is(load_response, 200)

test/unit/tools/test_cwl.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ def test_workflow_embedded_tools_proxy():
117117
assert exp_step["input_connections"]
118118

119119

120+
def test_workflow_scatter():
121+
version = "v1.0"
122+
proxy = workflow_proxy(_cwl_tool_path("%s/count-lines3-wf.cwl" % version))
123+
124+
step_proxies = proxy.step_proxies()
125+
assert len(step_proxies) == 1
126+
127+
galaxy_workflow_dict = proxy.to_dict()
128+
assert len(galaxy_workflow_dict["steps"]) == 2
129+
130+
wc_step = galaxy_workflow_dict["steps"][1]
131+
assert wc_step["input_connections"]
132+
133+
120134
def test_load_proxy_simple():
121135
cat3 = _cwl_tool_path("draft3/cat3-tool.cwl")
122136
tool_source = get_tool_source(cat3)

0 commit comments

Comments
 (0)