Search in sources :

Example 1 with IteratingDelimitedFileReader

use of ambit2.core.io.IteratingDelimitedFileReader in project ambit-mirror by ideaconsult.

the class ListenerTest method testListenerCSV.

@Test
public void testListenerCSV() throws Exception {
    String[] labels = { "Code", "Compound", "SMILES", "MolWeigth", "CasRN", "log_P", "eLumo", "eHomo", "IL", "Dev.", "Pred", "abs dev", "Obs" };
    IIteratingChemObjectReader reader = new IteratingDelimitedFileReader(getClass().getClassLoader().getResourceAsStream("Debnath_smiles.csv"));
    readFile(reader, labels);
}
Also used : IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) Test(org.junit.Test)

Example 2 with IteratingDelimitedFileReader

use of ambit2.core.io.IteratingDelimitedFileReader in project ambit-mirror by ideaconsult.

the class RawIteratingWrapperTest method test.

@Test
public void test() throws Exception {
    IIteratingChemObjectReader reader = FileInputState.getReader(RawIteratingWrapperTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/io/test.txt"), "test.txt");
    Assert.assertTrue(reader != null);
    // Assert.assertTrue(reader instanceof IteratingDelimitedFileReader);
    RawIteratingWrapper wrapper = new RawIteratingWrapper(reader);
    int count = 0;
    while (wrapper.hasNext()) {
        IStructureRecord record = (IStructureRecord) wrapper.next();
        count++;
    }
    Assert.assertEquals(11, count);
    wrapper.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) Test(org.junit.Test)

Example 3 with IteratingDelimitedFileReader

use of ambit2.core.io.IteratingDelimitedFileReader in project ambit-mirror by ideaconsult.

the class PKASmartsDescriptorTest method testPredictions.

@Test
public void testPredictions() throws Exception {
    File file = File.createTempFile("ambit_results", ".csv");
    file.deleteOnExit();
    // System.out.println(file.getAbsolutePath());
    DelimitedFileWriter writer = new DelimitedFileWriter(new FileOutputStream(file));
    HydrogenAdderProcessor ha = new HydrogenAdderProcessor();
    ha.setAddEexplicitHydrogens(true);
    Preferences.setProperty(Preferences.STOP_AT_UNKNOWNATOMTYPES, "true");
    InputStream in = PKASmartsDescriptor.class.getClassLoader().getResourceAsStream("ambit2/descriptors/pka/benchmark_new.csv");
    IteratingDelimitedFileReader reader = new IteratingDelimitedFileReader(in);
    while (reader.hasNext()) {
        Object o = reader.next();
        Assert.assertTrue(o instanceof IAtomContainer);
        IAtomContainer a = null;
        try {
            a = ha.process((IAtomContainer) o);
            // AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(a);
            CDKHueckelAromaticityDetector.detectAromaticity(a);
            DescriptorValue value = pka.calculate(a);
            VerboseDescriptorResult<String, DoubleResult> result = (VerboseDescriptorResult<String, DoubleResult>) value.getValue();
            a.setProperty(value.getNames()[0], result.getResult().doubleValue());
            a.setProperty(value.getNames()[0] + "-trace", result.getExplanation());
            Double d = Double.valueOf(a.getProperty("pKa-SMARTS").toString());
            if (!d.equals(result.getResult().doubleValue())) {
            }
            writer.write(a);
        } catch (CDKException x) {
            continue;
        } catch (AmbitException x) {
            continue;
        } catch (Exception x) {
            x.printStackTrace();
            continue;
        }
    }
    in.close();
    writer.close();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) CDKException(org.openscience.cdk.exception.CDKException) DelimitedFileWriter(ambit2.core.io.DelimitedFileWriter) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CDKException(org.openscience.cdk.exception.CDKException) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) HydrogenAdderProcessor(ambit2.core.processors.structure.HydrogenAdderProcessor) FileOutputStream(java.io.FileOutputStream) PKASmartsDescriptor(ambit2.descriptors.PKASmartsDescriptor) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) File(java.io.File) VerboseDescriptorResult(ambit2.descriptors.VerboseDescriptorResult) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) Test(org.junit.Test)

Example 4 with IteratingDelimitedFileReader

use of ambit2.core.io.IteratingDelimitedFileReader in project ambit-mirror by ideaconsult.

the class DragonShell method parseOutput.

