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);
}
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();
}
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();
}
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;
}
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;
}
Aggregations