-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster-submitter.py
executable file
·53 lines (43 loc) · 1.39 KB
/
cluster-submitter.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
#!/usr/bin/env python3
import math
import os
import sys
import re
from snakemake.utils import read_job_properties
jobscript = sys.argv[-1]
mo = re.match(r'(\S+)/snakejob\.\S+\.(\d+)\.sh', jobscript)
assert mo
sm_tmpdir, sm_jobid = mo.groups()
props = read_job_properties(jobscript)
# set up job name, project name
jobname = '{rule}-{jobid}'.format(rule=props['rule'], jobid=sm_jobid)
cluster = props['cluster']
mem_per_core = math.ceil(float(cluster['mem']) / int(cluster['n']))
if cluster['mem'] > 16:
reservation = 'y'
else:
reservation = 'n'
res_req = {
'm_mem_free': '{}G'.format(mem_per_core),
'h_vmem': '{}G'.format(mem_per_core),
}
if 'time' in cluster:
res_req['h_rt'] = '{}:00'.format(cluster['time'])
res_req_str = ','.join('{}={}'.format(k, v) for k, v in res_req.items())
cmd = ('qbsub --profile -r y -N {jobname} -q {queue} -R {reservation} '
'-l {res_req} '
'-n {n} -o {log}'.format(
jobname=jobname,
queue=cluster['queue'],
reservation=reservation,
res_req=res_req_str,
log=cluster.get('log') or 'log/default.log',
n=cluster['n']))
dependencies = set(sys.argv[1:-2])
if dependencies:
cmd += " -hold_jid '{}'".format(','.join(dependencies))
# the actual job
cmd += ' %s' % jobscript
# the part that strips bsub's output to just the job id
cmd += r' | tail -1 | cut -f 3 -d \ '
os.system(cmd)