Mercurial > repos > bgruening > sucos_max_score
annotate sucos.py @ 1:8eab6d2b7bdf draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit 6fa2a0294d615c9f267b766337dca0b2d3637219"
author | bgruening |
---|---|
date | Fri, 11 Oct 2019 18:25:27 -0400 |
parents | bb5365381c8f |
children | 2f110aef9b53 |
rev | line source |
---|---|
0
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/env python |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
2 """ |
bb5365381c8f
"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, |
bb5365381c8f
"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. |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
5 |
bb5365381c8f
"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. |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
9 """ |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
10 |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
13 import numpy as np |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
17 import utils |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
18 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
19 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
20 ### start function definitions ######################################### |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
21 |
bb5365381c8f
"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 |
bb5365381c8f
"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')) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
24 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
25 fmParams = {} |
bb5365381c8f
"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(): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
27 fparams = FeatMaps.FeatMapParams() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
28 fmParams[k] = fparams |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
29 |
bb5365381c8f
"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', |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
31 'Aromatic', 'Hydrophobe', 'LumpedHydrophobe') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
32 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
33 def filterFeature(f): |
bb5365381c8f
"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 |
bb5365381c8f
"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? |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
36 if not result: |
bb5365381c8f
"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()) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
38 return result |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
39 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
40 def getRawFeatures(mol): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
41 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
42 rawFeats = fdef.GetFeaturesForMol(mol) |
bb5365381c8f
"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 |
bb5365381c8f
"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)) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
45 return filtered |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
46 |
bb5365381c8f
"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): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
48 """ |
bb5365381c8f
"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. |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
50 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
51 :param small_feats: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
52 :param large_feats: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
53 :param tani: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
54 :return: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
55 """ |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
56 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
57 featLists = [] |
bb5365381c8f
"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]: |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
60 featLists.append(rawFeats) |
bb5365381c8f
"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] |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
62 # set the score mode |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
64 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
65 try: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
66 if tani: |
bb5365381c8f
"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]) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
68 A = fms[0].GetNumFeatures() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
69 B = len(featLists[1]) |
bb5365381c8f
"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(): |
bb5365381c8f
"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...?!") |
bb5365381c8f
"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) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
73 return tani_score |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
74 else: |
bb5365381c8f
"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])) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
76 return fm_score |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
77 except ZeroDivisionError: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
78 utils.log("ZeroDivisionError") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
79 return 0 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
80 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
81 if tani: |
bb5365381c8f
"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) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
83 return tani_score |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
84 else: |
bb5365381c8f
"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])) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
86 return fm_score |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
87 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
88 |
bb5365381c8f
"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): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
90 """ |
bb5365381c8f
"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. |
bb5365381c8f
"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 |
bb5365381c8f
"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. |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
94 |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"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 |
bb5365381c8f
"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. |
bb5365381c8f
"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. |
bb5365381c8f
"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, |
bb5365381c8f
"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 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
102 """ |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
103 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
104 if not ref_features: |
bb5365381c8f
"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) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
106 if not query_features: |
bb5365381c8f
"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) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
108 |
bb5365381c8f
"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) |
bb5365381c8f
"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) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
111 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
112 if tani: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
113 tani_sim = 1 - float(rdShapeHelpers.ShapeTanimotoDist(ref_mol, query_mol)) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
114 tani_sim = np.clip(tani_sim, 0, 1) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
115 SuCOS_score = 0.5*fm_score + 0.5*tani_sim |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
116 return SuCOS_score, fm_score, tani_sim |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
117 else: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
118 protrude_dist = rdShapeHelpers.ShapeProtrudeDist(ref_mol, query_mol, allowReordering=False) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
119 protrude_dist = np.clip(protrude_dist, 0, 1) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
120 protrude_val = 1.0 - protrude_dist |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
121 SuCOS_score = 0.5 * fm_score + 0.5 * protrude_val |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
122 return SuCOS_score, fm_score, protrude_val |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
123 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
124 def process(refmol_filename, inputs_filename, outputs_filename, refmol_index=None, |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
125 refmol_format=None, tani=False, score_mode=FeatMaps.FeatMapScoreMode.All): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
126 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
127 ref_mol = utils.read_single_molecule(refmol_filename, index=refmol_index, format=refmol_format) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
128 #utils.log("Reference mol has", ref_mol.GetNumHeavyAtoms(), "heavy atoms") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
129 ref_features = getRawFeatures(ref_mol) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
130 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
131 input_file = utils.open_file_for_reading(inputs_filename) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
132 suppl = Chem.ForwardSDMolSupplier(input_file) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
133 output_file = utils.open_file_for_writing(outputs_filename) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
134 writer = Chem.SDWriter(output_file) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
135 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
136 count = 0 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
137 total = 0 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
138 errors = 0 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
139 for mol in suppl: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
140 count +=1 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
141 if mol is None: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
142 continue |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
143 #utils.log("Mol has", str(mol.GetNumHeavyAtoms()), "heavy atoms") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
144 try: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
145 sucos_score, fm_score, val3 = get_SucosScore(ref_mol, mol, tani=tani, ref_features=ref_features, score_mode=score_mode) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
146 mol.SetDoubleProp("SuCOS_Score", sucos_score) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
147 mol.SetDoubleProp("SuCOS_FeatureMap_Score", fm_score) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
148 if tani: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
149 mol.SetDoubleProp("SuCOS_Tanimoto_Score", val3) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
150 else: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
151 mol.SetDoubleProp("SuCOS_Protrude_Score", val3) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
152 utils.log("Scores:", sucos_score, fm_score, val3) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
153 writer.write(mol) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
154 total +=1 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
155 except ValueError as e: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
156 errors +=1 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
157 utils.log("Molecule", count, "failed to score:", e.message) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
158 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
159 input_file.close() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
160 writer.flush() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
161 writer.close() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
162 output_file.close() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
163 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
164 utils.log("Completed.", total, "processed, ", count, "succeeded, ", errors, "errors") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
165 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
166 def parse_score_mode(value): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
167 if value == None or value == 'all': |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
168 return FeatMaps.FeatMapScoreMode.All |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
169 elif value == 'closest': |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
170 return FeatMaps.FeatMapScoreMode.Closest |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
171 elif value == 'best': |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
172 return FeatMaps.FeatMapScoreMode.Best |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
173 else: |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
174 raise ValueError(value + " is not a valid scoring mode option") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
175 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
176 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
177 ### start main execution ######################################### |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
178 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
179 def main(): |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
180 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
181 parser = argparse.ArgumentParser(description='SuCOS with RDKit') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
182 parser.add_argument('-i', '--input', help='Input file in SDF format. Can be gzipped (*.gz).') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
183 parser.add_argument('-r', '--refmol', help='Molecule to compare against in Molfile (.mol) or SDF (.sdf) format') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
184 parser.add_argument('--refmol-format', help="Format for the reference molecule (mol or sdf). " + |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
185 "Only needed if files don't have the expected extensions") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
186 parser.add_argument('--refmolidx', help='Reference molecule index in SD file if not the first', type=int, default=1) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
187 parser.add_argument('-o', '--output', help='Output file in SDF format. Can be gzipped (*.gz).') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
188 parser.add_argument('--tanimoto', action='store_true', help='Include Tanimoto distance in score') |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
189 parser.add_argument('--score_mode', choices=['all', 'closest', 'best'], |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
190 help="choose the scoring mode for the feature map, default is 'all'.") |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
191 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
192 args = parser.parse_args() |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
193 utils.log("SuCOS Args: ", args) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
194 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
195 score_mode = parse_score_mode(args.score_mode) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
196 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
197 process(args.refmol, args.input, args.output, refmol_index=args.refmolidx, |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
198 refmol_format=args.refmol_format, tani=args.tanimoto, score_mode=score_mode) |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
199 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
200 |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
201 if __name__ == "__main__": |
bb5365381c8f
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/sucos commit ef86cfa5f7ab5043de420511211579d03df58645"
bgruening
parents:
diff
changeset
|
202 main() |