diff mordred_descriptors.py @ 2:d074b0c2b54f draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/chemicaltoolbox/mordred commit 7efc367809c29ff5939ea971bd00c69b7f9f5903"
author bgruening
date Wed, 06 Nov 2019 13:59:30 -0500
parents e2f40a02f31a
children
line wrap: on
line diff
--- a/mordred_descriptors.py	Tue Jun 04 10:29:10 2019 -0400
+++ b/mordred_descriptors.py	Wed Nov 06 13:59:30 2019 -0500
@@ -35,7 +35,7 @@
         return [Chem.inchi.MolFromInchi(mol, sanitize=True) for mol in mols if mol != '']
 
 
-def mordred_descriptors(mols, output, header, use_3d):
+def mordred_descriptors(mols, output, header, use_3d, smi_as_col):
     """
     Calculate Mordred descriptors and save as tabular
     """
@@ -47,6 +47,10 @@
         df.iloc[mol] = np.nan
     df = df.applymap(convert_errors_to_nan)  # remove descriptors which errored
     df = df.round(6)
+    if smi_as_col:
+        smiles = [Chem.MolToSmiles(mol) for mol in mols]
+        df['SMILES'] = smiles
+
     df.to_csv(output, na_rep='', sep='\t', index=False, header=header)  # write output
 
 
@@ -65,7 +69,11 @@
     parser.add_argument("--header", dest="header", action="store_true",
                     default=False,
                     help="Write header line.")
+
+    parser.add_argument("--smiles", dest="smiles", action="store_true",
+                    default=False,
+                    help="Add a column with compound SMILES.")
     args = parser.parse_args()
 
     mols = mol_supplier(args.infile, args.iformat)
-    mordred_descriptors(mols, args.outfile, args.header, args.use_3d)
+    mordred_descriptors(mols, args.outfile, args.header, args.use_3d, args.smiles)