-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract_sdfscore2csv.py
42 lines (32 loc) · 1.08 KB
/
extract_sdfscore2csv.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
#!/usr/bin/env python
from rdkit.Chem import PandasTools
from rdkit import RDConfig
import pandas as pd
import numpy as np
from sklearn import metrics
import os,sys,string
if len(sys.argv) != 5:
print("")
print("usage: ")
print(sys.argv[0]," <input sdf file> <output csv file> <Score header> <agg method for score: min or max>")
print("For example:")
print(sys.argv[0],"active_fred_dock.sdf active_fred_score.csv min")
print("Any question, Please feel free to contact me. [email protected]")
sys.exit()
sdf_file = sys.argv[1]
if not os.path.exists(sdf_file):
#message = "Sorry, I cannot find the "%s" file."
print("Sorry, Cannot find the %s file" % sdf_file)
sys.exit()
ofile = sys.argv[2]
score_head = sys.argv[3]
agg_method = sys.argv[4]
df = PandasTools.LoadSDF(sdf_file,smilesName='SMILES',molColName='Molecule', includeFingerprints=True)
df[score_head] = df[score_head].astype(float)
df_grouped = df.groupby('Title')
vs_score = df_grouped.agg({
'Title':'first',
'label':'first',
score_head : agg_method,
})
vs_score.to_csv(ofile,index=False)