-
Notifications
You must be signed in to change notification settings - Fork 1
/
getf1.py
executable file
·39 lines (33 loc) · 1.36 KB
/
getf1.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
#!/usr/bin/env python3
'''Run pharmit on specified database with query'''
import argparse, sys, re, subprocess
parser = argparse.ArgumentParser(description='Run pharmit on specified database with query and report F1 score')
parser.add_argument("query",help="Query file (json) to search with")
parser.add_argument("db",help="Pharmit database to search")
parser.add_argument("--actives",default="actives_final.ism",help="Name of actives smiles file",required=False)
args = parser.parse_args()
try:
num_actives = len(open(args.actives).readlines()) # count lines
output = subprocess.check_output(f'pharmit dbsearch -dbdir {args.db} -in {args.query} -extra-info -max-orient=1 -reduceconfs=1',shell=True)
output = output.decode()
lines = output.split('\n')
hits = 0
tp = 0 # true positives
for line in lines:
vals = line.split(',') #index,rmsd, molweight, #rotbonds,name, internal stuff
if len(vals) != 7:
continue #skip other rows
hits += 1
name = vals[4]
if 'active' in name:
tp += 1
recall = tp/num_actives
if recall == 0: #avoid divide by zero
precision = 0
f1 = 0
else:
precision = tp/hits
f1 = 2*(precision*recall)/(precision+recall)
print(f'F1: {f1:5f} Recall: {recall:5f} Precision: {precision:5f}')
except:
print('error')