annotate rdkit_descriptors.py @ 9:0993ac4f4a23 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
author bgruening
date Sat, 04 Dec 2021 16:40:00 +0000
parents a1c53f0533b0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
2
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
3 import argparse
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
4 import inspect
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
5 import sys
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
6
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
7 from rdkit import Chem
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
8 from rdkit.Chem import Descriptors
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
9
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
10
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
11 def get_supplier(infile, format="smiles"):
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
12 """
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
13 Returns a generator over a SMILES or InChI file. Every element is of RDKit
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
14 molecule and has its original string as _Name property.
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
15 """
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
16 with open(infile) as handle:
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
17 for line in handle:
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
18 line = line.strip()
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
19 if format == "smiles":
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
20 mol = Chem.MolFromSmiles(line, sanitize=True)
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
21 elif format == "inchi":
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
22 mol = Chem.inchi.MolFromInchi(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
23 line,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
24 sanitize=True,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
25 removeHs=True,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
26 logLevel=None,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
27 treatWarningAsError=False,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
28 )
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
29 if mol is None:
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
30 yield False
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
31 else:
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
32 mol.SetProp("_Name", line.split("\t")[0])
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
33 yield mol
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
34
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
35
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
36 def get_rdkit_descriptor_functions():
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
37 """
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
38 Returns all descriptor functions under the Chem.Descriptors Module as tuple of (name, function)
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
39 """
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
40 ret = [
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
41 (name, f)
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
42 for name, f in inspect.getmembers(Descriptors)
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
43 if inspect.isfunction(f) and not name.startswith("_")
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
44 ]
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
45 # some which are not in the official Descriptors module we need to add manually
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
46 ret.extend([("FormalCharge", Chem.GetFormalCharge), ("SSSR", Chem.GetSSSR)])
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
47 ret.sort()
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
48 return ret
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
49
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
50
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
51 def descriptors(mol, functions):
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
52 """
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
53 Calculates the descriptors of a given molecule.
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
54 """
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
55 for name, function in functions:
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
56 yield (name, function(mol))
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
57
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
58
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
59 if __name__ == "__main__":
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
60 parser = argparse.ArgumentParser()
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
61 parser.add_argument("-i", "--infile", required=True, help="Path to the input file.")
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
62 parser.add_argument("--iformat", help="Specify the input file format.")
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
63
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
64 parser.add_argument(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
65 "-o",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
66 "--outfile",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
67 type=argparse.FileType("w+"),
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
68 default=sys.stdout,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
69 help="path to the result file, default is stdout",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
70 )
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
71
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
72 parser.add_argument(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
73 "-s",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
74 "--select",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
75 default=None,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
76 help="select a subset of comma-separated descriptors to use",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
77 )
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
78
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
79 parser.add_argument(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
80 "--header",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
81 dest="header",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
82 action="store_true",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
83 default=False,
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
84 help="Write header line.",
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
85 )
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
86
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
87 args = parser.parse_args()
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
88
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
89 if args.iformat == "sdf":
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
90 supplier = Chem.SDMolSupplier(args.infile)
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
91 elif args.iformat == "smi":
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
92 supplier = get_supplier(args.infile, format="smiles")
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
93 elif args.iformat == "inchi":
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
94 supplier = get_supplier(args.infile, format="inchi")
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
95 elif args.iformat == "pdb":
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
96 supplier = [Chem.MolFromPDBFile(args.infile)]
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
97 elif args.iformat == "mol2":
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
98 supplier = [Chem.MolFromMol2File(args.infile)]
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
99
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
100 functions = get_rdkit_descriptor_functions()
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
101 if args.select and args.select != "None":
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
102 selected = args.select.split(",")
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
103 functions = [(name, f) for name, f in functions if name in selected]
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
104
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
105 if args.header:
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
106 args.outfile.write(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
107 "%s\n" % "\t".join(["MoleculeID"] + [name for name, f in functions])
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
108 )
0
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
109
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
110 for mol in supplier:
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
111 if not mol:
749cc765636b planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit ed9b6859de648aa5f7cde483732f5df20aaff90e
bgruening
parents:
diff changeset
112 continue
8
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
113 descs = descriptors(mol, functions)
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
114 try:
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
115 molecule_id = mol.GetProp("_Name")
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
116 except KeyError:
a1c53f0533b0 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit 4d0bfcf37bfbedafc7ff0672dfe452766ca8a606"
bgruening
parents: 2
diff changeset
117 molecule_id = Chem.MolToSmiles(mol)
9
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
118 args.outfile.write(
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
119 "%s\n"
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
120 % "\t".join([molecule_id] + [str(round(res, 6)) for name, res in descs])
0993ac4f4a23 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/rdkit commit c1d813d3f0fec60ea6efe8a11e59d98bfdc1636f"
bgruening
parents: 8
diff changeset
121 )