Skip to content

Commit 508dce7

Browse files
committed
Implement cwl_script command.
1 parent 17b4b40 commit 508dce7

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "planemo/xml/xsd/tool"]
22
path = planemo/xml/xsd/tool
33
url = https://github.com/JeanFred/Galaxy-XSD
4+
[submodule "planemo_ext/cwl2script"]
5+
path = planemo_ext/cwl2script
6+
url = https://github.com/common-workflow-language/cwl2script.git

planemo/commands/cmd_cwl_script.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
"""
3+
from __future__ import print_function
4+
5+
import copy
6+
import os
7+
8+
import click
9+
10+
import schema_salad
11+
import cwltool
12+
from cwltool.main import load_tool
13+
from cwltool.process import (
14+
checkRequirements,
15+
shortname,
16+
)
17+
from cwl2script.cwl2script import (
18+
supportedProcessRequirements,
19+
generateScriptForWorkflow,
20+
generateScriptForTool,
21+
)
22+
23+
from planemo.cli import pass_context
24+
from planemo import options
25+
26+
27+
@click.command("cwl_script")
28+
@options.required_tool_arg()
29+
@options.required_job_arg()
30+
@click.option('--no_container', is_flag=True, default=False)
31+
@click.option('outdir', '--output_dir', type=click.Path())
32+
@click.option('basedir', '--base_dir', type=click.Path(), default=".")
33+
@pass_context
34+
def cli(ctx, path, job_path, **kwds):
35+
"""This compiles simple common workflow language workflows to a shell
36+
script.
37+
"""
38+
uri = "file://" + os.path.abspath(job_path)
39+
40+
loader = schema_salad.ref_resolver.Loader({
41+
"@base": uri,
42+
"path": {
43+
"@type": "@id"
44+
}
45+
})
46+
47+
job, _ = loader.resolve_ref(uri)
48+
49+
t = load_tool(path, False, False, cwltool.workflow.defaultMakeTool, True)
50+
51+
if type(t) == int:
52+
return t
53+
54+
checkRequirements(t.tool, supportedProcessRequirements)
55+
56+
for inp in t.tool["inputs"]:
57+
if shortname(inp["id"]) in job:
58+
pass
59+
elif shortname(inp["id"]) not in job and "default" in inp:
60+
job[shortname(inp["id"])] = copy.copy(inp["default"])
61+
elif shortname(inp["id"]) not in job and inp["type"][0] == "null":
62+
pass
63+
else:
64+
raise Exception("Missing inputs `%s`" % shortname(inp["id"]))
65+
66+
if not kwds.get("basedir", None):
67+
kwds["basedir"] = os.path.dirname(os.path.abspath(job_path))
68+
69+
outdir = kwds.get("outdir")
70+
71+
if t.tool["class"] == "Workflow":
72+
print(generateScriptForWorkflow(t, job, outdir))
73+
elif t.tool["class"] == "CommandLineTool":
74+
print(generateScriptForTool(t, job, outdir))
75+
76+
return 0

planemo/options.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ def enable_cwl_option():
9999
)
100100

101101

102+
def cwl_conformance_test():
103+
return click.option(
104+
"--conformance-test",
105+
is_flag=True,
106+
help=("Generate CWL conformance test object describing job. "
107+
"Required by CWL conformance test suite and implemented "
108+
"by cwltool reference implementation."),
109+
)
110+
111+
102112
def brew_dependency_resolution():
103113
return click.option(
104114
"--brew_dependency_resolution",
@@ -182,6 +192,19 @@ def required_tool_arg():
182192
return click.argument("path", metavar="TOOL_PATH", type=arg_type)
183193

184194

195+
def required_job_arg():
196+
""" Decorate click method as requiring the path to a single tool.
197+
"""
198+
arg_type = click.Path(
199+
exists=True,
200+
file_okay=True,
201+
dir_okay=False,
202+
readable=True,
203+
resolve_path=True,
204+
)
205+
return click.argument("job_path", metavar="JOB_PATH", type=arg_type)
206+
207+
185208
def _optional_tools_default(ctx, param, value):
186209
if param.name == "paths" and len(value) == 0:
187210
return [os.path.abspath(os.getcwd())]

planemo_ext/cwl2script

Submodule cwl2script added at 401d3e3

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
'PyGithub',
2424
'bioblend',
2525
'glob2',
26+
'cwltool',
2627
]
2728

2829
# Latest stable bioblend does not support Python 3, setup dev dependency.
@@ -59,6 +60,7 @@
5960
'planemo.shed2tap',
6061
'planemo.xml',
6162
'planemo_ext',
63+
'planemo_ext.cwl2script',
6264
'planemo_ext.galaxy',
6365
'planemo_ext.galaxy.eggs',
6466
'planemo_ext.galaxy.tools',

0 commit comments

Comments
 (0)