This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild_workflow.py
executable file
·104 lines (92 loc) · 3.95 KB
/
build_workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# Build the workflow to DNAnexus, and optionally test it. Assumes dx-toolkit
# is installed and configured
from __future__ import print_function
import dxpy
import argparse
import sys
import os
import subprocess
import json
import time
dxWDL_version="0.77"
here = os.getcwd()
git_revision = subprocess.check_output(["git", "describe", "--always", "--dirty", "--tags"], cwd=here).strip()
def main():
argparser = argparse.ArgumentParser(description="Build DVGLx workflow on DNAnexus.")
argparser.add_argument("--project", help="DNAnexus project ID", default="project-FBQJgzQ04PyJ7JxZJJvZ39jX")
argparser.add_argument("--folder", help="Folder within project (default: timestamp/git-based)", default=None)
argparser.add_argument("--test", help="Build and run test workflow", action='store_true')
argparser.add_argument("--no-wait", help="With --test, launch the analysis and exit without awaiting completion", action='store_true')
args = argparser.parse_args()
ensure_dxWDL()
# set up environment
if args.folder is None:
args.folder = time.strftime("/builds/%Y-%m-%d/%H%M%S-") + git_revision
project = dxpy.DXProject(args.project)
print("project: {} ({})".format(project.name, args.project))
project.new_folder(args.folder, parents=True)
print("folder: {}".format(args.folder))
# build the workflow
wf = dxWDL(here+"/wdl/htsget_DeepVariant_GLnexus.wdl", project, args.folder)
print("workflow: {} ({})".format(wf.name, wf.get_id()))
# build and run the tests, if desired
if args.test:
test_folder=args.folder+"/test"
print("test folder: {}".format(test_folder))
project.new_folder(test_folder)
analyses = []
for test in ["b37_CEUtrio_ALDH2_BRCA1", "hg38_CEUtrio_ALDH2_BRCA1"]:
twf = dxWDL(here+"/test/test.wdl", project, test_folder, reorg=False, quiet=True,
inputs="{}/test/{}.input.json".format(here, test))
run_cmd=[
"dx", "run", twf.get_id(),
"--destination", "{}:{}".format(project.get_id(), test_folder),
"--name", "DVGLx test {} {}".format(git_revision, test),
"-f", "{}/test/{}.input.dx.json".format(here, test),
"-y", "--brief", "--priority", "normal"
]
analysis = subprocess.check_output(run_cmd).strip()
print("{}\t{}".format(test, analysis))
analyses.append(analysis)
if not args.no_wait:
noise = subprocess.Popen(["/bin/bash", "-c", "while true; do sleep 60; date; done"])
try:
subprocess.check_call(["dx","wait"] + analyses)
print("success")
finally:
noise.kill()
# download the dxWDL jar file if necessary
def ensure_dxWDL():
dxWDL_fullname = "dxWDL-{}.jar".format(dxWDL_version)
dxWDL_local_path = os.path.join(here, dxWDL_fullname)
if not os.path.exists(dxWDL_local_path):
# download the jar file
download_cmd = [
"wget", "-nv",
"https://github.com/dnanexus/dxWDL/releases/download/{}/{}".format(dxWDL_version, dxWDL_fullname),
"-O",
dxWDL_local_path]
print(" ".join(download_cmd))
subprocess.check_call(download_cmd)
return dxWDL_local_path
def dxWDL(filename, project, folder, reorg=True, inputs=None, quiet=False):
dxWDL_path = ensure_dxWDL()
cmd = ["java", "-jar", dxWDL_path, "compile",
os.path.join(here, filename),
"-project", project.get_id(),
"-folder", folder,
"-imports", here+"/wdl"]
if inputs:
cmd = cmd + ["--inputs", inputs]
if reorg:
cmd = cmd + ["--reorg"]
if quiet:
cmd = cmd + ["--quiet"]
buf = subprocess.check_output(cmd)
wfid = buf.strip()
wf = dxpy.DXWorkflow(wfid, project.get_id())
wf.set_properties({"git_revision": git_revision})
return wf
if __name__ == '__main__':
main()