Skip to content
This repository was archived by the owner on Jun 9, 2020. It is now read-only.

Commit 0b9f2d4

Browse files
committed
Adds support for InputParameter connections when building workflows
1 parent 5fd96b5 commit 0b9f2d4

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

cwlgen/workflow.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def __init__(self, param_id, outputSource, label=None, secondary_files=None, par
185185
self.outputSource = outputSource
186186

187187
############################
188-
# Workflow contruction classes
188+
# Workflow construction classes
189189

190190

191191
class File:
@@ -196,6 +196,8 @@ def __init__(self, path):
196196
self.path = path
197197

198198

199+
200+
199201
class Variable:
200202
"""
201203
An output variable from a workflow step
@@ -216,6 +218,8 @@ def store(self):
216218
return
217219

218220

221+
222+
219223
class StepRun:
220224
"""
221225
Result of adding a step into a workflow
@@ -233,10 +237,13 @@ def __init__(self, workflow, id, tool, params):
233237
step.inputs.append(WorkflowStepInput(i, default=j))
234238
elif isinstance(j, Variable):
235239
step.inputs.append(WorkflowStepInput(i, src=j.path()))
240+
elif isinstance(j, InputParameter):
241+
self.workflow.inputs.append(j),
242+
step.inputs.append(WorkflowStepInput(j.id, src=j.id))
236243
elif isinstance(j, File):
244+
# This is just used as a stub, the 'path' inside the file doesn't do anything
237245
self.workflow.inputs.append(InputParameter(i, param_type="File"))
238246
step.inputs.append(WorkflowStepInput(i, src=i))
239-
240247
for o in tool.outputs:
241248
step.outputs.append(o.id)
242249

test/test_unit_workflow.py

+61-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@
1010
import os
1111
import filecmp
1212
import unittest
13+
from tempfile import NamedTemporaryFile
1314

1415
# External libraries
1516
import cwlgen
1617

1718
# Class(es) ------------------------------
1819

19-
class TestCommandLineTool(unittest.TestCase):
2020

21+
class TestWorkflow(unittest.TestCase):
2122

22-
def test_build(self):
23+
def capture_tempfile(self, func):
24+
with NamedTemporaryFile() as f:
25+
func(f.name)
26+
return f.read()
27+
28+
def test_generates_workflow_two_steps(self):
2329

2430
w = cwlgen.Workflow()
2531
tool = cwlgen.parse_cwl("test/import_cwl.cwl")
@@ -29,4 +35,56 @@ def test_build(self):
2935
o1 = w.add('step-a', tool, {"INPUT1" : f})
3036
o2 = w.add('step-b', tool, {"INPUT1" : o1['OUTPUT1']})
3137
o2['OUTPUT1'].store()
32-
w.export("test.cwl")
38+
generated = self.capture_tempfile(w.export)
39+
expected = b"""#!/usr/bin/env cwl-runner
40+
41+
class: Workflow
42+
cwlVersion: v1.0
43+
inputs:
44+
INPUT1: {id: INPUT1, type: File}
45+
outputs:
46+
step-b_OUTPUT1: {id: step-b_OUTPUT1, outputSource: step-b/OUTPUT1, type: File}
47+
steps:
48+
step-a:
49+
id: step-a
50+
in: {INPUT1: INPUT1}
51+
out: [OUTPUT1]
52+
run: test/import_cwl.cwl
53+
step-b:
54+
id: step-b
55+
in: {INPUT1: step-a/OUTPUT1}
56+
out: [OUTPUT1]
57+
run: test/import_cwl.cwl
58+
"""
59+
self.assertEqual(expected, generated)
60+
61+
def test_generates_workflow_int_inputs(self):
62+
63+
w = cwlgen.Workflow()
64+
tool = cwlgen.parse_cwl("test/int_tool.cwl")
65+
66+
i = cwlgen.workflow.InputParameter('INTEGER', param_type='int')
67+
o1 = w.add('step', tool, {"INTEGER": i})
68+
o1['OUTPUT1'].store()
69+
70+
expected = b"""#!/usr/bin/env cwl-runner
71+
72+
class: Workflow
73+
cwlVersion: v1.0
74+
inputs:
75+
INTEGER: {id: INTEGER, type: int}
76+
outputs:
77+
step_OUTPUT1: {id: step_OUTPUT1, outputSource: step/OUTPUT1, type: File}
78+
steps:
79+
step:
80+
id: step
81+
in: {INTEGER: INTEGER}
82+
out: [OUTPUT1]
83+
run: test/int_tool.cwl
84+
"""
85+
generated = self.capture_tempfile(w.export)
86+
self.assertEqual(expected, generated)
87+
88+
89+
90+

0 commit comments

Comments
 (0)