-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun
executable file
·91 lines (72 loc) · 2.83 KB
/
run
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
#! /usr/bin/env python
"""
Execution script for snakemake workflows.
"""
import argparse
import os.path
import snakemake
import sys
import pprint
import json
thisdir = os.path.abspath(os.path.dirname(__file__))
def main(args):
# first, find the Snakefile
snakefile = os.path.join(thisdir, 'Snakefile')
if not os.path.exists(snakefile):
sys.stderr.write('Error: cannot find Snakefile at {}\n'.format(snakefile))
sys.exit(-1)
# next, find the workflow config file
workflowfile = None
if os.path.exists(args.workflowfile) and not os.path.isdir(args.workflowfile):
workflowfile = args.workflowfile
else:
for suffix in ('', '.json'):
tryfile = os.path.join(thisdir, args.workflowfile + suffix)
if os.path.exists(tryfile) and not os.path.isdir(tryfile):
sys.stderr.write('Found workflowfile at {}\n'.format(tryfile))
workflowfile = tryfile
break
if not workflowfile:
sys.stderr.write('Error: cannot find workflowfile {}\n'.format(args.workflowfile))
sys.exit(-1)
# next, find the workflow params file
paramsfile = None
if os.path.exists(args.paramsfile) and not os.path.isdir(args.paramsfile):
paramsfile = args.paramsfile
else:
for suffix in ('', '.json'):
tryfile = os.path.join(thisdir, args.paramsfile + suffix)
if os.path.exists(tryfile) and not os.path.isdir(tryfile):
sys.stderr.write('Found paramsfile at {}\n'.format(tryfile))
paramsfile = tryfile
break
if not paramsfile:
sys.stderr.write('Error: cannot find paramsfile {}\n'.format(args.paramsfile))
sys.exit(-1)
with open(workflowfile, 'rt') as fp:
workflow_info = json.load(fp)
target = workflow_info['workflow_target']
config = dict()
print('--------')
print('details!')
print('\tsnakefile: {}'.format(snakefile))
print('\tconfig: {}'.format(workflowfile))
print('\tparams: {}'.format(paramsfile))
print('\ttarget: {}'.format(target))
print('--------')
# run!!
status = snakemake.snakemake(snakefile, configfile=paramsfile,
targets=[target], printshellcmds=True,
dryrun=args.dry_run, config=config)
if status: # translate "success" into shell exit code of 0
return 0
return 1
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='run snakemake workflows', usage='''run <workflow> <parameters> [<target>]
Run snakemake workflows, using the given workflow name & parameters file.
''')
parser.add_argument('workflowfile')
parser.add_argument('paramsfile')
parser.add_argument('-n', '--dry-run', action='store_true')
args = parser.parse_args()
sys.exit(main(args))