annotate sucos.py @ 2:8161c08627bf draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
author bgruening
date Thu, 19 Mar 2020 07:13:36 -0400
parents f8f53668d5a2
children 4f1896782f7c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
2 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
3 Basic SuCOS scoring. Allows a set of molecules from a SD file to be overlayed to a reference molecule,
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
4 with the resulting scores being written as properties in the output SD file.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
5
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
6 SuCOS is the work of Susan Leung.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
7 GitHub: https://github.com/susanhleung/SuCOS
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
8 Publication: https://doi.org/10.26434/chemrxiv.8100203.v1
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
9 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
10
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
11 from __future__ import print_function
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
12 import argparse, os, sys, gzip
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
13 import numpy as np
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
14 from rdkit import Chem, rdBase, RDConfig
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
15 from rdkit.Chem import AllChem, rdShapeHelpers
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
16 from rdkit.Chem.FeatMaps import FeatMaps
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
17 import utils
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
18
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
19
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
20 ### start function definitions #########################################
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
21
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
22 # Setting up the features to use in FeatureMap
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
23 fdef = AllChem.BuildFeatureFactory(os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef'))
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
24
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
25 fmParams = {}
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
26 for k in fdef.GetFeatureFamilies():
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
27 fparams = FeatMaps.FeatMapParams()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
28 fmParams[k] = fparams
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
29
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
30 keep = ('Donor', 'Acceptor', 'NegIonizable', 'PosIonizable', 'ZnBinder',
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
31 'Aromatic', 'Hydrophobe', 'LumpedHydrophobe')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
32
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
33 def filterFeature(f):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
34 result = f.GetFamily() in keep
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
35 # TODO - nothing ever seems to be filtered. Is this expected?
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
36 if not result:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
37 utils.log("Filtered out feature type", f.GetFamily())
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
38 return result
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
39
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
40 def getRawFeatures(mol):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
41
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
42 rawFeats = fdef.GetFeaturesForMol(mol)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
43 # filter that list down to only include the ones we're interested in
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
44 filtered = list(filter(filterFeature, rawFeats))
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
45 return filtered
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
46
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
47 def get_FeatureMapScore(small_feats, large_feats, tani=False, score_mode=FeatMaps.FeatMapScoreMode.All):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
48 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
49 Generate the feature map score.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
50
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
51 :param small_feats:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
52 :param large_feats:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
53 :param tani:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
54 :return:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
55 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
56
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
57 featLists = []
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
58 for rawFeats in [small_feats, large_feats]:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
59 # filter that list down to only include the ones we're interested in
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
60 featLists.append(rawFeats)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
61 fms = [FeatMaps.FeatMap(feats=x, weights=[1] * len(x), params=fmParams) for x in featLists]
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
62 # set the score mode
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
63 fms[0].scoreMode = score_mode
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
64
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
65 try:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
66 if tani:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
67 c = fms[0].ScoreFeats(featLists[1])
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
68 A = fms[0].GetNumFeatures()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
69 B = len(featLists[1])
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
70 if B != fms[1].GetNumFeatures():
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
71 utils.log("Why isn't B equal to number of features...?!")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
72 tani_score = float(c) / (A+B-c)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
73 return tani_score
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
74 else:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
75 fm_score = fms[0].ScoreFeats(featLists[1]) / min(fms[0].GetNumFeatures(), len(featLists[1]))
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
76 return fm_score
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
77 except ZeroDivisionError:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
78 utils.log("ZeroDivisionError")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
79 return 0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
80
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
81 if tani:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
82 tani_score = float(c) / (A+B-c)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
83 return tani_score
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
84 else:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
85 fm_score = fms[0].ScoreFeats(featLists[1]) / min(fms[0].GetNumFeatures(), len(featLists[1]))
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
86 return fm_score
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
87
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
88
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
89 def get_SucosScore(ref_mol, query_mol, tani=False, ref_features=None, query_features=None, score_mode=FeatMaps.FeatMapScoreMode.All):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
90 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
91 This is the key function that calculates the SuCOS scores and is expected to be called from other modules.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
92 To improve performance you can pre-calculate the features and pass them in as optional parameters to avoid having
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
93 to recalculate them. Use the getRawFeatures function to pre-calculate the features.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
94
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
95 :param ref_mol: The reference molecule to compare to
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
96 :param query_mol: The molecule to align to the reference
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
97 :param tani: Whether to calculate Tanimoto distances
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
98 :param ref_features: An optional feature map for the reference molecule, avoiding the need to re-calculate it.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
99 :param query_features: An optional feature map for the query molecule, avoiding the need to re-calculate it.
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
100 :return: A tuple of 3 values. 1 the sucos score, 2 the feature map score,
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
101 3 the Tanimoto distance or 1 minus the protrude distance
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
102 """
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
103
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
104 if not ref_features:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
105 ref_features = getRawFeatures(ref_mol)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
106 if not query_features:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
107 query_features = getRawFeatures(query_mol)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
108
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
109 fm_score = get_FeatureMapScore(ref_features, query_features, tani, score_mode)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
110 fm_score = np.clip(fm_score, 0, 1)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
111
2
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
112 try :
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
113 if tani:
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
114 tani_sim = 1 - float(rdShapeHelpers.ShapeTanimotoDist(ref_mol, query_mol))
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
115 tani_sim = np.clip(tani_sim, 0, 1)
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
116 SuCOS_score = 0.5*fm_score + 0.5*tani_sim
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
117 return SuCOS_score, fm_score, tani_sim
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
118 else:
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
119 protrude_dist = rdShapeHelpers.ShapeProtrudeDist(ref_mol, query_mol, allowReordering=False)
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
120 protrude_dist = np.clip(protrude_dist, 0, 1)
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
121 protrude_val = 1.0 - protrude_dist
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
122 SuCOS_score = 0.5 * fm_score + 0.5 * protrude_val
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
123 return SuCOS_score, fm_score, protrude_val
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
124 except:
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
125 utils.log("Failed to calculate SuCOS scores. Returning 0,0,0")
8161c08627bf "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6f1ee2812cca091561a2b2e464498dae2f913b8d"
bgruening
parents: 0
diff changeset
126 return 0, 0, 0
0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
127
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
128 def process(refmol_filename, inputs_filename, outputs_filename, refmol_index=None,
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
129 refmol_format=None, tani=False, score_mode=FeatMaps.FeatMapScoreMode.All):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
130
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
131 ref_mol = utils.read_single_molecule(refmol_filename, index=refmol_index, format=refmol_format)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
132 #utils.log("Reference mol has", ref_mol.GetNumHeavyAtoms(), "heavy atoms")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
133 ref_features = getRawFeatures(ref_mol)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
134
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
135 input_file = utils.open_file_for_reading(inputs_filename)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
136 suppl = Chem.ForwardSDMolSupplier(input_file)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
137 output_file = utils.open_file_for_writing(outputs_filename)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
138 writer = Chem.SDWriter(output_file)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
139
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
140 count = 0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
141 total = 0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
142 errors = 0
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
143 for mol in suppl:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
144 count +=1
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
145 if mol is None:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
146 continue
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
147 #utils.log("Mol has", str(mol.GetNumHeavyAtoms()), "heavy atoms")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
148 try:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
149 sucos_score, fm_score, val3 = get_SucosScore(ref_mol, mol, tani=tani, ref_features=ref_features, score_mode=score_mode)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
150 mol.SetDoubleProp("SuCOS_Score", sucos_score)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
151 mol.SetDoubleProp("SuCOS_FeatureMap_Score", fm_score)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
152 if tani:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
153 mol.SetDoubleProp("SuCOS_Tanimoto_Score", val3)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
154 else:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
155 mol.SetDoubleProp("SuCOS_Protrude_Score", val3)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
156 utils.log("Scores:", sucos_score, fm_score, val3)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
157 writer.write(mol)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
158 total +=1
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
159 except ValueError as e:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
160 errors +=1
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
161 utils.log("Molecule", count, "failed to score:", e.message)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
162
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
163 input_file.close()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
164 writer.flush()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
165 writer.close()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
166 output_file.close()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
167
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
168 utils.log("Completed.", total, "processed, ", count, "succeeded, ", errors, "errors")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
169
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
170 def parse_score_mode(value):
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
171 if value == None or value == 'all':
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
172 return FeatMaps.FeatMapScoreMode.All
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
173 elif value == 'closest':
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
174 return FeatMaps.FeatMapScoreMode.Closest
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
175 elif value == 'best':
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
176 return FeatMaps.FeatMapScoreMode.Best
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
177 else:
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
178 raise ValueError(value + " is not a valid scoring mode option")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
179
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
180
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
181 ### start main execution #########################################
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
182
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
183 def main():
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
184
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
185 parser = argparse.ArgumentParser(description='SuCOS with RDKit')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
186 parser.add_argument('-i', '--input', help='Input file in SDF format. Can be gzipped (*.gz).')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
187 parser.add_argument('-r', '--refmol', help='Molecule to compare against in Molfile (.mol) or SDF (.sdf) format')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
188 parser.add_argument('--refmol-format', help="Format for the reference molecule (mol or sdf). " +
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
189 "Only needed if files don't have the expected extensions")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
190 parser.add_argument('--refmolidx', help='Reference molecule index in SD file if not the first', type=int, default=1)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
191 parser.add_argument('-o', '--output', help='Output file in SDF format. Can be gzipped (*.gz).')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
192 parser.add_argument('--tanimoto', action='store_true', help='Include Tanimoto distance in score')
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
193 parser.add_argument('--score_mode', choices=['all', 'closest', 'best'],
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
194 help="choose the scoring mode for the feature map, default is 'all'.")
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
195
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
196 args = parser.parse_args()
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
197 utils.log("SuCOS Args: ", args)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
198
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
199 score_mode = parse_score_mode(args.score_mode)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
200
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
201 process(args.refmol, args.input, args.output, refmol_index=args.refmolidx,
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
202 refmol_format=args.refmol_format, tani=args.tanimoto, score_mode=score_mode)
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
203
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
204
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
205 if __name__ == "__main__":
f8f53668d5a2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff changeset
206 main()