changeset 0:6bb56f3a8de0 draft default tip

Uploaded
author bgruening
date Thu, 15 Aug 2013 03:35:10 -0400
parents
children
files rdkit_descriptors.py rdkit_descriptors.xml repository_dependencies.xml tool_dependencies.xml
diffstat 4 files changed, 230 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdkit_descriptors.py	Thu Aug 15 03:35:10 2013 -0400
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+
+from rdkit.Chem import Descriptors
+from rdkit import Chem
+import sys, os, re
+import argparse
+import inspect
+
+def get_supplier( infile, format = 'smiles' ):
+    """
+    Returns a generator over a SMILES or InChI file. Every element is of RDKit 
+    molecule and has its original string as _Name property.
+    """
+    with open(infile) as handle:
+        for line in handle:
+            line = line.strip()
+            if format == 'smiles':
+                mol = Chem.MolFromSmiles( line, sanitize=True )
+            elif format == 'inchi':
+                mol = Chem.inchi.MolFromInchi( line, sanitize=True, removeHs=True, logLevel=None, treatWarningAsError=False )
+            if mol is None:
+                yield False
+            else:
+                mol.SetProp( '_Name', line.split('\t')[0] )
+                yield mol
+
+
+def get_rdkit_descriptor_functions():
+    """
+    Returns all descriptor functions under the Chem.Descriptors Module as tuple of (name, function)
+    """
+    ret = [ (name, f) for name, f in inspect.getmembers( Descriptors ) if inspect.isfunction( f ) and not name.startswith( '_' ) ]
+    ret.sort()
+    return ret
+
+
+def descriptors( mol, functions ):
+    """
+    Calculates the descriptors of a given molecule.
+    """
+    for name, function in functions:
+        yield (name, function( mol ))
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-i', '--infile', required=True, help='Path to the input file.')
+    parser.add_argument("--iformat", help="Specify the input file format.")
+
+    parser.add_argument('-o', '--outfile', type=argparse.FileType('w+'), 
+        default=sys.stdout, help="path to the result file, default it sdtout")
+
+    parser.add_argument("--header", dest="header", action="store_true",
+                    default=False,
+                    help="Write header line.")
+
+    args = parser.parse_args()
+
+    if args.iformat == 'sdf':
+        supplier = Chem.SDMolSupplier( args.infile )
+    elif args.iformat =='smi':
+        supplier = get_supplier( args.infile, format = 'smiles' )
+    elif args.iformat == 'inchi':
+        supplier = get_supplier( args.infile, format = 'inchi' )
+
+    functions = get_rdkit_descriptor_functions()
+
+    if args.header:
+        args.outfile.write( '%s\n' % '\t'.join( [name for name, f in functions] ) )
+
+    for mol in supplier:
+        if not mol:
+            continue
+        descs = descriptors( mol, functions )
+        molecule_id = mol.GetProp("_Name")
+        args.outfile.write( "%s\n" % '\t'.join( [molecule_id]+ [str(res) for name, res in descs] ) )
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rdkit_descriptors.xml	Thu Aug 15 03:35:10 2013 -0400
@@ -0,0 +1,143 @@
+<tool id="ctb_rdkit_describtors" name="Descriptors" version="0.1">
+    <description>calculated with RDKit</description>
+    <parallelism method="multi" split_inputs="infile" split_mode="to_size" split_size="10000" shared_inputs="" merge_outputs="outfile"></parallelism>
+    <requirements>
+        <requirement type="package" version="2012_12_1">rdkit</requirement>
+    </requirements>
+    <command interpreter="python">rdkit_descriptors.py -i "${infile}" --iformat "${infile.ext}" -o "${outfile}" $header 2>&#38;1</command>
+    <inputs>
+        <param format="smi,sdf" name="infile" type="data" label="Molecule data in SD- or SMILES-format" help="Dataset missing? See TIP below"/>
+        <param name="header" type="boolean" label="Include the descriptor name as header" truevalue="--header" falsevalue="" checked="false" />
+    </inputs>
+    <outputs>
+        <data format="tabular" name="outfile" />
+    </outputs>
+    <tests>
+    </tests>
+    <help>
+
+.. class:: infomark
+
+**What this tool does** 
+
+| RDKit is an open source toolkit for cheminformatics and machine learning.
+| This implementation focuses on descriptor calculation, though, RDKit offers a vast number of other functions.
+| 
+| The table below shows a brief overview of the descriptors.
+| 
+
++-----------------------------------+------------+
+|    Descriptor/Descriptor Family   |  Language  | 
++===================================+============+ 
+| Gasteiger/Marsili Partial Charges |     C++    |
++-----------------------------------+------------+
+|            BalabanJ               |   Python   |
++-----------------------------------+------------+
+|             BertzCT               |   Python   |
++-----------------------------------+------------+
+|               Ipc                 |   Python   |
++-----------------------------------+------------+
+|          HallKierAlpha            |   Python   |
++-----------------------------------+------------+
+|         Kappa1 - Kappa3           |   Python   |
++-----------------------------------+------------+
+|            Chi0, Chi1             |   Python   |
++-----------------------------------+------------+
+|           Chi0n - Chi4n           |   Python   |
++-----------------------------------+------------+
+|           Chi0v - Chi4v           |   Python   |
++-----------------------------------+------------+
+|              MolLogP              |     C++    |
++-----------------------------------+------------+
+|               MolMR               |     C++    |
++-----------------------------------+------------+
+|               MolWt               |     C++    |
++-----------------------------------+------------+
+|           HeavyAtomCount          |   Python   |
++-----------------------------------+------------+
+|           HeavyAtomMolWt          |   Python   |
++-----------------------------------+------------+
+|             NHOHCount             |     C++    |
++-----------------------------------+------------+
+|              NOCount              |     C++    |
++-----------------------------------+------------+
+|            NumHAcceptors          |     C++    |
++-----------------------------------+------------+
+|             NumHDonors            |     C++    |
++-----------------------------------+------------+
+|            NumHeteroatoms         |     C++    |
++-----------------------------------+------------+
+|          NumRotatableBonds        |     C++    |
++-----------------------------------+------------+
+|         NumValenceElectrons       |   Python   |
++-----------------------------------+------------+
+|              RingCount            |     C++    |
++-----------------------------------+------------+
+|                 TPSA              |     C++    |
++-----------------------------------+------------+
+|              LabuteASA            |     C++    |
++-----------------------------------+------------+
+|       PEOE_VSA1 - PEOE_VSA14      | Python/C++ |
++-----------------------------------+------------+
+|         SMR_VSA1 - SMR_VSA10      | Python/C++ |
++-----------------------------------+------------+
+|      SlogP_VSA1 - SlogP_VSA12     | Python/C++ |
++-----------------------------------+------------+
+|     EState_VSA1 - EState_VSA11    |   Python   |
++-----------------------------------+------------+
+|     VSA_EState1 - VSA_EState10    |   Python   |
++-----------------------------------+------------+
+|           Topliss fragments       |   Python   |
++-----------------------------------+------------+
+
+| 
+| A full list of the descriptors can be obtained here_.
+
+.. _here: https://code.google.com/p/rdkit/wiki/DescriptorsInTheRDKit
+
+-----
+
+.. class:: warningmark
+
+**HINT**
+
+Use the **cut columns from a table** tool to select just the desired descriptors.
+
+-----
+
+.. class:: infomark
+
+**Input**
+
+| - `SD-Format`_
+| - `SMILES Format`_
+| - TDT_
+| - SLN
+| - `Corina MOL2`_
+
+.. _SD-Format: http://en.wikipedia.org/wiki/Chemical_table_file
+.. _SMILES Format: http://en.wikipedia.org/wiki/Simplified_molecular_input_line_entry_specification
+.. _TDT: https://earray.chem.agilent.com/earray/helppages/index.htm#tdt_format_files.htm
+.. _Corina MOL2: http://www.molecular-networks.com/products/corina
+
+-----
+
+.. class:: infomark
+
+ **Output**
+
+Tabularfile, where each descriptor (value) is shown in a seperate column.
+
+-----
+
+.. class:: informark
+
+**Cite**
+
+Greg Landrum - RDKit_: Open-source cheminformatics
+
+.. _RDKit: http://www.rdkit.org
+
+
+    </help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/repository_dependencies.xml	Thu Aug 15 03:35:10 2013 -0400
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<repositories description="This requires the Molecule datatype definitions (e.g. SMILES, InChI, SD-format).">
+    <repository changeset_revision="85eca06eefc6" name="molecule_datatypes" owner="iuc" toolshed="http://toolshed.g2.bx.psu.edu" />
+</repositories>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tool_dependencies.xml	Thu Aug 15 03:35:10 2013 -0400
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<tool_dependency>
+    <package name="rdkit" version="2012_12_1">
+        <repository changeset_revision="7c60f011c70c" name="package_rdkit_2012_12" owner="iuc" prior_installation_required="True" toolshed="http://toolshed.g2.bx.psu.edu" />
+    </package>
+</tool_dependency>