-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfingerprint_obabel_comp.py
69 lines (53 loc) · 1.65 KB
/
fingerprint_obabel_comp.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
import os
import stat
import subprocess
file_type = '.sdf'
similarity_threshold = 0.82
fp_type = 'MACCS'
#fp_type = 'fFP2'
template_dir = os.getcwd() + '/template/'
cpd_dir = os.getcwd() + '/cpds/'
templates = []
for file in os.listdir(template_dir):
if file_type in file:
templates.append(template_dir + file)
templates.sort()
cpds = []
for file in os.listdir(cpd_dir):
if file_type in file:
cpds.append(cpd_dir + file)
cpds.sort()
out_csv = open('output' + fp_type + '.csv','w')
header = ' ,'
for inputcpd in cpds:
cpd_name = os.path.basename(inputcpd)
cpd_name = cpd_name[:-4]
header = header + cpd_name + ','
header=header[:-1]
out_csv.write(header + '\n')
outfile = open('outfile_' + fp_type + '.res','w')
outfile.write('HIGH SIMILARITY DETECTED FOR THE FOLLOWING COMBINATIONS:' + '\n')
for template in templates:
print(template)
temp_base = os.path.basename(template)
csv_string_per_temp = temp_base[:-4] + ','
print(csv_string_per_temp)
for cpd in cpds:
cpd_base = os.path.basename(cpd)
cpd_base = cpd_base[:-4]
command = "obabel " + template + " " + cpd + " -ofpt -x" + fp_type
print(command)
p = subprocess.Popen(command, shell=True, bufsize=0, stdout=subprocess.PIPE, universal_newlines=True)
p.wait()
output = p.stdout.read()
for element in output.split('\n'):
if '=' in element:
es = element.split('=')
value = es[1].strip()
print(value)
csv_string_per_temp = csv_string_per_temp + str(value) + ','
if float(value) >= similarity_threshold:
outfile.write(temp_base[:-4] + ' vs ' + cpd_base + ' ' + str(value) + '\n')
#print(output)
p.stdout.close()
out_csv.write(csv_string_per_temp + '\n')