Permalink
Browse files

Implement cwl_script command.

  • Loading branch information...
jmchilton committed Oct 28, 2015
1 parent 17b4b40 commit 508dce72a5453d81672a8b9ec5e5f10f92393b23
Showing with 105 additions and 0 deletions.
  1. +3 −0 .gitmodules
  2. +76 −0 planemo/commands/cmd_cwl_script.py
  3. +23 −0 planemo/options.py
  4. +1 −0 planemo_ext/cwl2script
  5. +2 −0 setup.py
@@ -1,3 +1,6 @@
[submodule "planemo/xml/xsd/tool"]
path = planemo/xml/xsd/tool
url = https://github.com/JeanFred/Galaxy-XSD
[submodule "planemo_ext/cwl2script"]
path = planemo_ext/cwl2script
url = https://github.com/common-workflow-language/cwl2script.git
@@ -0,0 +1,76 @@
"""
"""
from __future__ import print_function

import copy
import os

import click

import schema_salad
import cwltool
from cwltool.main import load_tool
from cwltool.process import (
checkRequirements,
shortname,
)
from cwl2script.cwl2script import (
supportedProcessRequirements,
generateScriptForWorkflow,
generateScriptForTool,
)

from planemo.cli import pass_context
from planemo import options


@click.command("cwl_script")
@options.required_tool_arg()
@options.required_job_arg()
@click.option('--no_container', is_flag=True, default=False)
@click.option('outdir', '--output_dir', type=click.Path())
@click.option('basedir', '--base_dir', type=click.Path(), default=".")
@pass_context
def cli(ctx, path, job_path, **kwds):
"""This compiles simple common workflow language workflows to a shell
script.
"""
uri = "file://" + os.path.abspath(job_path)

loader = schema_salad.ref_resolver.Loader({
"@base": uri,
"path": {
"@type": "@id"
}
})

job, _ = loader.resolve_ref(uri)

t = load_tool(path, False, False, cwltool.workflow.defaultMakeTool, True)

if type(t) == int:
return t

checkRequirements(t.tool, supportedProcessRequirements)

for inp in t.tool["inputs"]:
if shortname(inp["id"]) in job:
pass
elif shortname(inp["id"]) not in job and "default" in inp:
job[shortname(inp["id"])] = copy.copy(inp["default"])
elif shortname(inp["id"]) not in job and inp["type"][0] == "null":
pass
else:
raise Exception("Missing inputs `%s`" % shortname(inp["id"]))

if not kwds.get("basedir", None):
kwds["basedir"] = os.path.dirname(os.path.abspath(job_path))

outdir = kwds.get("outdir")

if t.tool["class"] == "Workflow":
print(generateScriptForWorkflow(t, job, outdir))
elif t.tool["class"] == "CommandLineTool":
print(generateScriptForTool(t, job, outdir))

return 0
@@ -99,6 +99,16 @@ def enable_cwl_option():
)


def cwl_conformance_test():
return click.option(
"--conformance-test",
is_flag=True,
help=("Generate CWL conformance test object describing job. "
"Required by CWL conformance test suite and implemented "
"by cwltool reference implementation."),
)


def brew_dependency_resolution():
return click.option(
"--brew_dependency_resolution",
@@ -182,6 +192,19 @@ def required_tool_arg():
return click.argument("path", metavar="TOOL_PATH", type=arg_type)


def required_job_arg():
""" Decorate click method as requiring the path to a single tool.
"""
arg_type = click.Path(
exists=True,
file_okay=True,
dir_okay=False,
readable=True,
resolve_path=True,
)
return click.argument("job_path", metavar="JOB_PATH", type=arg_type)


def _optional_tools_default(ctx, param, value):
if param.name == "paths" and len(value) == 0:
return [os.path.abspath(os.getcwd())]
Submodule cwl2script added at 401d3e
@@ -23,6 +23,7 @@
'PyGithub',
'bioblend',
'glob2',
'cwltool',
]

# Latest stable bioblend does not support Python 3, setup dev dependency.
@@ -59,6 +60,7 @@
'planemo.shed2tap',
'planemo.xml',
'planemo_ext',
'planemo_ext.cwl2script',
'planemo_ext.galaxy',
'planemo_ext.galaxy.eggs',
'planemo_ext.galaxy.tools',

0 comments on commit 508dce7

Please sign in to comment.