@Override
protected synchronized IAtomContainer parseOutput(String path, IAtomContainer mol) throws ShellException {
    // mol.getProperties().clear();
    MoleculeTools.clearProperties(mol);
    for (int i = 0; i < outFile.length; i++) {
        String fname = path + "/" + outFile[i];
        File f = new File(fname);
        if (!f.exists())
            continue;
        logger.fine("<outfile name=\"" + fname + "\">");
        try {
            IteratingDelimitedFileReader re = new IteratingDelimitedFileReader(new InputStreamReader(new FileInputStream(f)), new DelimitedFileFormat("\t", '"'));
            while (re.hasNext()) {
                IAtomContainer m = (IAtomContainer) re.next();
                mol.setProperties(m.getProperties());
                break;
            }
            re.close();
        // f.delete();
        } catch (Exception x) {
            logger.fine("<error name=\"" + x.getMessage() + "\"/>");
            logger.fine("</outfile>");
            throw new ShellException(this, x);
        } finally {
        }
        logger.fine("</outfile>");
    }
    return mol;
}
Also used : DelimitedFileFormat(ambit2.core.io.DelimitedFileFormat) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) File(java.io.File) ShellException(ambit2.base.external.ShellException) FileInputStream(java.io.FileInputStream) ShellException(ambit2.base.external.ShellException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 5 with IteratingDelimitedFileReader

use of ambit2.core.io.IteratingDelimitedFileReader in project ambit-mirror by ideaconsult.

the class VegaShell method parseOutput.

@Override
protected IAtomContainer parseOutput(String path, IAtomContainer mol) throws ShellException {
    // mol.getProperties().clear();
    MoleculeTools.clearProperties(mol);
    for (int i = 0; i < outFile.length; i++) {
        String fname = path + "/" + outFile[i];
        File f = new File(fname);
        if (!f.exists())
            continue;
        logger.fine("<outfile name=\"" + fname + "\">");
        try {
            IteratingDelimitedFileReader re = new IteratingDelimitedFileReader(new InputStreamReader(new FileInputStream(f)), new DelimitedFileFormat("\t", '"')) {

                @Override
                public void setReader(Reader reader) throws CDKException {
                    super.setReader(reader);
                    try {
                        // skipLines(35); //for all models
                        skipLines(13);
                    } catch (Exception x) {
                        logger.log(Level.WARNING, x.getMessage());
                    }
                }
            };
            while (re.hasNext()) {
                IAtomContainer m = (IAtomContainer) re.next();
                for (Entry<Object, Object> e : m.getProperties().entrySet()) {
                    if ("-".equals(e.getValue()))
                        continue;
                    Property p = properties.get(e.getKey().toString().replaceAll("\"", ""));
                    if (p == null)
                        continue;
                    mol.setProperty(p, e.getValue());
                }
                break;
            }
            re.close();
        // f.delete();
        } catch (Exception x) {
            logger.fine("<error name=\"" + x.getMessage() + "\"/>");
            logger.fine("</outfile>");
            throw new ShellException(this, x);
        } finally {
        }
        logger.fine("</outfile>");
    }
    return mol;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ShellException(ambit2.base.external.ShellException) FileInputStream(java.io.FileInputStream) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CDKException(org.openscience.cdk.exception.CDKException) ShellException(ambit2.base.external.ShellException) DelimitedFileFormat(ambit2.core.io.DelimitedFileFormat) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) File(java.io.File) Property(ambit2.base.data.Property)

Aggregations

IteratingDelimitedFileReader (ambit2.core.io.IteratingDelimitedFileReader)8 Test (org.junit.Test)5 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)5 ShellException (ambit2.base.external.ShellException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 CDKException (org.openscience.cdk.exception.CDKException)3 Property (ambit2.base.data.Property)2 DelimitedFileFormat (ambit2.core.io.DelimitedFileFormat)2 AbstractMopacShell (ambit2.mopac.AbstractMopacShell)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 IChemObject (org.openscience.cdk.interfaces.IChemObject)2 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 DelimitedFileWriter (ambit2.core.io.DelimitedFileWriter)1 RawIteratingWrapper (ambit2.core.io.RawIteratingWrapper)1 HydrogenAdderProcessor (ambit2.core.processors.structure.HydrogenAdderProcessor)1 PKASmartsDescriptor (ambit2.descriptors.PKASmartsDescriptor)1