-
Notifications
You must be signed in to change notification settings - Fork 4
/
Multi-target-drug-screening-analysis.py
116 lines (116 loc) · 3.9 KB
/
Multi-target-drug-screening-analysis.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
import os
import re
from collections import Counter
path = "./"
rule = re.compile('^[a-z]{1}.*$')
Dividing_line = "-*" * 15
def finder(pattern, root='.'):
matches = []
dirs = []
for x in os.listdir(root):
nd = os.path.join(root, x)
if os.path.isdir(nd):
dirs.append(nd)
elif os.path.isfile(nd) and pattern in x:
matches.append(nd)
for match in matches:
print(match)
for dir in dirs:
finder(pattern, root=dir)
return matches
log_file = finder('log_',root =path )
print(log_file)
print(type(log_file))
f_n = len(log_file)
f_i = 0
m_list = open("mul_target_result.txt", "w+")
m_list.write("\n" + Dividing_line + 'score < -6 result' + Dividing_line + "\n")
while f_i < f_n:
logname = log_file[f_i]
log_result = str(logname)[6:] + ".txt"
f = open(str(log_result), "w")
d = {}
result_list = []
f.write("\n" + Dividing_line + "auto-dock-vina-score-result" + Dividing_line + "\n")
for line in open(logname):
if line.startswith('Processing ligand'):
mol = line.split()[2]
mol_name = mol.strip()
print(mol_name, end=" ")
f.write(mol_name)
elif line.startswith('WARNING: Check that it is large enough'):
print("0")
f.write(" 0")
f.write('\n')
d[mol_name] = int(0)
elif line.startswith('Parse error'):
print("0")
f.write(" 0")
f.write('\n')
d[mol_name] = int(0)
elif line.startswith('! 1'):
score = (line[5:14])
print(score)
f.write(" " + score)
f.write('\n')
d[mol_name] = float(score.strip())
elif line.startswith('An internal error'):
print("0")
f.write(" 0")
f.write('\n')
d[mol_name] = int(0)
elif line.startswith('terminate called '):
print("0")
f.write(" 0")
f.write('\n')
d[mol_name] = int(0)
d_order = sorted(d.items(), key=lambda x: x[1], reverse=False)
f.write("\n" + Dividing_line + 'score < -6 result' + Dividing_line + "\n")
print("\n" + Dividing_line + 'score < -6 result' + Dividing_line + "\n")
v = dict(d_order)
for sorted_mol_name in v.keys():
if d[sorted_mol_name] < -6.5:
f.write("\n")
f.write(str(sorted_mol_name))
result_list.append(sorted_mol_name)
print(sorted_mol_name)
print("\n" + Dividing_line + 'score < -8 result' + Dividing_line + "\n")
f.write("\n" + Dividing_line + 'score < -8 result' + Dividing_line + "\n")
v = dict(d_order[:100])
for sorted_mol_name in v.keys():
if d[sorted_mol_name] < -8:
f.write("\n")
f.write(str(sorted_mol_name))
print(sorted_mol_name)
print(v[sorted_mol_name])
f.write('\n')
f.write(str(v))
f.close()
print("\n")
f_i += 1
m_list.write(str(logname)[6:] + "\n")
m_list.write(str(result_list) + "\n")
Multi_target_result = []
m_result = open("mul_target_result.txt")
for line in m_result:
if rule.match(line) :
pass
else:
mol_name = line.split(",")
num = len(mol_name)
i = 0
while i < num:
mol = mol_name[i]
#mol = ''.join(filter(str.isalnum, mol))
Multi_target_result.append(mol)
i += 1
print(len(Multi_target_result))
Counting_result = Counter(Multi_target_result)
m_list.write("\n"+ Dividing_line + "Multi-target statistical results" +Dividing_line +"\n")
print(Counting_result)
Counting_list = Counting_result.most_common(len(Counting_result))
for fda_name in Counting_list[:10]:
print(fda_name)
m_list.write(str(fda_name) + "\n")
m_list.close()
print("finish")