-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
--toil
engine type for CWL development.
More information on Toil can be found at https://github.com/BD2KGenomics/toil.
- Loading branch information
Showing
6 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
"""Entry point for modules describing abstractions for dealing with CWL artifacts.""" | ||
from .run import run_cwltool | ||
from .script import to_script | ||
from .toil import run_toil | ||
|
||
|
||
__all__ = ( | ||
'run_cwltool', | ||
'run_toil', | ||
'to_script', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from __future__ import absolute_import | ||
|
||
import json | ||
import tempfile | ||
|
||
try: | ||
from toil.cwl import cwltoil | ||
except ImportError: | ||
cwltoil = None | ||
|
||
from planemo.deps import ensure_dependency_resolvers_conf_configured | ||
from planemo.io import error, real_io | ||
from planemo.runnable import ( | ||
ErrorRunResponse, | ||
) | ||
from .run import ( | ||
CwlToolRunResponse, | ||
JSON_PARSE_ERROR_MESSAGE | ||
) | ||
|
||
|
||
TOIL_REQUIRED_MESSAGE = "This functionality requires Toil, please install with 'pip install toil'" | ||
|
||
|
||
def run_toil(ctx, path, job_path, **kwds): | ||
"""Translate planemo kwds to cwltool kwds and run cwltool main function.""" | ||
_ensure_toil_available() | ||
|
||
args = [] | ||
if not ctx.verbose: | ||
args.append("--quiet") | ||
output_directory = kwds.get("output_directory", None) | ||
if output_directory: | ||
args.append("--outdir") | ||
args.append(output_directory) | ||
if kwds.get("no_container", False): | ||
args.append("--no-container") | ||
ensure_dependency_resolvers_conf_configured(ctx, kwds) | ||
args.append("--beta-dependency-resolvers-configuration") | ||
args.append(kwds["dependency_resolvers_config_file"]) | ||
if kwds.get("mulled_containers"): | ||
args.append("--beta-use-biocontainers") | ||
|
||
if kwds.get("non_strict_cwl", False): | ||
args.append("--non-strict") | ||
|
||
args.extend([path, job_path]) | ||
ctx.vlog("Calling cwltoil with arguments %s" % args) | ||
with tempfile.NamedTemporaryFile("w") as tmp_stdout: | ||
# cwltool passes sys.stderr to subprocess.Popen - ensure it has | ||
# and actual fileno. | ||
with real_io(): | ||
ret_code = cwltoil.main( | ||
args, | ||
stdout=tmp_stdout | ||
) | ||
tmp_stdout.flush() | ||
with open(tmp_stdout.name, "r") as stdout_f: | ||
try: | ||
result = json.load(stdout_f) | ||
except ValueError: | ||
message = JSON_PARSE_ERROR_MESSAGE % ( | ||
open(tmp_stdout.name, "r").read(), | ||
tmp_stdout.name, | ||
) | ||
error(message) | ||
raise Exception(message) | ||
|
||
if ret_code != 0: | ||
return ErrorRunResponse("Error running Toil") | ||
outputs = result | ||
return CwlToolRunResponse( | ||
"", | ||
outputs=outputs, | ||
) | ||
|
||
|
||
def _ensure_toil_available(): | ||
if cwltoil is None: | ||
raise Exception(TOIL_REQUIRED_MESSAGE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Module contianing the :class:`ToilEngine` implementation of :class:`Engine`.""" | ||
|
||
from planemo import cwl | ||
from planemo.runnable import RunnableType | ||
from .interface import BaseEngine | ||
|
||
|
||
class ToilEngine(BaseEngine): | ||
"""An :class:`Engine` implementation backed by Toil. | ||
More information on toil can be found at https://github.com/BD2KGenomics/toil. | ||
""" | ||
|
||
handled_runnable_types = [RunnableType.cwl_tool, RunnableType.cwl_workflow] | ||
|
||
def _run(self, runnable, job_path): | ||
"""Run CWL job using Toil.""" | ||
path = runnable.path | ||
return cwl.run_toil(self._ctx, path, job_path, **self._kwds) | ||
|
||
|
||
__all__ = ( | ||
"ToilEngine", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters