Skip to content

Commit d0f9d40

Browse files
denis-yuentetron
authored andcommitted
CWL document resolver via GA4GH tool API (#201)
* Support Dockstore lookups for tools. * Update README.rst to add reference to discovery mechanism * Add --enable/disable-ga4gh-tool-registry and --add-ga4gh-tool-registry
1 parent 46d337f commit d0f9d40

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

README.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ is referenced and that document isn't found in the current directory then the
7878
following locations will be searched:
7979
http://www.commonwl.org/v1.0/CommandLineTool.html#Discovering_CWL_documents_on_a_local_filesystem
8080

81+
82+
Use with GA4GH Tool Registry API
83+
--------------------------------
84+
85+
Cwltool can launch tools directly from `GA4GH Tool Registry API`_ endpoints.
86+
87+
By default, cwltool searches https://dockstore.org/ . Use --add-tool-registry to add other registries to the search path.
88+
89+
For example ::
90+
91+
cwltool --non-strict quay.io/collaboratory/dockstore-tool-bamstats:master test.json
92+
93+
and (defaults to latest when a version is not specified) ::
94+
95+
cwltool --non-strict quay.io/collaboratory/dockstore-tool-bamstats test.json
96+
97+
For this example, grab the test.json (and input file) from https://github.com/CancerCollaboratory/dockstore-tool-bamstats
98+
99+
.. _`GA4GH Tool Registry API`: https://github.com/ga4gh/tool-registry-schemas
100+
81101
Import as a module
82102
------------------
83103

@@ -101,6 +121,8 @@ The easiest way to use cwltool to run a tool or workflow from Python is to use a
101121
Cwltool control flow
102122
--------------------
103123

124+
Technical outline of how cwltool works internally, for maintainers.
125+
104126
#. Use CWL `load_tool()` to load document.
105127

106128
#. Fetches the document from file or URL

cwltool/main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from .pack import pack
2828
from .process import (shortname, Process, relocateOutputs, cleanIntermediate,
2929
scandeps, normalizeFilesDirs, use_custom_schema, use_standard_schema)
30-
from .resolver import tool_resolver
30+
from .resolver import tool_resolver, ga4gh_tool_registries
3131
from .stdfsaccess import StdFsAccess
3232

3333
_logger = logging.getLogger("cwltool")
@@ -166,7 +166,16 @@ def arg_parser(): # type: () -> argparse.ArgumentParser
166166
help="Will be passed to `docker run` as the '--net' "
167167
"parameter. Implies '--enable-net'.")
168168

169-
parser.add_argument("--on-error", type=str,
169+
exgroup = parser.add_mutually_exclusive_group()
170+
exgroup.add_argument("--enable-ga4gh-tool-registry", action="store_true", help="Enable resolution using GA4GH tool registry API",
171+
dest="enable_ga4gh_tool_registry", default=True)
172+
exgroup.add_argument("--disable-ga4gh-tool-registry", action="store_false", help="Disable resolution using GA4GH tool registry API",
173+
dest="enable_ga4gh_tool_registry", default=True)
174+
175+
parser.add_argument("--add-ga4gh-tool-registry", action="append", help="Add a GA4GH tool registry endpoint to use for resolution, default %s" % ga4gh_tool_registries,
176+
dest="ga4gh_tool_registries", default=[])
177+
178+
parser.add_argument("--on-error",
170179
help="Desired workflow behavior when a step fails. One of 'stop' or 'continue'. "
171180
"Default is 'stop'.", default="stop", choices=("stop", "continue"))
172181

@@ -642,6 +651,11 @@ def main(argsl=None, # type: List[str]
642651
if args.relax_path_checks:
643652
draft2tool.ACCEPTLIST_RE = draft2tool.ACCEPTLIST_EN_RELAXED_RE
644653

654+
if args.ga4gh_tool_registries:
655+
ga4gh_tool_registries[:] = args.ga4gh_tool_registries
656+
if not args.enable_ga4gh_tool_registry:
657+
del ga4gh_tool_registries[:]
658+
645659
if args.enable_ext:
646660
res = pkg_resources.resource_stream(__name__, 'extensions.yml')
647661
use_custom_schema("v1.0", "http://commonwl.org/cwltool", res.read())

cwltool/resolver.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import urllib
34

45
from schema_salad.ref_resolver import file_uri
56

@@ -25,8 +26,25 @@ def resolve_local(document_loader, uri):
2526

2627

2728
def tool_resolver(document_loader, uri):
28-
for r in [resolve_local]:
29+
for r in [resolve_local, resolve_ga4gh_tool]:
2930
ret = r(document_loader, uri)
3031
if ret is not None:
3132
return ret
3233
return file_uri(os.path.abspath(uri), split_frag=True)
34+
35+
36+
ga4gh_tool_registries = ["https://dockstore.org:8443"]
37+
38+
def resolve_ga4gh_tool(document_loader, uri):
39+
path, version = uri.partition(":")[::2]
40+
if not version:
41+
version = "latest"
42+
for reg in ga4gh_tool_registries:
43+
ds = "{0}/api/ga4gh/v1/tools/{1}/versions/{2}/plain-CWL/descriptor".format(reg, urllib.quote(path, ""), urllib.quote(version, ""))
44+
try:
45+
resp = document_loader.session.head(ds)
46+
resp.raise_for_status()
47+
return ds
48+
except Exception:
49+
pass
50+
return None

0 commit comments

Comments
 (0)