Repository navigation
Expand file tree
/
Copy pathqsub.py
More file actions
64 lines (52 loc) · 1.77 KB
/
Copy pathqsub.py
File metadata and controls
64 lines (52 loc) · 1.77 KB
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
'''The code is a modified version of cluster_utils.py
from MISO package.
'''
import time
import subprocess
def check_job(jobid):
'''Returns True is a job is finished,
otherwise False.
'''
output = subprocess.Popen('qstat %i' %(jobid),
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE).communicate()
if 'Unknown Job Id Error' in output[1]:
return True
else:
return False
def wait_on_job(jobids, delay=60):
'''Wait until a job is finished.'''
completed = []
while(len(completed) < len(jobids)):
for jid in jobids:
if jid in completed:
continue
status = check_job(jid)
if status: # job is finished
print >> sys.stderr, 'Job #%d is finished [%d/%d]' \
% (jid, len(completed), len(jobids))
completed.append(jid)
else:
print >> sys.stderr, 'Waiting for job #%d' % (jid)
time.sleep(delay)
def launch_job(commands):
'''Launches a job by executing a command.'''
jobids = []
for cmd in commands:
proc = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
# Read the job ID if it's a known cluster
# submission system
output = proc.communicate()
if "." in output[0][:-1] and ">" not in output[0]:
jobids.append(int(output[0].split(".")[0]))
wait_on_job(jobids)
if __name__=='__main__':
import sys
input = sys.argv[1]
commands = ['qsub -v input=%s blat_job.sh' % (input)]
print commands
launch_job(commands)