From 4ed79098c147209343fc083c1b63f2946fbd6914 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Thu, 20 Sep 2012 10:20:59 +0200 Subject: Java doc --- java/ApplyCDKDescriptors.class | Bin 8632 -> 8865 bytes java/ApplyCDKDescriptors.java | 142 +++++++++++++++++++++++++++++++---------- pc.rb | 7 +- 3 files changed, 112 insertions(+), 37 deletions(-) diff --git a/java/ApplyCDKDescriptors.class b/java/ApplyCDKDescriptors.class index dd00864..c5ee8a4 100644 Binary files a/java/ApplyCDKDescriptors.class and b/java/ApplyCDKDescriptors.class differ diff --git a/java/ApplyCDKDescriptors.java b/java/ApplyCDKDescriptors.java index f872026..85a1abd 100644 --- a/java/ApplyCDKDescriptors.java +++ b/java/ApplyCDKDescriptors.java @@ -28,40 +28,52 @@ import org.openscience.cdk.tools.manipulator.ChemFileManipulator; import org.openscience.cdk.qsar.descriptors.molecular.IPMolecularLearningDescriptor; import org.openscience.cdk.smiles.SmilesGenerator; -public class ApplyCDKDescriptors -{ - public ApplyCDKDescriptors(String inpath, String outpath, String descNamesStr) throws java.io.IOException - { +/** + * ApplyCDKDescriptors.java + * Purpose: Calculate CDK descriptors in CSV format from input SDF files + * For ease of use, the design is completely static, i.e. no member functions + * Calling the constructor executes the algorithm + * + * @author Martin Guetlein, Andreas Maunz + * @version 1.0 20/9/2012 + */ +public class ApplyCDKDescriptors { + private static DescriptorEngine ENGINE = new DescriptorEngine(DescriptorEngine.MOLECULAR); + + + /** + * Constructor, executing the algorithm + * + * @param: string The path to the input SDF file + * @param: string The path to the output CSV file + */ + public ApplyCDKDescriptors(String inpath, String outpath, String descNamesStr) throws java.io.IOException { getDescriptorCSV(inpath,outpath,descNamesStr); } - private static DescriptorEngine ENGINE = new DescriptorEngine(DescriptorEngine.MOLECULAR); - - private static int getSize(IMolecularDescriptor descriptor) - { - IDescriptorResult r = descriptor.getDescriptorResultType(); - if (r instanceof DoubleArrayResultType) - return ((DoubleArrayResultType) r).length(); - else if (r instanceof IntegerArrayResultType) - return ((IntegerArrayResultType) r).length(); - else - return 1; - } - private static String getName(IDescriptor descriptor) + /** + * Example main + * + */ + public static void main(String args[]) throws java.io.IOException { - return ENGINE.getDictionaryTitle(descriptor.getSpecification()).trim(); + String inpath = "hamster_3d.sdf"; + String outpath = "hamster_desc.csv"; + getDescriptorCSV(inpath,outpath,""); } - //public static void main(String args[]) throws java.io.IOException - //{ - // String inpath = "hamster_3d.sdf"; - // String outpath = "hamster_desc.csv"; - // getDescriptorCSV(inpath,outpath,""); - //} - public static void getDescriptorCSV(String sdfInputPath, String csvOutputPath, String descNamesStr) throws java.io.IOException { + /** + * Calculate descriptors. Omits IPMolecularLearningDescriptor + * + * @param string path to SDF input file + * @param string path to CSV output file + * @param string comma-seperated list of descriptor names (if empty, all descriptors will be calculated) + */ + public static void getDescriptorCSV(String sdfInputPath, String csvOutputPath, String descNamesStr) throws java.io.IOException + { List mols = readMolecules(sdfInputPath); System.err.println("read " + mols.size() + " compounds"); List descriptors = ENGINE.getDescriptorInstances(); @@ -110,24 +122,45 @@ public class ApplyCDKDescriptors } + /** + * Get SMILES code for a molecule + * + * @param IMolecule The molecule + * @return string The SMILES code + */ public static String getSmiles(IMolecule m) - { - Map props = m.getProperties(); - for (Object key : props.keySet()) { - if (key.toString().equals("STRUCTURE_SMILES") || key.toString().equals("SMILES")) - return props.get(key).toString(); - } - SmilesGenerator g = new SmilesGenerator(); - return g.createSMILES(m); - } + { + Map props = m.getProperties(); + for (Object key : props.keySet()) { + if (key.toString().equals("STRUCTURE_SMILES") || key.toString().equals("SMILES")) + return props.get(key).toString(); + } + SmilesGenerator g = new SmilesGenerator(); + return g.createSMILES(m); + } + + /** + * Compute descriptor values, convert to list + * + * @param List The molecules + * @param IMoleculeDescriptor The descriptor + * @return List The descriptor values as list + */ public static List computeLists(List mols, IMolecularDescriptor desc ) { - //System.out.println("computing descriptor " + getName(desc)); + System.out.println("computing descriptor " + getName(desc)); List values = computeDescriptors(mols, (IMolecularDescriptor) desc); return values; } + + /** + * Read in molecules, using any supported format + * + * @param string The input file + * @return Vector The molecules + */ public static List readMolecules(String filepath) { Vector mols = new Vector(); @@ -179,6 +212,14 @@ public class ApplyCDKDescriptors return mols; } + + /** + * Compute descriptors + * + * @param List The molecules + * @param IMoleculeDescriptor The descriptor + * @return List The results as list + */ public static List computeDescriptors(List mols, IMolecularDescriptor descriptor) { List vv = new ArrayList(); @@ -227,4 +268,35 @@ public class ApplyCDKDescriptors return vv; } + + + /** + * Get length of result for a given descriptor + * + * @param IMolecularDescriptor The descriptor + * @return int The length + */ + private static int getSize(IMolecularDescriptor descriptor) + { + IDescriptorResult r = descriptor.getDescriptorResultType(); + if (r instanceof DoubleArrayResultType) + return ((DoubleArrayResultType) r).length(); + else if (r instanceof IntegerArrayResultType) + return ((IntegerArrayResultType) r).length(); + else + return 1; + } + + + /** + * Get name for a given descriptor + * + * @param IMolecularDescriptor The descriptor + */ + private static String getName(IDescriptor descriptor) + { + return ENGINE.getDictionaryTitle(descriptor.getSpecification()).trim(); + } + + } diff --git a/pc.rb b/pc.rb index 2ef95bb..14a1e76 100644 --- a/pc.rb +++ b/pc.rb @@ -79,8 +79,11 @@ post '/pc/AllDescriptors' do task = OpenTox::Task.create("PC descriptor calculation for dataset ", @uri) do |task| Rjb.load(nil,["-Xmx64m"]) # start vm - byteArray = Rjb::import('java.io.ByteArrayOutputStream'); printStream = Rjb::import('java.io.PrintStream'); - out = byteArray.new() ; Rjb::import('java.lang.System').out = printStream.new(out) # joelib is too verbose + byteArray = Rjb::import('java.io.ByteArrayOutputStream') + printStream = Rjb::import('java.io.PrintStream') + out = byteArray.new() + Rjb::import('java.lang.System').out = printStream.new(out) # suppress java output + Rjb::import('java.lang.System').err = printStream.new(out) # suppress java output s = Rjb::import('JoelibFc') # import main class t = Rjb::import('ApplyCDKDescriptors') -- cgit v1.2.3