-
Notifications
You must be signed in to change notification settings - Fork 5
/
QDeep.py
1409 lines (1231 loc) · 74.1 KB
/
QDeep.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
#######################################################################################################
# Name: QDeep.py
# Purpose: Protein single-model quality assessment using Residual Neural Network
# Developed by: Md Hossain Shuvo
# Developed on: 1/17/2020
# Modified by:
# Change log:
#######################################################################################################
import os, sys, math, time
import argparse, subprocess
import numpy as np
from tensorflow.keras.models import model_from_json
from datetime import timedelta
start_time = time.monotonic()
#----------------------global variables-------------------------#
# #
#---------------------------------------------------------------#
features = []
finalFeatures = []
window_size = 0
seq_length = 0
print('\n***************************************************************************')
print('* QDeep *')
print('* Distance-based protein model quality estimation using deep ResNets *')
print('* For comments, please email to bhattacharyad@auburn.edu *')
print('***************************************************************************')
#------------------------configure------------------------------#
#Configures before the first use #
#---------------------------------------------------------------#
configured = 0
qDeep_path = 'change/to/your/current/directory'
if(configured == 0 or not os.path.exists(qDeep_path + '/apps/aleigen') or
not os.path.exists(qDeep_path + '/apps/calNf_ly') or
not os.path.exists(qDeep_path + '/apps/dssp') or
not os.path.exists(qDeep_path + '/scripts/pdb2rr.pl') or
not os.path.exists(qDeep_path + '/scripts/ros_energy.py')):
print("\nError: not yet configured!\nPlease configure as follows\n$ cd QDeep\n$ python configure.py\n")
exit(1)
#------------------------arguments------------------------------#
#Shows help to the users #
#---------------------------------------------------------------#
parser = argparse.ArgumentParser()
parser._optionals.title = "Arguments"
parser.add_argument('--tgt', dest='target_name',
default = '', # default empty!
help = 'Target name')
parser.add_argument('--seq', dest='seq_file',
default = '', # default empty!
help = 'Sequence file')
parser.add_argument('--dcy', dest='decoy_dir',
default = '', # default empty!
help = 'Decoy directory')
parser.add_argument('--aln', dest='aln_file',
default = '', # default empty!
help = 'Multiple sequence alignment')
parser.add_argument('--dist', dest='distance_file',
default = '', # default empty!
help = 'DMPfold predicted distance')
parser.add_argument('--pssm', dest='pssm_file',
default = '', # default empty!
help = 'PSSM file')
parser.add_argument('--spd3', dest='spd33_file',
default = '', # default empty!
help = 'SPIDER3 output (.spd33)')
parser.add_argument('--msa', dest='yes',
default = 'no', # default no!
help = 'yes|no Whether to use deep MSA (default: no)')
parser.add_argument('--gpu', dest='device_id',
default = '-1', # default cpu!
help = 'Device id (0/1/2/3/4/..) Whether to run on GPU (default: CPU)')
parser.add_argument('--out', dest='output_path',
default = '', # default empty!
help = 'Output directory name')
if len(sys.argv) < 8:
parser.print_help(sys.stderr)
sys.exit(1)
options = parser.parse_args()
seq_file = options.seq_file
target_name = options.target_name
decoy_dir = options.decoy_dir
aln_file = options.aln_file
pssm_file = options.pssm_file
spd3_file = options.spd33_file
dist_file = options.distance_file
deep_msa = options.yes
gpu = options.device_id
output_path = options.output_path
working_path = os.getcwd()
#----------------trained models and weights---------------------#
# #
#---------------------------------------------------------------#
if(deep_msa == 'no'):
model_1_0 = qDeep_path + '/models/QDeep_standard/1.0/model_on_parameter_1'
model_2_0 = qDeep_path + '/models/QDeep_standard/2.0/model_on_parameter_1'
model_4_0 = qDeep_path + '/models/QDeep_standard/4.0/model_on_parameter_1'
model_8_0 = qDeep_path + '/models/QDeep_standard/8.0/model_on_parameter_1'
model_1_0_weight = qDeep_path + '/models/QDeep_standard/1.0/weights_on_parameter_1.h5'
model_2_0_weight = qDeep_path + '/models/QDeep_standard/2.0/weights_on_parameter_1.h5'
model_4_0_weight = qDeep_path + '/models/QDeep_standard/4.0/weights_on_parameter_1.h5'
model_8_0_weight = qDeep_path + '/models/QDeep_standard/8.0/weights_on_parameter_1.h5'
if(deep_msa == 'yes'):
model_1_0 = qDeep_path + '/models/QDeep_deep/1.0/model_on_parameter_1'
model_2_0 = qDeep_path + '/models/QDeep_deep/2.0/model_on_parameter_1'
model_4_0 = qDeep_path + '/models/QDeep_deep/4.0/model_on_parameter_1'
model_8_0 = qDeep_path + '/models/QDeep_deep/8.0/model_on_parameter_1'
model_1_0_weight = qDeep_path + '/models/QDeep_deep/1.0/weights_on_parameter_1.h5'
model_2_0_weight = qDeep_path + '/models/QDeep_deep/2.0/weights_on_parameter_1.h5'
model_4_0_weight = qDeep_path + '/models/QDeep_deep/4.0/weights_on_parameter_1.h5'
model_8_0_weight = qDeep_path + '/models/QDeep_deep/8.0/weights_on_parameter_1.h5'
#------------------------sets GPU device------------------------#
# #
#---------------------------------------------------------------#
if(gpu != ""):
os.environ["CUDA_VISIBLE_DEVICES"] = gpu
#------------------------DO NOT change--------------------------#
# #
#---------------------------------------------------------------#
dssp_path = qDeep_path + '/apps/dssp'
stride_path = qDeep_path + '/apps/stride'
aleigen_path = qDeep_path + '/apps/aleigen'
neff_path = qDeep_path + '/apps/calNf_ly'
pdb2rr_path = qDeep_path + '/scripts/pdb2rr.pl'
ros_script = qDeep_path + '/scripts/ros_energy.py'
class QDeep():
#------------------------constructor----------------------------#
#Initialize necessary variables #
#---------------------------------------------------------------#
def __init__(self, target):
self.target_name = target
self.seq_length = 0
#------------------------check option---------------------------#
#checks whether all args are passed #
#---------------------------------------------------------------#
def check_options(self):
if (seq_file != "" and target_name != "" and decoy_dir != "" and
aln_file != "" and pssm_file != "" and spd3_file != "" and
dist_file != "" and output_path != ""):
return True
else:
return False
#---------------------validate input files----------------------#
#checks validity of input file #
#---------------------------------------------------------------#
def contains_number(self, str):
return any(char.isdigit() for char in str)
#-------validate sequence file-----------#
#Invalid if the file does not exist
#Invalid if the file is empty
#Invalid if the sequence contains any digit
def validate_seq(self, seq_file):
if(os.path.exists(seq_file)):
f = open(seq_file, 'r')
text = f.readlines()
text = [line.strip() for line in text if not '>' in line]
seqQ = ''.join( text )
self.seq_length = len(seqQ)
if(self.seq_length > 0):
return True
else:
return False
else:
return False
#-----------validate decoy dir-----------#
#Invalid if dir not passed
#Invalid if the dir does not exist
#Invalid if the dir does not contain at least
#1 pdb file with ATOM records
#Invalid if all the pdb files are empty
def validate_dec_dir(self, decoy_dir):
valid = False
global tot_decoy
tot_decoy = 0
if(os.path.isdir(decoy_dir)):
decoys = os.listdir(decoy_dir)
for i in range(len(decoys)):
#if(decoys[i].endswith('.pdb')):
dec_res_list=[]
dec_res_no = []
with open(decoy_dir + "/" + decoys[i]) as dFile:
for line in dFile:
if(line[0:(0+4)]=="ATOM"):
dec_res_no.append(line[22:(22+4)])
dec_res_list=sorted((self.get_unique_list(dec_res_no)))
if(len(dec_res_list) > 0):
tot_decoy += 1
if(tot_decoy > 0):
valid = True
return valid
#------------validate aln----------------#
#Invalid if the file does not exist
def validate_aln(self, aln_file):
valid = False
if(os.path.exists(aln_file)):
valid = True
else:
valid = False
return valid
#--------validate distance file----------#
#Invalid if the file does not exist
def validate_dist(self, dist_file):
valid = False
if(os.path.exists(dist_file)):
valid = True
else:
valid = False
return valid
#----------validate PSSM file------------#
#Invalid if the file does not exist
#Invalid if the file is empty
#Invalid if residue line < 43
def validate_pssm(self, pssm_file):
valid = False
if(os.path.exists(pssm_file)):
with open(pssm_file) as fFile:
for line in fFile:
tmp = line.split()
if(len(tmp) > 0 and self.contains_number(tmp[0]) == True and
len(tmp) < 42):
valid = False
break
else:
valid = True
return valid
#---------validate spd33 file-----------#
#Invalid if the file does not exist
#Invalid if the file is empty
#Invalid if residue line < | > 13
def validate_spd3(self, spd3_file):
valid = False
if(os.path.exists(spd3_file)):
with open(spd3_file) as fFile:
for line in fFile:
tmp = line.split()
if(len(tmp) > 0 and self.contains_number(tmp[0]) == True):
if(len(tmp) > 13 or len(tmp) < 13):
valid = False
break
else:
valid = True
return valid
#----------------------sigmoid----------------------------------#
#purpose: scale numbers between 0 and 1 #
#parameter: number #
#---------------------------------------------------------------#
def sigmoid(self, x):
if x < 0:
return 1 - 1/(1 + math.exp(x))
else:
return 1/(1 + math.exp(-x))
#---------------------get_unique_list---------------------------#
#purpose: takes a list and return a non-redundant list #
#parameter: list #
#---------------------------------------------------------------#
def get_unique_list(self, in_list):
if isinstance(in_list,list):
return list(set(in_list))
#---------------------readFiles---------------------------------#
#purpose: reads and store all files in a dir to an array #
#parameter: directory #
#---------------------------------------------------------------#
def read_files(self, directory):
global filesInDir
filesInDir=[]
for file in os.listdir(directory):
#getOnlyFileName=os.path.splitext(file.rsplit('.', 2)[0])[0]
#if(decoys[i].endswith('.pdb')):
dec_res_list=[]
dec_res_no = []
with open(decoy_dir + "/" + file) as dFile:
for line in dFile:
if(line[0:(0+4)]=="ATOM"):
dec_res_no.append(line[22:(22+4)])
dec_res_list=sorted((self.get_unique_list(dec_res_no)))
if(len(dec_res_list) > 0):
filesInDir.append(file)
return filesInDir
#----------------------run_dssp or stride-----------------------#
#purpose: runs dssp or stride tool for generating SS and SA #
#if DSSP fails, STRIDE will run #
# #
#---------------------------------------------------------------#
def run_dssp_stride(self):
files = []
files = self.read_files(decoy_dir)
if not os.path.isdir(output_path+"/dssp"):
os.makedirs(output_path+"/dssp")
if not os.path.isdir(output_path+"/stride"):
os.makedirs(output_path+"/stride")
for i in range(len(files)):
dssp_ret_code = os.system(dssp_path +" -i " + decoy_dir + "/" + files[i] + " -o " +
output_path + "/dssp/" + os.path.splitext(files[i].rsplit('/', 1)[-1])[0] + ".dssp")
if(dssp_ret_code != 0):
print("DSSP failed to run. Running STRIDE for " + files[i])
os.system(stride_path +" " + decoy_dir + "/" + files[i] + ">" +
output_path + "/stride/" + os.path.splitext(files[i].rsplit('/', 1)[-1])[0] + ".stride")
#-----------------------get_neff--------------------------------#
#purpose: calculate NEFF #
#---------------------------------------------------------------#
def get_neff(self):
neff = 0
with open(output_path + '/neff/' + self.target_name + '.neff') as n_file:
for line in n_file:
tmp = line.split()
if(len(tmp) > 0):
x=np.array(tmp)
x=np.asfarray(x, float)
neff = sum(x) / len(x)
return neff
#------------------------get_cmo--------------------------------#
#purpose: extract the CMO value #
#---------------------------------------------------------------#
def get_cmo(self, cmo_file):
cmo = 0
count = 0
with open(cmo_file) as n_file:
for line in n_file:
tmp = line.split()
if(len(tmp) > 0 and count == 1):
cmo = float(tmp[0])
break
count += 1
return cmo
#------------------------get8to3ss------------------------------#
#purpose: converts 8 states SS to 3 states SS #
#---------------------------------------------------------------#
def get8to3ss(self, ss_parm):
eTo3=""
if (ss_parm == "H" or ss_parm == "G" or ss_parm == "I"):
eTo3="H"
elif(ss_parm == "E" or ss_parm == "B"):
eTo3="E"
else:
eTo3="C"
return eTo3
#------------------------get3to1aa------------------------------#
#purpose: converts 3 states AA to 1 states AA #
#---------------------------------------------------------------#
def get3to1aa(self, aa):
dict = {'CYS': 'C', 'ASP': 'D', 'SER': 'S', 'GLN': 'Q', 'LYS': 'K',
'ILE': 'I', 'PRO': 'P', 'THR': 'T', 'PHE': 'F', 'ASN': 'N',
'GLY': 'G', 'HIS': 'H', 'LEU': 'L', 'ARG': 'R', 'TRP': 'W',
'ALA': 'A', 'VAL':'V', 'GLU': 'E', 'TYR': 'Y', 'MET': 'M'}
return dict[aa]
#--------------------------get_rsa------------------------------#
#purpose: extracts RSA #
#---------------------------------------------------------------#
def get_rsa(self, amnAcidParam, saValParam):
saVal = 0;
aaSA=[];
aaSaVal=[];
aaSA=['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'];
aaSaVal=[115, 135, 150, 190, 210, 75, 195, 175, 200, 170, 185, 160, 145, 180, 225, 115, 140, 155, 255, 230];
k=0
while k<len(aaSA):
if(amnAcidParam==aaSA[k]):
saVal = float(saValParam) / aaSaVal[k]
break
else:
k+=1
return saVal
#----------------------gen_energy_terms-------------------------#
#purpose: generate 12 Rosetta's energy terms #
#---------------------------------------------------------------#
def gen_energy_terms(self):
files = []
files = self.read_files(decoy_dir)
if not os.path.isdir(output_path + "/rosetta"):
os.makedirs(output_path + "/rosetta")
ros_proc = subprocess.Popen('python -W ignore ' + ros_script + ' -d ' + decoy_dir +
' -o ' + output_path + "/rosetta > " + output_path + "/rosetta.log", shell=True).wait()
if(ros_proc != 0):
print('Error occurred while generating rosetta energy.\n' +
'Please check the installation')
exit()
#---------------------generate_int_map--------------------------#
#purpose: generate int map at diff thresholds #
#---------------------------------------------------------------#
def generate_int_map(self):
if not os.path.isdir(output_path + "/int_maps"):
os.makedirs(output_path + "/int_maps")
#------interaction map at threshold 6---------#
# #
#---------------------------------------------#
threshold = [6]
for i in range(len(threshold)):
#os.chdir(output_path + "/int_maps")
outFile = open(output_path + "/int_maps/" + self.target_name + "_" + str(threshold[i]) + ".rr", "w")
with open(dist_file) as cFile:
for line in cFile:
tmp = line.split()
total_prob = 0
string = ""
for t in range(threshold[i] - 2):
total_prob = total_prob + float(tmp[t + 2])
outFile.write(tmp[0] + " " + tmp[1] + " " + str(total_prob) + "\n")
outFile.close()
#os.chdir(working_path)
threshold = [8, 10, 12, 14]
for i in range(len(threshold)):
#os.chdir(output_path + "/int_maps")
outFile = open(output_path + "/int_maps/" + self.target_name + "_" + str(threshold[i]) + ".rr", "w")
with open(dist_file) as cFile:
for line in cFile:
tmp = line.split()
total_prob = 0
string = ""
for t in range(threshold[i]):
total_prob = total_prob + float(tmp[t + 2])
outFile.write(tmp[0] + " " + tmp[1] + " " + str(total_prob) + "\n")
outFile.close()
#------------------------align_map------------------------------#
#purpose: align predicted and true interaction map #
#---------------------------------------------------------------#
def align_map(self):
if not os.path.isdir(output_path + "/cmo"):
os.makedirs(output_path + "/cmo")
decoys = os.listdir(decoy_dir)
#------for 6A interact map------#
# #
#-------------------------------#
if(os.path.exists(output_path + "/int_maps/" + self.target_name + '_6.rr')):
os.system('cp ' + output_path + "/int_maps/" + self.target_name + '_6.rr ' + output_path + "/cmo")
os.chdir(output_path + "/cmo")
#step3: format the predicted interaction map
lines_pred = []
with open(self.target_name + '_6.rr') as pCon:
for line in pCon:
lines_pred.append(line)
out_file = open(self.target_name + '_6.rr', 'w')
os.chdir(working_path)
#open seq to get the number of residue#
#write the length of the sequence
#write only the first two column
os.chdir(output_path + "/cmo")
out_file.write(str(self.seq_length) + '\n')
for l in range(len(lines_pred)):
temp_l = lines_pred[l].split()
#--------change int. map threshold here---------#
# #
#-----------------------------------------------#
if(float(temp_l[2]) > 0.2):
out_file.write(str(int(temp_l[0]) -1) + ' ' + str(int(temp_l[1]) -1) + '\n')
out_file.close()
#step1: calculate int. map from the pdbs#
#decoys = os.listdir(decoy_dir)
for d in range(len(decoys)):
os.chdir(working_path)
os.system('perl ' + pdb2rr_path + ' ' + decoy_dir + '/' + decoys[d] + ' CB 5 8&> ' + output_path + "/cmo/" + decoys[d].split('.')[0] + '_true.rr')
os.chdir(output_path + "/cmo")
# step:2 format the rr file for aleigen
lines = []
with open(decoys[d].split('.')[0] + '_true.rr') as tcFile:
for line in tcFile:
lines.append(line)
#open file
final_out = open(decoys[d].split('.')[0] + '_true.rr', 'w')
count = 0
for c in range(len(lines)):
temp_con = lines[c].split()
if(count == 0):
final_out.write(str(len(temp_con[0])) + '\n')
else:
final_out.write(str(int(temp_con[0]) - 1) + ' ' + str(int(temp_con[1]) - 1) + '\n')
count += 1
final_out.close()
#step4: run aleigen
os.system(aleigen_path + ' ' + decoys[d].split('.')[0] + '_true.rr' + ' '
+ self.target_name + '_6.rr 6 &>' + decoys[d].split('.')[0] + '_6.cmo')
os.chdir(working_path)
#--------for 8A int. map--------#
# #
#-------------------------------#
#copy the predicted int. map
if(os.path.exists(output_path + "/int_maps/" + self.target_name + '_8.rr')):
os.system('cp ' + output_path + "/int_maps/" + self.target_name + '_8.rr ' + output_path + "/cmo")
os.chdir(output_path + "/cmo")
#step3: format the predicted int. map
lines_pred = []
with open(self.target_name + '_8.rr') as pCon:
for line in pCon:
lines_pred.append(line)
outFile = open(self.target_name + '_8.rr', 'w')
#open sequence file to get the number of residue#
os.chdir(working_path)
#write the length of the sequence
#write only the first two column
os.chdir(output_path + "/cmo")
outFile.write(str(self.seq_length) + '\n')
for l in range(len(lines_pred)):
temp_l = lines_pred[l].split()
#--------change int. map threshold here---------#
# #
#-----------------------------------------------#
if(float(temp_l[2]) > 0.2):
outFile.write(str(int(temp_l[0]) -1) + ' ' + str(int(temp_l[1]) -1) + '\n')
outFile.close()
#step1: calculate int. map from the pdbs#
#decoys = os.listdir(decoy_dir)
for d in range(len(decoys)):
os.chdir(working_path)
os.system('perl ' + pdb2rr_path + ' ' + decoy_dir + '/' + decoys[d] + ' CB 5 8&> ' + output_path + "/cmo/" + decoys[d].split('.')[0] + '_true.rr')
os.chdir(output_path + "/cmo")
# step:2 format the rr file for aleigen
lines = []
with open(decoys[d].split('.')[0] + '_true.rr') as tcFile:
for line in tcFile:
lines.append(line)
#open file
final_out = open(decoys[d].split('.')[0] + '_true.rr', 'w')
count = 0
for c in range(len(lines)):
temp_con = lines[c].split()
if(count == 0):
final_out.write(str(len(temp_con[0])) + '\n')
else:
final_out.write(str(int(temp_con[0]) - 1) + ' ' + str(int(temp_con[1]) - 1) + '\n')
count += 1
final_out.close()
#step4: run aleigen
os.system(aleigen_path + ' ' + decoys[d].split('.')[0] + '_true.rr' + ' '
+ self.target_name + '_8.rr 6 &>' + decoys[d].split('.')[0] + '_8.cmo')
os.chdir(working_path)
#--------for 10A int. map--------#
# #
#--------------------------------#
#copy the predicted int. map
if(os.path.exists(output_path + "/int_maps/" + self.target_name + '_10.rr')):
os.system('cp ' + output_path + "/int_maps/" + self.target_name + '_10.rr ' + output_path + "/cmo")
os.chdir(output_path + "/cmo")
#step3: format the predicted int. map
lines_pred = []
with open(self.target_name + '_10.rr') as p_con:
for line in p_con:
lines_pred.append(line)
out_file = open(self.target_name + '_10.rr', 'w')
#open seq to get the number of residue#
os.chdir(working_path)
#write the length of the sequence
#write only the first two column
os.chdir(output_path + "/cmo")
out_file.write(str(self.seq_length) + '\n')
for l in range(len(lines_pred)):
temp_l = lines_pred[l].split()
#--------change int. map threshold here---------#
# #
#-----------------------------------------------#
if(float(temp_l[2]) > 0.2):
out_file.write(str(int(temp_l[0]) -1) + ' ' + str(int(temp_l[1]) -1) + '\n')
out_file.close()
#step1: calculate int. map from the pdbs#
#decoys = os.listdir(decoy_dir)
for d in range(len(decoys)):
os.chdir(working_path)
os.system('perl ' + pdb2rr_path + ' ' + decoy_dir + '/' + decoys[d] + ' CB 5 8&> ' + output_path + "/cmo/" + decoys[d].split('.')[0] + '_true.rr')
os.chdir(output_path + "/cmo")
# step:2 format the rr file for aleigen
lines = []
with open(decoys[d].split('.')[0] + '_true.rr') as tcFile:
for line in tcFile:
lines.append(line)
#open file
final_out = open(decoys[d].split('.')[0] + '_true.rr', 'w')
count = 0
for c in range(len(lines)):
temp_con = lines[c].split()
if(count == 0):
final_out.write(str(len(temp_con[0])) + '\n')
else:
final_out.write(str(int(temp_con[0]) - 1) + ' ' + str(int(temp_con[1]) - 1) + '\n')
count += 1
final_out.close()
#step4: run aleigen
os.system(aleigen_path + ' ' + decoys[d].split('.')[0] + '_true.rr' + ' '
+ self.target_name + '_10.rr 6 &>' + decoys[d].split('.')[0] + '_10.cmo')
os.chdir(working_path)
#--------for 12A int. map--------#
# #
#--------------------------------#
#copy the predicted int. map
if(os.path.exists(output_path + "/int_maps/" + self.target_name + '_12.rr')):
os.system('cp ' + output_path + "/int_maps/" + self.target_name + '_12.rr ' + output_path + "/cmo")
os.chdir(output_path + "/cmo")
#step3: format the predicted int. map
lines_pred = []
with open(self.target_name + '_12.rr') as p_con:
for line in p_con:
lines_pred.append(line)
out_file = open(self.target_name + '_12.rr', 'w')
#open seq to get the number of residue#
os.chdir(working_path)
#write the length of the sequence
#write only the first two column
os.chdir(output_path + "/cmo")
out_file.write(str(self.seq_length) + '\n')
for l in range(len(lines_pred)):
temp_l = lines_pred[l].split()
#--------change int. map threshold here---------#
# #
#-----------------------------------------------#
if(float(temp_l[2]) > 0.2):
out_file.write(str(int(temp_l[0]) -1) + ' ' + str(int(temp_l[1]) -1) + '\n')
out_file.close()
#step1: calculate int. maps from the pdbs#
#decoys = os.listdir(decoy_dir)
for d in range(len(decoys)):
os.chdir(working_path)
os.system('perl ' + pdb2rr_path + ' ' + decoy_dir + '/' + decoys[d] + ' CB 5 8&> ' + output_path + "/cmo/" + decoys[d].split('.')[0] + '_true.rr')
os.chdir(output_path + "/cmo")
# step:2 format the rr file for aleigen
lines = []
with open(decoys[d].split('.')[0] + '_true.rr') as tc_file:
for line in tc_file:
lines.append(line)
#open file
final_out = open(decoys[d].split('.')[0] + '_true.rr', 'w')
count = 0
for c in range(len(lines)):
temp_con = lines[c].split()
if(count == 0):
final_out.write(str(len(temp_con[0])) + '\n')
else:
final_out.write(str(int(temp_con[0]) - 1) + ' ' + str(int(temp_con[1]) - 1) + '\n')
count += 1
final_out.close()
#step4: run aleigen
os.system(aleigen_path + ' ' + decoys[d].split('.')[0] + '_true.rr' + ' '
+ self.target_name + '_12.rr 6 &>' + decoys[d].split('.')[0] + '_12.cmo')
os.chdir(working_path)
#--------for 14A int. map--------#
# #
#--------------------------------#
#copy the predicted int. map
if(os.path.exists(output_path + "/int_maps/" + self.target_name + '_14.rr')):
os.system('cp ' + output_path + "/int_maps/" + self.target_name + '_14.rr ' + output_path + "/cmo")
os.chdir(output_path + "/cmo")
lines_pred = []
with open(self.target_name + '_14.rr') as p_con:
for line in p_con:
lines_pred.append(line)
out_file = open(self.target_name + '_14.rr', 'w')
#open seq to get the number of residue#
os.chdir(working_path)
#write the length of the sequence
#write only the first two column
os.chdir(output_path + "/cmo")
out_file.write(str(self.seq_length) + '\n')
for l in range(len(lines_pred)):
temp_l = lines_pred[l].split()
#--------change int_map threshold here----------#
# #
#-----------------------------------------------#
if(float(temp_l[2]) > 0.2):
out_file.write(str(int(temp_l[0]) -1) + ' ' + str(int(temp_l[1]) -1) + '\n')
out_file.close()
#step1: calculate int_map from the pdbs#
#decoys = os.listdir(decoy_dir)
for d in range(len(decoys)):
os.chdir(working_path)
os.system('perl ' + pdb2rr_path + ' ' + decoy_dir + '/' + decoys[d] + ' CB 5 8&> ' + output_path + "/cmo/" + decoys[d].split('.')[0] + '_true.rr')
os.chdir(output_path + "/cmo")
# step:2 format the rr file for aleigen
lines = []
with open(decoys[d].split('.')[0] + '_true.rr') as tc_file:
for line in tc_file:
lines.append(line)
#open file
final_out = open(decoys[d].split('.')[0] + '_true.rr', 'w')
count = 0
for c in range(len(lines)):
temp_con = lines[c].split()
if(count == 0):
final_out.write(str(len(temp_con[0])) + '\n')
else:
final_out.write(str(int(temp_con[0]) - 1) + ' ' + str(int(temp_con[1]) - 1) + '\n')
count += 1
final_out.close()
#step4: run aleigen
os.system(aleigen_path + ' ' + decoys[d].split('.')[0] + '_true.rr' + ' '
+ self.target_name + '_14.rr 6 &>' + decoys[d].split('.')[0] + '_14.cmo')
os.chdir(working_path)
#------run and process neff-------#
#input: aln #
#---------------------------------#
def generate_neff(self):
if not os.path.isdir(output_path + "/neff"):
os.makedirs(output_path + "/neff")
os.system('cp ' + aln_file + ' ' + output_path + "/neff")
os.chdir(output_path + "/neff")
os.system(neff_path + ' ' + self.target_name + '.aln 0.8&> ' + self.target_name + '.neff')
os.chdir(working_path)
#---------------------------process sliding window if used during training-------------------------#
# #
#--------------------------------------------------------------------------------------------------#
def processSlidingWindow_train_with_0(self, featureFile, targetDir, window_size):
del features[:]
del finalFeatures[:]
##reading all features to a list##
with open(featureFile) as fFile:
first_res = 1
for line in fFile:
#pad features for blanks#
#---pad feat at the beginning---#
# #
#-------------------------------#
if(first_res == 1):
feat_len = len(line.split())
#how many lines to pad? = (window_size-1)/2
for p in range(int((window_size - 1)/2)):
feat = ""
#how many features? = len of feat
for l in range(feat_len):
feat += "0 "
features.append(feat)
features.append(line.rstrip())
first_res = 0
#------pad feat at the end------#
# #
#-------------------------------#
feat_len = len(line.split())
#how many lines to pad? = window_size/2 - 1
for p in range(int((window_size - 1)/2)):
feat = ""
#how many features? = len of feat + 1 (label)
for l in range(feat_len):
feat += "0 "
features.append(feat)
start = 0
for i in range((len(features)-int(window_size))+1):
tmpFeatures=[]
tmpIndFtrs=[]
window_label=[]
label=0
##label position (middle)##
window_label=(int(window_size)/2)+1
##read till total no of window size##
for j in range (int(window_size)):
##taking all features except the label##
tmp=features[j+start].split()
tmpFeatures.append(tmp)
##determining the label (middle)##
#if(j+1==int(window_label)):
# label=tmp[-1]
start=start+1
##store individual features for concatenation##
for k in range(len(tmpFeatures)):
for l in range(len(tmpFeatures[k])):
tmpIndFtrs.append(tmpFeatures[k][l])
len(tmpIndFtrs)
finalFeatures.append(" ".join(tmpIndFtrs))
#-----write features------#
# #
#-------------------------#
featOut = open(targetDir + "/" + os.path.splitext(featureFile.rsplit('/', 1)[-1])[0] + ".window_feat", "w")
for feat in range(len(finalFeatures)):
featOut.write(finalFeatures[feat] + "\n")
featOut.close()
#-----------------------------------Step 1:process unique features---------------------------------------------#
# #
#--------------------------------------------------------------------------------------------------------------#
def generate_feature(self):
#----------get neff feat---------#
# #
#--------------------------------#
noOfEffSeq = self.get_neff()
#-------Failed decoy log---------#
# #
#--------------------------------#
global total_failed_decoy
total_failed_decoy = 0
failed_decoy = open(output_path + '/failed_decoy.log', 'w')
#check here whether all features have been generated or not#
#fetch lines from files those are common#
pssmLines = []
spd3Lines = []
if os.path.isfile(pssm_file):
with open(pssm_file) as fFile:
for line in fFile:
tmp = line.split()
if(len(tmp) > 0):
pssmLines.append(line)
if os.path.isfile(spd3_file):
with open(spd3_file) as fFile:
for line in fFile:
tmp = line.split()
if(len(tmp) > 0 and tmp[0] != "#"):
spd3Lines.append(line)
if not os.path.isdir(output_path + "/features"):
os.makedirs(output_path + "/features")
if not os.path.isdir(output_path + "/residue_list"):
os.makedirs(output_path + "/residue_list")
#---------------for each decoy---------------#
# #
#--------------------------------------------#
#read all decoys for the target
self.read_files(decoy_dir)
for d in range(len(filesInDir)): #for each decoy
outputFeat = open(output_path + "/features/" + filesInDir[d].split('.')[0] + ".feat", "w")
#--------get CMO--------#
# #
#-----------------------#
cmo_score_6 = 0
cmo_score_6 = float(self.get_cmo(output_path + '/cmo/' + filesInDir[d].split('.')[0] + '_6.cmo') * 10) / float(100)
cmo_score_8 = 0
cmo_score_8 = float(self.get_cmo(output_path + '/cmo/' + filesInDir[d].split('.')[0] + '_8.cmo') * 25) / float(100)
cmo_score_10 = 0
cmo_score_10 = float(self.get_cmo(output_path + '/cmo/' + filesInDir[d].split('.')[0] + '_10.cmo') * 30) / float(100)
cmo_score_12 = 0
cmo_score_12 = float(self.get_cmo(output_path + '/cmo/' + filesInDir[d].split('.')[0] + '_12.cmo') * 25) / float(100)
cmo_score_14 = 0
cmo_score_14 = float(self.get_cmo(output_path + '/cmo/' + filesInDir[d].split('.')[0] + '_14.cmo') * 10) / float(100)
#get residue list from the reference model
######################################get residue index#################################################
residueList=[]
tmp_residue_list = []
start_end_ResNo = [] ##
with open(decoy_dir + "/" + filesInDir[d]) as file: ##
for line in file: ##
if(line[0:(0+4)]=="ATOM"): ##
start_end_ResNo.append(line[22:(22+4)]) ##
##
residueList=sorted((self.get_unique_list(start_end_ResNo))) ##
residueList=list(map(int, residueList)) ##
######################################process each decoy file with respect to the native################
#-------residue-wise feature extraction------#
# #
#--------------------------------------------#
#--------for each residue of a decoy---------#
# #
#--------------------------------------------#
total_phi = 0
total_psi = 0
total_feat_res = 0
angular_rmsd_phi = ""
angular_rmsd_psi = ""
angular_rmsd_norm_phi = ""
angular_rmsd_norm_psi = ""
for r in range(len(residueList)):
feat_pssm = ""
feat_ss = ""
feat_sa = 0
feat_rosetta = ""
feat_mass = ""
feat_rosetta = ""
lga_label = ""
feat_max_prob = 0
#----------PSSM features--------#
# #
#-------------------------------#
for p in range(len(pssmLines)):
tmp = pssmLines[p].split()
if(len(tmp) > 20 and tmp[0] != 'A' and tmp[0] != 'K' and tmp[0] != 'Standard' and
tmp[0] != 'PSI' and tmp[0] != 'Last' and int(tmp[0]) == residueList[r]):
feat_pssm += str(self.sigmoid(float(tmp[43])))
break
#-------SA and SS features------#
# #
#-------------------------------#
#SS and SA features (for each residue, after matching with the residue, extract ss and sa)
ss=""
sa=""
aa=""
#-------Process each DSSP-------#
# #
#-------------------------------#
dsspResFound = 0
if os.path.isfile(output_path + "/dssp/" + filesInDir[d].split('.')[0] + ".dssp"):
with open(output_path + "/dssp/" + filesInDir[d].split('.')[0] + ".dssp") as fp:
line = fp.readline()
cntLn = 0 ##line counter##
residue="#"
while line: ##reading each line##
line = fp.readline()
if (cntLn<1):
if (line[2:(2+len(residue))] == residue):
cntLn+=1
continue