use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class RawIteratingWrapperTest method testDX.
@Test
public void testDX() throws Exception {
InputStream in = RawIteratingWrapperTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/dx/predictions.sdf");
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
reader.setReference(LiteratureEntry.getInstance("predictions.sdf"));
Assert.assertTrue(reader != null);
DXParser dxParser = new DXParser();
StructureNormalizer normalizer = new StructureNormalizer();
int count = 0;
while (reader.hasNext()) {
IStructureRecord record = (IStructureRecord) reader.next();
IStructureRecord normalized = normalizer.process(record);
// System.out.println(normalized.getContent());
int rr = 0;
for (Property p : normalized.getRecordProperties()) {
rr++;
// System.out.println(String.format(">>\t%s\t=%s\t%s", p.getName(),normalized.getRecordProperty(p),p.getLabel()));
Assert.assertNotNull(normalized.getRecordProperty(p));
Assert.assertNotNull(p.getLabel());
Assert.assertNotNull(p.getName());
if (p.getName().startsWith("DX.")) {
Assert.assertTrue(p.getLabel().startsWith("http://www.opentox.org/echaEndpoints.owl#"));
// System.out.println(p.getAnnotations());
}
}
Assert.assertEquals(27, rr);
/*
* normalized = dxParser.process(normalized); for (Property p :
* normalized.getProperties()) {
* System.out.println(String.format("DX>>\t%s\t=%s",
* p.getName(),normalized.getProperty(p)));
* Assert.assertNotNull(normalized.getProperty(p)); }
*/
count++;
}
Assert.assertEquals(1, count);
reader.close();
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class RawIteratingWrapperTest method main.
public static void main(String[] args) {
if (args == null || args.length == 0)
System.exit(-1);
File file = new File(args[0]);
RawIteratingSDFReader reader = null;
try {
reader = new RawIteratingSDFReader(new FileReader(file));
int count = 0;
long start = System.currentTimeMillis();
long now = System.currentTimeMillis();
long startRead = start;
while (reader.hasNext()) {
IStructureRecord mol = reader.nextRecord();
// System.out.println(mol.getContent());
count++;
if ((count % 1000) == 0) {
now = System.currentTimeMillis();
System.out.print(count);
System.out.print("\t");
System.out.println((now - start) / 100.0);
start = now;
}
}
now = System.currentTimeMillis();
System.out.println(count);
System.out.print(now - startRead);
System.out.println(" msec");
} catch (Exception x) {
x.printStackTrace();
} finally {
try {
if (reader != null)
reader.close();
} catch (Exception x) {
}
}
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class QuerySmartsTest method testMatchWithAccelerator.
@Test
public void testMatchWithAccelerator() throws Exception {
Preferences.setProperty(Preferences.FASTSMARTS, "true");
QuerySMARTS q = new QuerySMARTS();
q.setValue(new FunctionalGroup("aromatic aldehyde example", "c1ccccc1[$(C(C)C(=O)),$(CC(C)C(=O))]", ""));
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/test/smartssearch.sdf")));
int count = 0;
SMARTSPropertiesGenerator gen = new SMARTSPropertiesGenerator();
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
try {
gen.process(record);
} catch (Exception x) {
x.printStackTrace();
}
Assert.assertNotNull(record.getRecordProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp)));
/*
record.setProperty(Property.getInstance(CMLUtilities.SMARTSProp, CMLUtilities.SMARTSProp),
"0210,1430,1440,04310600,14310600,14310600,14310600,14310600,14310600,3440,0110,0110,0110,0110,0110,0110,0110,0110,0110,0110,\n0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,0,0,0,0,0,");
*/
Assert.assertEquals(1.0, q.calculateMetric(record));
count++;
}
Assert.assertEquals(2, count);
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class AtomEnvironmentGeneratorTest method test.
/*
* public void testAtomEnvironmentDescriptor() throws Exception {
* AtomEnvironmentGenerator gen = new AtomEnvironmentGenerator();
* gen.setMaxLevels(1); gen.setUseHydrogens(false);
*
* SmilesParserWrapper sp = SmilesParserWrapper.getInstance();
* IAtomContainer mol = sp.parseSmiles("CCCC(O)=O"); AtomConfigurator typer
* = new AtomConfigurator(); typer.process(mol);
*
* CDKHydrogenAdder hAdder =
* CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
* hAdder.addImplicitHydrogens(mol);
*
* mol = gen.process(mol);
*
* Object ae = mol.getProperty(AmbitCONSTANTS.AtomEnvironment);
*
* Assert.assertTrue(ae instanceof AtomEnvironmentList); for
* (AtomEnvironment a : (AtomEnvironmentList) ae) { System.out.println(a);
* int[] l0 = a.getLevel(0); for (int i:l0)
* System.out.print(String.format("%d,", i)); System.out.println(); int[] l1
* = a.getLevel(1); for (int i:l1) System.out.print(String.format("%d,",
* i)); System.out.println(); } System.out.println(ae);
*
* }
*/
@Test
public void test() throws Exception {
AtomEnvironmentGenerator gen = new AtomEnvironmentGenerator();
gen.setMaxLevels(1);
InputStream in = AtomEnvironmentGeneratorTest.class.getClassLoader().getResourceAsStream("ambit2/descriptors/3d/test.sdf");
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
record = gen.process(record);
AtomEnvironmentList ae = (AtomEnvironmentList) record.getRecordProperty(gen.getProperty());
System.out.println();
System.out.println(ae);
for (AtomEnvironment a : (AtomEnvironmentList) ae) {
System.out.println(a);
int[] l0 = a.getLevel(0);
for (int i : l0) System.out.print(String.format("%d,", i));
System.out.println();
int[] l1 = a.getLevel(1);
for (int i : l1) System.out.print(String.format("%d,", i));
System.out.println();
}
}
reader.close();
/*
* IStructureRecord record = new StructureRecord(); record.setContent();
* MoleculeReader reader = new MoleculeReader(); reader.process(target)
*/
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class Context method parseCommandDataset.
protected long parseCommandDataset(long now) throws Exception {
RawIteratingSDFReader reader = null;
try {
File file = new File(options.input);
reader = new RawIteratingSDFReader(new FileReader(file));
reader.setReference(LiteratureEntry.getInstance(file.getName()));
SourceDataset dataset = new SourceDataset(file.getName(), LiteratureEntry.getInstance("File", file.getName()));
return write(reader, new NoneKey(), dataset, -1);
} catch (Exception x) {
throw x;
} finally {
logger_cli.log(Level.INFO, "MSG_INFO_COMPLETED", (System.currentTimeMillis() - now));
try {
if (reader != null)
reader.close();
} catch (Exception x) {
}
if (options.output != null) {
logger_cli.log(Level.INFO, "MSG_INFO_RESULTSWRITTEN", options.output);
}
}
}
Aggregations