Search in sources :

Example 16 with RawIteratingSDFReader

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();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) StructureNormalizer(ambit2.core.processors.StructureNormalizer) InputStream(java.io.InputStream) DXParser(ambit2.core.io.dx.DXParser) Property(ambit2.base.data.Property) Test(org.junit.Test)

Example 17 with RawIteratingSDFReader

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) {
        }
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) FileReader(java.io.FileReader) File(java.io.File)

Example 18 with RawIteratingSDFReader

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);
}
Also used : QuerySMARTS(ambit2.db.search.structure.QuerySMARTS) IStructureRecord(ambit2.base.interfaces.IStructureRecord) FunctionalGroup(ambit2.descriptors.FunctionalGroup) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) SMARTSPropertiesGenerator(ambit2.smarts.processors.SMARTSPropertiesGenerator) Test(org.junit.Test)

Example 19 with RawIteratingSDFReader

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)
		 */
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) AtomEnvironment(ambit2.descriptors.AtomEnvironment) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) AtomEnvironmentGenerator(ambit2.descriptors.processors.AtomEnvironmentGenerator) InputStream(java.io.InputStream) AtomEnvironmentList(ambit2.descriptors.processors.AtomEnvironmentList) Test(org.junit.Test)

Example 20 with RawIteratingSDFReader

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);
        }
    }
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) FileReader(java.io.FileReader) SourceDataset(ambit2.base.data.SourceDataset) NoneKey(ambit2.core.processors.structure.key.NoneKey) File(java.io.File) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)30 InputStreamReader (java.io.InputStreamReader)26 Test (org.junit.Test)21 IStructureRecord (ambit2.base.interfaces.IStructureRecord)19 InputStream (java.io.InputStream)18 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)13 ITable (org.dbunit.dataset.ITable)12 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)7 FileReader (java.io.FileReader)6 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)6 File (java.io.File)5 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)5 IOException (java.io.IOException)4 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)4 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)3 BitSet (java.util.BitSet)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 Property (ambit2.base.data.Property)2 StructureRecord (ambit2.base.data.StructureRecord)2 IteratingDelimitedFileReader (ambit2.core.io.IteratingDelimitedFileReader)2