Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/planemo/cwl/toil.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import json | |
4 import tempfile | |
5 | |
6 try: | |
7 from toil.cwl import cwltoil | |
8 except ImportError: | |
9 cwltoil = None | |
10 | |
11 from planemo.deps import ensure_dependency_resolvers_conf_configured | |
12 from planemo.io import error, real_io | |
13 from planemo.runnable import ( | |
14 ErrorRunResponse, | |
15 ) | |
16 from .run import ( | |
17 CwlToolRunResponse, | |
18 JSON_PARSE_ERROR_MESSAGE | |
19 ) | |
20 | |
21 | |
22 TOIL_REQUIRED_MESSAGE = "This functionality requires Toil, please install with 'pip install toil'" | |
23 | |
24 | |
25 def run_toil(ctx, path, job_path, **kwds): | |
26 """Translate planemo kwds to cwltool kwds and run cwltool main function.""" | |
27 _ensure_toil_available() | |
28 | |
29 args = [] | |
30 if not ctx.verbose: | |
31 args.append("--quiet") | |
32 output_directory = kwds.get("output_directory", None) | |
33 if output_directory: | |
34 args.append("--outdir") | |
35 args.append(output_directory) | |
36 if kwds.get("no_container", False): | |
37 args.append("--no-container") | |
38 ensure_dependency_resolvers_conf_configured(ctx, kwds) | |
39 args.append("--beta-dependency-resolvers-configuration") | |
40 args.append(kwds["dependency_resolvers_config_file"]) | |
41 if kwds.get("mulled_containers"): | |
42 args.append("--beta-use-biocontainers") | |
43 | |
44 if kwds.get("non_strict_cwl", False): | |
45 args.append("--non-strict") | |
46 | |
47 args.extend([path, job_path]) | |
48 ctx.vlog("Calling cwltoil with arguments %s" % args) | |
49 with tempfile.NamedTemporaryFile("w") as tmp_stdout: | |
50 # cwltool passes sys.stderr to subprocess.Popen - ensure it has | |
51 # and actual fileno. | |
52 with real_io(): | |
53 ret_code = cwltoil.main( | |
54 args, | |
55 stdout=tmp_stdout | |
56 ) | |
57 tmp_stdout.flush() | |
58 with open(tmp_stdout.name, "r") as stdout_f: | |
59 try: | |
60 result = json.load(stdout_f) | |
61 except ValueError: | |
62 message = JSON_PARSE_ERROR_MESSAGE % ( | |
63 open(tmp_stdout.name, "r").read(), | |
64 tmp_stdout.name, | |
65 ) | |
66 error(message) | |
67 raise Exception(message) | |
68 | |
69 if ret_code != 0: | |
70 return ErrorRunResponse("Error running Toil") | |
71 outputs = result | |
72 return CwlToolRunResponse( | |
73 "", | |
74 outputs=outputs, | |
75 ) | |
76 | |
77 | |
78 def _ensure_toil_available(): | |
79 if cwltoil is None: | |
80 raise Exception(TOIL_REQUIRED_MESSAGE) |