diff options
author | Andreas Maunz <andreas@maunz.de> | 2012-09-20 10:20:59 +0200 |
---|---|---|
committer | Andreas Maunz <andreas@maunz.de> | 2012-09-20 10:20:59 +0200 |
commit | 4ed79098c147209343fc083c1b63f2946fbd6914 (patch) | |
tree | 80bc343f0a986849cd8094a334c0eeadb25bbc81 | |
parent | 3703fef20c6ce0c6324c2636691438bca047cc85 (diff) |
Java doc
-rw-r--r-- | java/ApplyCDKDescriptors.class | bin | 8632 -> 8865 bytes | |||
-rw-r--r-- | java/ApplyCDKDescriptors.java | 142 | ||||
-rw-r--r-- | pc.rb | 7 |
3 files changed, 112 insertions, 37 deletions
diff --git a/java/ApplyCDKDescriptors.class b/java/ApplyCDKDescriptors.class Binary files differindex dd00864..c5ee8a4 100644 --- a/java/ApplyCDKDescriptors.class +++ b/java/ApplyCDKDescriptors.class 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<IMolecule> mols = readMolecules(sdfInputPath); System.err.println("read " + mols.size() + " compounds"); List<IDescriptor> 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<Object, Object> 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<Object, Object> 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<IMolecule> The molecules + * @param IMoleculeDescriptor The descriptor + * @return List<Double[]> The descriptor values as list + */ public static List<Double[]> computeLists(List<IMolecule> mols, IMolecularDescriptor desc ) { - //System.out.println("computing descriptor " + getName(desc)); + System.out.println("computing descriptor " + getName(desc)); List<Double[]> values = computeDescriptors(mols, (IMolecularDescriptor) desc); return values; } + + /** + * Read in molecules, using any supported format + * + * @param string The input file + * @return Vector<IMolecule> The molecules + */ public static List<IMolecule> readMolecules(String filepath) { Vector<IMolecule> mols = new Vector<IMolecule>(); @@ -179,6 +212,14 @@ public class ApplyCDKDescriptors return mols; } + + /** + * Compute descriptors + * + * @param List<IMolecule> The molecules + * @param IMoleculeDescriptor The descriptor + * @return List<Double[]> The results as list + */ public static List<Double[]> computeDescriptors(List<IMolecule> mols, IMolecularDescriptor descriptor) { List<Double[]> vv = new ArrayList<Double[]>(); @@ -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(); + } + + } @@ -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') |