-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQsub.py
More file actions
executable file
·115 lines (104 loc) · 4.45 KB
/
Copy pathQsub.py
File metadata and controls
executable file
·115 lines (104 loc) · 4.45 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
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
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
#$ -cwd
#$ -j y
#$ -V
## Copyright (c) 2015 Ryan Koesterer GNU General Public License v3
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pwd
import psutil
import resource
import sys
from time import strftime, localtime, time, gmtime
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w')
def main(argv):
start_time = (localtime(), time())
env_vars = os.environ.copy()
local=False
user_name=pwd.getpwuid(os.getuid()).pw_name
if argv[1].split('(')[0] in ["RunSnv","RunSnvgroup","RunMeta","RunMerge","RunTools"] and 'SGE_TASK_ID' in env_vars:
if env_vars['SGE_TASK_ID'] not in ['None','undefined']:
with open(argv[2]) as f:
joblist = [line.rstrip() for line in f]
job = joblist[int(env_vars['SGE_TASK_ID'])-1]
argv[1] = argv[1].replace("UGA_JOB_ID",job)
argv[3] = argv[3].replace("UGA_JOB_ID",job)
argv[1] = argv[1].replace("UGA_JOB_RANGE",str(int((100 * ((int(job)-1) // 100) + 1))) + "-" + str(int((100 * ((int(job)-1) // 100) + 100))))
argv[3] = argv[3].replace("UGA_JOB_RANGE",str(int((100 * ((int(job)-1) // 100) + 1))) + "-" + str(int((100 * ((int(job)-1) // 100) + 100))))
try:
lf = open(argv[3],'w')
except(IOError, OSError):
return
sys.stdout = lf
sys.stderr = lf
if not 'REQNAME' in list(env_vars.keys()):
local=True
env_vars['REQNAME'] = env_vars['HOSTNAME'] + '_' + strftime('%Y_%m_%d_%H_%M_%S', start_time[0]) if 'HOSTNAME' in list(env_vars.keys()) else strftime('%Y_%m_%d_%H_%M_%S', start_time[0])
if not 'JOB_ID' in list(env_vars.keys()):
env_vars['JOB_ID'] = '1'
if not 'SGE_TASK_ID' in list(env_vars.keys()):
env_vars['SGE_TASK_ID'] = 'None'
from uga.__version__ import version
print("uga v" + version)
print("start time: " + strftime("%Y-%m-%d %H:%M:%S", start_time[0]))
if 'SGE_CLUSTER_NAME' in list(env_vars.keys()):
print("sge cluster: " + env_vars['SGE_CLUSTER_NAME'])
if 'HOST' in list(env_vars.keys()):
print("host: " + env_vars['HOST'])
if 'Queue' in list(env_vars.keys()):
print("queue: " + env_vars['QUEUE'])
if 'HOSTNAME' in list(env_vars.keys()):
print("compute node: " + env_vars['HOSTNAME'])
if 'PWD' in list(env_vars.keys()):
print("current directory: " + env_vars['PWD'])
print("user name: " + user_name)
if 'JOB_ID' in list(env_vars.keys()):
print("job id: " + env_vars['JOB_ID'])
if 'REQNAME' in list(env_vars.keys()):
print("job name: " + env_vars['REQNAME'])
if 'SGE_TASK_ID' in list(env_vars.keys()):
print("task index number: " + env_vars['SGE_TASK_ID'])
if 'SGE_STDOUT_PATH' in list(env_vars.keys()):
print("sge log file: " + env_vars['SGE_STDOUT_PATH'])
if argv[1].split('(')[0] == "RunSnv":
from uga.RunSnv import RunSnv
if argv[1].split('(')[0] == "RunSnvgroup":
from uga.RunSnvgroup import RunSnvgroup
if argv[1].split('(')[0] == "RunMeta":
from uga.RunMeta import RunMeta
if argv[1].split('(')[0] == "RunMerge":
from uga.RunMerge import RunMerge
if argv[1].split('(')[0] == "RunSnvplot":
from uga.RunSnvplot import RunSnvplot
if argv[1].split('(')[0] == "RunSnvgroupplot":
from uga.RunSnvgroupplot import RunSnvgroupplot
if argv[1].split('(')[0] == "RunFilter":
from uga.RunFilter import RunFilter
if argv[1].split('(')[0] == "RunTools":
from uga.RunTools import RunTools
print("")
print("command entered: " + argv[1])
r = eval(argv[1])
if r == 0:
end_time = (localtime(), time())
process = psutil.Process(os.getpid())
mem=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1000.0
mem_children=resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss/1000.0
print('finish time: ' + strftime("%Y-%m-%d %H:%M:%S", end_time[0]))
print('time elapsed: ' + strftime('%H:%M:%S', gmtime(end_time[1] - start_time[1])))
print('max memory used by main process: ' + str('%.2f' % mem) + ' MB')
print('max memory used by any subprocess: ' + str('%.2f' % mem_children) + ' MB')
if __name__ == "__main__":
main(sys.argv)