-
Notifications
You must be signed in to change notification settings - Fork 0
/
yukti.py
executable file
·474 lines (347 loc) · 16.5 KB
/
yukti.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# "yukti": a program, intended for the students of computational biology & bioinformatics; helps its users perform an assisted experiment involving molecular docking simulation techniques
import os;
from shutil import copyfile;
from shutil import rmtree;
print("\nHello user! 'YUKTI' (yukti.py) is running now! Always make sure that you've properly converted all of your targets/proteins & ligands/compounds to the PDBQT file format before using this program in order to avoid any errors!\n\nA recommendation:\n\nIf you run 'YUKTI' more than once in the same folder/directory for any reason, then make sure to remove everything created during its previous run before you run it again because otherwise, it'll all get deleted & also make sure to take a proper look at the \"read me\" file prepared for it. This program's flexibility will keep improving until its development is complete & the preparations required for using it will keep decreasing.\n");
judge1 = os.path.exists("/home/user/YUKTI/target_1");
if judge1 == True:
rmtree("/home/user/YUKTI/target_1");
os.mkdir("/home/user/YUKTI/target_1");
folders1 = ["{}".format(x) for x in range(11)];
del folders1[0];
for f_variable in folders1:
os.mkdir(os.path.join("/home/user/YUKTI/target_1", f_variable));
src_path = "/home/user/YUKTI/";
#fileA = "autodock4.exe";
#fileB = "autogrid4.exe";
fileC = "target_1.pdb";
fileD = "target_1.pdbqt";
for f_variable in folders1:
dst_path = "/home/user/YUKTI/target_1/{}/".format(f_variable);
#copyfile(src_path+str(fileA), dst_path+str(fileA));
#copyfile(src_path+str(fileB), dst_path+str(fileB));
copyfile(src_path+str(fileC), dst_path+str(fileC));
copyfile(src_path+str(fileD), dst_path+str(fileD));
judge2 = os.path.exists("/home/user/YUKTI/target_2");
if judge2 == True:
rmtree("/home/user/YUKTI/target_2");
os.mkdir("/home/user/YUKTI/target_2");
folders2 = ["{}".format(x) for x in range(11)];
del folders2[0];
for f_variable in folders2:
os.mkdir(os.path.join("/home/user/YUKTI/target_2", f_variable));
src_path = "/home/user/YUKTI/";
#fileA = "autodock4.exe";
#fileB = "autogrid4.exe";
fileC = "target_2.pdb";
fileD = "target_2.pdbqt";
for f_variable in folders2:
dst_path = "/home/user/YUKTI/target_2/{}/".format(f_variable);
#copyfile(src_path+str(fileA), dst_path+str(fileA));
#copyfile(src_path+str(fileB), dst_path+str(fileB));
copyfile(src_path+str(fileC), dst_path+str(fileC));
copyfile(src_path+str(fileD), dst_path+str(fileD));
folders = ["{}".format(x) for x in range(11)];
del folders[0];
src_path1 = "/home/user/YUKTI/library-pdbqt/";
for f_variable in folders:
dst_path1 = "/home/user/YUKTI/target_1/{}/".format(f_variable);
dst_path2 = "/home/user/YUKTI/target_2/{}/".format(f_variable);
copyfile(src_path1+"compound_"+str(f_variable)+".pdbqt", dst_path1+"compound_"+str(f_variable)+".pdbqt");
copyfile(src_path1+"compound_"+str(f_variable)+".pdbqt", dst_path2+"compound_"+str(f_variable)+".pdbqt");
copyfile("/home/user/YUKTI/library-pdb/compound_"+str(f_variable)+".pdb", dst_path1+"compound_"+str(f_variable)+".pdb");
copyfile("/home/user/YUKTI/library-pdb/compound_"+str(f_variable)+".pdb", dst_path2+"compound_"+str(f_variable)+".pdb");
src_path2 = "/home/user/YUKTI/";
for f_variable in folders:
dst_path1 = "/home/user/YUKTI/target_1/{}/".format(f_variable);
dst_path2 = "/home/user/YUKTI/target_2/{}/".format(f_variable);
copyfile(src_path2+"prepare_gpf4.py", dst_path1+"prepare_gpf4.py");
copyfile(src_path2+"prepare_gpf4.py", dst_path2+"prepare_gpf4.py");
copyfile(src_path2+"prepare_dpf4.py", dst_path1+"prepare_dpf4.py");
copyfile(src_path2+"prepare_dpf4.py", dst_path2+"prepare_dpf4.py");
#copyfile(src_path2+"sunya.py", dst_path1+"sunya.py");
#copyfile(src_path2+"sunya.py", dst_path2+"sunya.py");
index = list(range(0, 10));
location1 = "/home/user/YUKTI/target_1";
folders1 = ["{}".format(x) for x in range(11)];
del folders1[0];
for i_variable1 in index:
folders1[i_variable1] = os.path.join(location1, folders1[i_variable1]);
location2 = "/home/user/YUKTI/target_2";
folders2 = ["{}".format(x) for x in range(11)];
del folders2[0];
for i_variable2 in index:
folders2[i_variable2] = os.path.join(location2, folders2[i_variable2]);
numbers = list(range(0, 11));
del numbers[0];
autopython = "/home/user/mgltools_x86_64Linux2_1.5.6/bin/pythonsh"; # location of 'pythonsh'
for i_variable in index:
holderA = autopython+" "+folders1[i_variable]+"/prepare_gpf4.py -l "+folders1[i_variable]+"/compound_"+str(numbers[i_variable])+".pdbqt -r "+folders1[i_variable]+"/target_1.pdbqt -p npts=\'60,60,60\' -p gridcenter=\'11.112,-7.196,1.36\' -o \'"+folders1[i_variable]+"/target.gpf\'";
os.system(holderA);
holderB = autopython+" "+folders1[i_variable]+"/prepare_dpf4.py -l "+folders1[i_variable]+"/compound_"+str(numbers[i_variable])+".pdbqt -r "+folders1[i_variable]+"/target_1.pdbqt -o \'"+folders1[i_variable]+"/compound_target.dpf\'";
os.system(holderB);
#holderC = "python3 "+folders1[i_variable]+"/sunya.py";
#os.system(holderC);
# insert replacement code to get rid of 'sunya.py'
tempaddr = folders1[i_variable] + "/";
#retrieved_address = __file__;
#retrieved_address = retrieved_address.replace("sunya.py", "");
retrieved_address = tempaddr;
file_path = retrieved_address+"compound_target.dpf";
fin = open(file_path, "rt");
data = fin.read();
data = data.replace('extended', 'bound');
fin.close();
fin = open(file_path, "wt");
fin.write(data);
fin.close();
os.chdir(folders1[i_variable]);
holderD = "autogrid4 -p "+folders1[i_variable]+"/target.gpf -l "+folders1[i_variable]+"/protein.glg";
os.system(holderD);
holderE = "autodock4 -p "+folders1[i_variable]+"/compound_target.dpf -l "+folders1[i_variable]+"/protein.dlg";
os.system(holderE);
with open('protein.dlg', 'r') as f:
content = f.read();
holder1 = content.index("\n\nMODEL ");
holder2 = content.index("TER\nENDMDL\n");
holder3 = content[holder1+1:holder2+11];
output = open("bestmodel.pdb", "w");
output.write(holder3);
output.close();
print("\nTarget 1's Compound "+str(i_variable+1)+" is done!\n");
holderA = autopython+" "+folders2[i_variable]+"/prepare_gpf4.py -l "+folders2[i_variable]+"/compound_"+str(numbers[i_variable])+".pdbqt -r "+folders2[i_variable]+"/target_2.pdbqt -p npts=\'82,42,126\' -o \'"+folders2[i_variable]+"/target.gpf\'";
os.system(holderA);
holderB = autopython+" "+folders2[i_variable]+"/prepare_dpf4.py -l "+folders2[i_variable]+"/compound_"+str(numbers[i_variable])+".pdbqt -r "+folders2[i_variable]+"/target_2.pdbqt -o \'"+folders2[i_variable]+"/compound_target.dpf\'";
os.system(holderB);
#holderC = "python3 "+folders2[i_variable]+"/sunya.py";
#os.system(holderC);
# insert replacement code to get rid of 'sunya.py'
tempaddr = folders2[i_variable] + "/";
#retrieved_address = __file__;
#retrieved_address = retrieved_address.replace("sunya.py", "");
retrieved_address = tempaddr;
file_path = retrieved_address+"compound_target.dpf";
fin = open(file_path, "rt");
data = fin.read();
data = data.replace('extended', 'bound');
fin.close();
fin = open(file_path, "wt");
fin.write(data);
fin.close();
os.chdir(folders2[i_variable]);
holderD = "autogrid4 -p "+folders2[i_variable]+"/target.gpf -l "+folders2[i_variable]+"/protein.glg";
os.system(holderD);
holderE = "autodock4 -p "+folders2[i_variable]+"/compound_target.dpf -l "+folders2[i_variable]+"/protein.dlg";
os.system(holderE);
with open('protein.dlg', 'r') as f:
content = f.read();
holder1 = content.index("\n\nMODEL ");
holder2 = content.index("TER\nENDMDL\n");
holder3 = content[holder1+1:holder2+11];
output = open("bestmodel.pdb", "w");
output.write(holder3);
output.close();
print("\nTarget 2's Compound "+str(i_variable+1)+" is done!\n");
index = list(range(0, 10));
values1 = list(range(0, 10));
values2 = list(range(0, 10));
location1 = "/home/user/YUKTI/target_1";
folders1 = ["{}".format(x) for x in range(11)];
del folders1[0];
for i_variable1 in index:
folders1[i_variable1] = os.path.join(location1, folders1[i_variable1]);
location2 = "/home/user/YUKTI/target_2";
folders2 = ["{}".format(x) for x in range(11)];
del folders2[0];
for i_variable2 in index:
folders2[i_variable2] = os.path.join(location2, folders2[i_variable2]);
for i_variable in index:
os.chdir(folders1[i_variable]);
x = "target 1";
y = "compound "+str(i_variable+1);
with open('protein.dlg', 'r') as f:
content = f.read();
holderA = content.index("|___________\n");
holderB = content[holderA+35:holderA+43];
#print("Binding Energy for "+x+"\'s "+y+"\'s best model: "+holderB);
values1[index[i_variable]] = float(holderB);
os.chdir(folders2[i_variable]);
x = "target 2";
y = "compound "+str(i_variable+1);
with open('protein.dlg', 'r') as f:
content = f.read();
holderA = content.index("|___________\n");
holderC = content[holderA+35:holderA+43];
#print("Binding Energy for "+x+"\'s "+y+"\'s best model: "+holderC);
values2[index[i_variable]] = float(holderC);
dex = list(range(0, 10));
take1 = list(range(0, 10));
take2 = list(range(0, 10));
v1 = sorted(values1); #print(values1); print(v1);
v11 = sorted(values11); #print(values11); print(v11);
numbers1 = list(range(0, 10));
numbers11 = list(range(0, 10));
# first ranker starts here onwards
repeat1S = [];
repeat2S = [];
repeat1Z = [];
repeat2Z = [];
repeat1J = [];
repeat2J = [];
for d in dex:
if d != 0:
if numbers1[d-1] == values1.index(v1[d])+1:
#repeat1S = [];
for i in range(0, len(values1)) :
if values1[i] == v1[d]:
repeat1S.append(i);
numbers1[d] = values1.index(v1[d])+1;
else:
numbers1[d] = values1.index(v1[d])+1;
else:
numbers1[d] = values1.index(v1[d])+1;
grrrr = []
for i in range(0, len(repeat1S)) :
j = (len(repeat1S)/2)+i;
j = int(j);
if j < len(repeat1S):
if repeat1S[i] == repeat1S[j]:
grrrr.append(j);
for i in range(0, len(grrrr)) :
del repeat1S[i];
#print("first repeat1S: "); print(repeat1S); print("first repeat1Z: "); print(repeat1Z); print("first repeat1J: "); print(repeat1J);
for i in range(0, len(repeat1S)) :
if values1[repeat1S[0]] != values1[repeat1S[-1]]:
repeat1Z.insert(0, repeat1S[-1]); # added from front
if repeat1S[-1] == repeat1Z[0]:
del repeat1S[-1]; # substracted from back
for i in range(0, len(repeat1Z)) :
if values1[repeat1Z[0]] != values1[repeat1Z[-1]]:
repeat1J.insert(0, repeat1Z[-1]); # added from front
if repeat1Z[-1] == repeat1J[0]:
del repeat1Z[-1]; # substracted from back
#print("first repeat1S: "); print(repeat1S); print("first repeat1Z: "); print(repeat1Z); print("first repeat1J: "); print(repeat1J);
for i in range(1, len(numbers1)) :
if numbers1[i] == numbers1[i-1]:
repeat2S.append(i);
#print("first repeat2S: "); print(repeat2S); print("first repeat2Z: "); print(repeat2Z); print("first repeat2J: "); print(repeat2J);
for i in range(0, len(repeat2S)) :
if v1[repeat2S[0]] != v1[repeat2S[-1]]:
repeat2Z.insert(0, repeat2S[-1]); # added from front
if repeat2S[-1] == repeat2Z[0]:
del repeat2S[-1]; # substracted from back
for i in range(0, len(repeat2Z)) :
if v1[repeat2Z[0]] != v1[repeat2Z[-1]]:
repeat2J.insert(0, repeat2Z[-1]); # added from front
if repeat2Z[-1] == repeat2J[0]:
del repeat2Z[-1]; # substracted from back
#print("first repeat2S: "); print(repeat2S); print("first repeat2Z: "); print(repeat2Z); print("first repeat2J: "); print(repeat2J);
if repeat1S[0] > repeat1S[1]:
repeat1S.sort();
holdin = 1;
if holdin < len(repeat1S):
numbers1[repeat2S[holdin-1]] = repeat1S[holdin]+1;
if holdin < len(repeat1Z):
numbers1[repeat2Z[holdin-1]] = repeat1Z[holdin]+1;
if holdin < len(repeat1J):
numbers1[repeat2J[holdin-1]] = repeat1J[holdin]+1;
holdin = 2;
if holdin < len(repeat1S):
numbers1[repeat2S[holdin-1]] = repeat1S[holdin]+1;
if holdin < len(repeat1Z):
numbers1[repeat2Z[holdin-1]] = repeat1Z[holdin]+1;
if holdin < len(repeat1J):
numbers1[repeat2J[holdin-1]] = repeat1J[holdin]+1;
#print(values1); print(v1); print(numbers1);
# second ranker starts here onwards
repeat1S = [];
repeat2S = [];
repeat1Z = [];
repeat2Z = [];
repeat1J = [];
repeat2J = [];
for d in dex:
if d != 0:
if numbers11[d-1] == values11.index(v11[d])+1:
#repeat1S = [];
for i in range(0, len(values11)) :
if values11[i] == v11[d]:
repeat1S.append(i);
numbers11[d] = values11.index(v11[d])+1;
else:
numbers11[d] = values11.index(v11[d])+1;
else:
numbers11[d] = values11.index(v11[d])+1;
grrrr = []
for i in range(0, len(repeat1S)) :
j = (len(repeat1S)/2)+i;
j = int(j);
if j < len(repeat1S):
if repeat1S[i] == repeat1S[j]:
grrrr.append(j);
for i in range(0, len(grrrr)) :
del repeat1S[i];
#print("second repeat1S: "); print(repeat1S); print("second repeat1Z: "); print(repeat1Z); print("second repeat1J: "); print(repeat1J);
for i in range(0, len(repeat1S)) :
if values11[repeat1S[0]] != values11[repeat1S[-1]]:
repeat1Z.insert(0, repeat1S[-1]); # added from front
if repeat1S[-1] == repeat1Z[0]:
del repeat1S[-1]; # substracted from back
for i in range(0, len(repeat1Z)) :
if values11[repeat1Z[0]] != values11[repeat1Z[-1]]:
repeat1J.insert(0, repeat1Z[-1]); # added from front
if repeat1Z[-1] == repeat1J[0]:
del repeat1Z[-1]; # substracted from back
#print("second repeat1S: "); print(repeat1S); print("second repeat1Z: "); print(repeat1Z); print("second repeat1J: "); print(repeat1J);
for i in range(1, len(numbers11)) :
if numbers11[i] == numbers11[i-1]:
repeat2S.append(i);
#print("second repeat2S: "); print(repeat2S); print("second repeat2Z: "); print(repeat2Z); print("second repeat2J: "); print(repeat2J);
for i in range(0, len(repeat2S)) :
if v11[repeat2S[0]] != v11[repeat2S[-1]]:
repeat2Z.insert(0, repeat2S[-1]); # added from front
if repeat2S[-1] == repeat2Z[0]:
del repeat2S[-1]; # substracted from back
for i in range(0, len(repeat2Z)) :
if v11[repeat2Z[0]] != v11[repeat2Z[-1]]:
repeat2J.insert(0, repeat2Z[-1]); # added from front
if repeat2Z[-1] == repeat2J[0]:
del repeat2Z[-1]; # substracted from back
#print("second repeat2S: "); print(repeat2S); print("second repeat2Z: "); print(repeat2Z); print("second repeat2J: "); print(repeat2J);
if repeat1S[0] > repeat1S[1]:
repeat1S.sort();
holdin = 1;
if holdin < len(repeat1S):
numbers11[repeat2S[holdin-1]] = repeat1S[holdin]+1;
if holdin < len(repeat1Z):
numbers11[repeat2Z[holdin-1]] = repeat1Z[holdin]+1;
if holdin < len(repeat1J):
numbers11[repeat2J[holdin-1]] = repeat1J[holdin]+1;
holdin = 2;
if holdin < len(repeat1S):
numbers11[repeat2S[holdin-1]] = repeat1S[holdin]+1;
if holdin < len(repeat1Z):
numbers11[repeat2Z[holdin-1]] = repeat1Z[holdin]+1;
if holdin < len(repeat1J):
numbers11[repeat2J[holdin-1]] = repeat1J[holdin]+1;
#print(values11); print(v11); print(numbers11);
for d in dex:
take1[d] = "Compound "+str(numbers1[d])+" at "+str(v1[d]);
take2[d] = "Compound "+str(numbers11[d])+" at "+str(v11[d]);
print("Top 10 results in our library of ligands for Target 1 in ascending order:");
for d in dex:
print(str(d+1)+". "+take1[d]);
print("Top 10 results in our library of ligands for Target 2 in ascending order:");
for d in dex:
print(str(d+1)+". "+take2[d]);
print("The result rankings will also be available as \"top_results.txt\" and will be updated every time this program is run.\n");
os.chdir("/home/user/YUKTI");
output = open("top_results.txt", "w");
output.write("Top 10 results in our library of ligands for Target 1 in ascending order:\n");
for d in dex:
output.write(str(d+1)+". "+take1[d]+"\n");
output.write("Top 10 results in our library of ligands for Target 2 in ascending order:\n");
for d in dex:
output.write(str(d+1)+". "+take2[d]+"\n");
output.write("The result rankings will also be presented on the console and will be updated every time this program is run.\n");
output.close();