-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_daemon.py
214 lines (166 loc) · 5.59 KB
/
run_daemon.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import time
import subprocess
import sys
import os
import zipfile
import rna_design.email_client
def run_thread(nstruct, sequence, fmt, mutation_list, insertion_list, email):
args = []
if server_state == "release":
args.append( '/home/ubuntu/Rosetta/main/source/bin/rna_thread_and_minimize.linuxclangrelease' )
else:
args.append( '/home/ubuntu/Rosetta/main/source/bin/rna_thread_and_minimize.linuxclangdebug' )
args.extend( ( '-s', 'rna.pdb', '-nstruct', str(nstruct), '-score:weights', 'rna_minimize' ) )
if len( sequence ) > 0:
args.append( '-seq' )
args.append( sequence )
if fmt != "DEFAULT":
args.append( '-input_sequence_type' )
args.append( fmt )
if len( mutation_list ) > 0:
args.append( '-mutation_list' )
args.append( mutation_list )
if len( insertion_list ) > 0:
args.append( '-insertion_list' )
args.append( insertion_list )
f = open( "out.txt", "w" )
subprocess.call( args, stdout=f )
def format_pdb_num(num):
s = "S_"
if num < 1000:
s += "0"
if num < 100:
s += "0"
if num < 10:
s += "0"
s += str(num)
return s + ".pdb"
class SequenceCluster(object):
def __init__(self, score, pdb_file):
self.score, self.pdb_file = score, pdb_file
def lines_from( fn ):
f = open( fn )
try:
lines = f.readlines()
except:
print "could not open", fn
f.close()
return lines
def output_png( pdb, num ):
try:
subprocess.call(["pymol", "-pc", pdb, "-d", "orient all; rr(); ray 320, 240; png test.png; quit"] )
except:
e = sys.exc_info()[0]
print e
try:
subprocess.call(["convert", "test.png", "-trim", "cluster_%s.png" % str(num) ])
except:
e = sys.exc_info()[0]
print e
print "convert failed on", pdb, num
def get_top_clusters():
# score vs rmsd for all!
f = open("score.sc")
lines = f.readlines()
f.close()
lines.pop(0)
min_energy = 10000
max_energy = -1000
ind_rms = 0
for l in lines:
spl = l.split()
if spl[1] == "total_score":
# label line
ind_rms = spl.index( "rms_from_starting" )
break
lines.pop(0)
energies = [ float(line.split()[1]) for line in lines ]
RMSDs = [ float(line.split()[ind_rms]) for line in lines ]
print energies
print RMSDs
import matplotlib.pyplot as plt
import numpy as np
plt.scatter( np.array( RMSDs ), np.array( energies ) )
plt.savefig( "svr.png" )
# TODO: an actual clustering procedure (this just gives you each decoy)
lines = [l for l in lines_from( "score.sc" ) if l[0:5] == "SCORE" ]#and l[7:9] != "tot"]
clusters = []
for i,l in enumerate(lines):
if i == 0: continue
print i,l
spl = l.split()
if len(clusters) == 0:
print "appending to clusters"
# use i, not i+1, since score term names line is 0
clusters.append(SequenceCluster(spl[1], "%s.pdb" % spl[-1] )) #format_pdb_num(i)))
continue
found = False
# deactivate score repetition - output everything for now
# (as single mutation runs will be deterministic)
#for c in clusters:
# if spl[1] == c.score:
# found = True
# break
if not found:
clusters.append(SequenceCluster(spl[1], "%s.pdb" % spl[-1] )) #format_pdb_num(i)))
if len(clusters) > 4:
break
for i,c in enumerate(clusters):
output_png( c.pdb_file, i+1 )
f = zipfile.ZipFile("all.zip", "w")
for name in os.listdir('.'):
if name[-4:] != '.pdb':
continue
f.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
f.close()
def write_error_file(error):
f = open("ERROR", "w")
f.write(error + ', an email has been sent to the administrator, please email amw579@stanford.edu if you have questions')
f.close()
def update_jobs_file(lines):
f = open("jobs.dat", "w")
for l in lines:
f.write(l)
f.close()
if __name__ == '__main__' :
fr = open("run_jobs", "a")
while True:
f = open("jobs.dat")
lines = f.readlines()
f.close()
if len(lines) == 0:
time.sleep(5)
continue
print "job detected!"
spl = lines[0].split(" | ")
cl = lines.pop(0)
job_dir = spl[0]
nstruct = int(spl[1])
sequence=spl[2].rstrip()
fmt=spl[3].rstrip()
mutation_list=spl[4].rstrip()
insertion_list=spl[5].rstrip()
email=spl[6].rstrip()
os.chdir(job_dir)
try:
run_thread(int(nstruct), sequence, fmt, mutation_list, insertion_list, email)
except:
print nstruct, "|%s|" % sequence, "|%s|" % fmt, "|%s|" % mutation_list, "|%s|" % insertion_list, email
write_error_file('rna_thread_and_minimize failed')
os.chdir("../..")
update_jobs_file(lines)
continue
try:
get_top_clusters()
except:
write_error_file('generating top models failed')
os.chdir("../..")
update_jobs_file(lines)
continue
os.chdir("../..")
print "job completed"
if email is not None:
print email
#rna_design.email_client.send_email(email, job_dir[5:])
fr.write(cl)
update_jobs_file(lines)