Search in sources :

Example 1 with XLogPDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor in project ambit-mirror by ideaconsult.

the class DbDescriptorValuesWriterTest method testWriteDescriptorValue.

/**
 * Test method for
 * {@link ambit2.db.processors.DbDescriptorWriter#write(org.openscience.cdk.qsar.DescriptorValue)}
 * .
 */
@Test
public void testWriteDescriptorValue() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5, names.getRowCount());
    ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(2, values.getRowCount());
    ITable templates = c.createQueryTable("EXPECTED_TEMPLATES", "SELECT * FROM template");
    Assert.assertEquals(5, templates.getRowCount());
    ITable dictionary = c.createQueryTable("EXPECTED_ONTOLOGY", "SELECT * FROM dictionary");
    Assert.assertEquals(3, dictionary.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.setStructure(new StructureRecord(7, 100211, "", ""));
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(6, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(3, values.getRowCount());
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new DoubleResult(5.01), new String[] { "XLogP" });
    writer.setStructure(new StructureRecord(10, 100214, "", ""));
    writer.write(v);
    // one more time
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT value_num FROM property_values WHERE idstructure=100214");
    Assert.assertEquals(1, values.getRowCount());
    Assert.assertEquals(5.01, (Double) DataType.DOUBLE.typeCast(values.getValue(0, "value_num")), 1E-4);
    c.close();
}
Also used : StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 2 with XLogPDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor in project ambit-mirror by ideaconsult.

the class DbDescriptorValuesWriterTest method testReadWriteProperty.

@Test
public void testReadWriteProperty() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/experiments-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_FIELDS", "SELECT * FROM property_values");
    Assert.assertEquals(0, names.getRowCount());
    XLogPDescriptor xlogp = new XLogPDescriptor();
    RepositoryReader reader = new RepositoryReader();
    reader.setConnection(c.getConnection());
    writer.setConnection(c.getConnection());
    writer.open();
    reader.open();
    int records = 0;
    long now = System.currentTimeMillis();
    IChemObjectBuilder b = SilentChemObjectBuilder.getInstance();
    IStructureRecord o;
    while (reader.hasNext()) {
        o = reader.next();
        String content = reader.getStructure(o.getIdstructure());
        if (content == null)
            continue;
        IIteratingChemObjectReader mReader = new IteratingSDFReader(new StringReader(content), b);
        if (mReader.hasNext()) {
            Object mol = mReader.next();
            if (mol instanceof IAtomContainer) {
                writer.setStructure(o);
                writer.write(xlogp.calculate((IAtomContainer) mol));
            }
        }
        o.clear();
        mReader.close();
        mReader = null;
        records++;
    }
    reader.close();
    writer.close();
    now = System.currentTimeMillis() - now;
    c = getConnection();
    names = c.createQueryTable("EXPECTED_FIELDS", "SELECT * FROM property_values where value_num is not null");
    Assert.assertEquals(2, names.getRowCount());
    names = c.createQueryTable("EXPECTED_FIELDS", "SELECT * FROM property_values  where idstructure in (105095,109287)");
    Assert.assertEquals(2, names.getRowCount());
    c.close();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) IStructureRecord(ambit2.base.interfaces.IStructureRecord) StringReader(java.io.StringReader) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) RepositoryReader(ambit2.db.RepositoryReader) Test(org.junit.Test)

Example 3 with XLogPDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor in project ambit-mirror by ideaconsult.

the class DbDescriptorWriterTest method testWriteAllDescriptors.

@Test
public void testWriteAllDescriptors() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    DbDescriptorWriter writer = new DbDescriptorWriter();
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5, names.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new DoubleResult(5), new String[] { "XLogP" });
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(2, values.getRowCount());
    c.close();
}
Also used : DbDescriptorWriter(ambit2.db.processors.DbDescriptorWriter) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 4 with XLogPDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor in project ambit-mirror by ideaconsult.

the class DbDescriptorValuesWriterTest method testWriteStringDescriptorValue.

@Test
public void testWriteStringDescriptorValue() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5, names.getRowCount());
    ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(2, values.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.setStructure(new StructureRecord(7, 100211, "", ""));
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(6, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(3, values.getRowCount());
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new StringDescriptorResultType("TESTVALUE"), new String[] { "XLogP" });
    writer.setStructure(new StructureRecord(10, 100214, "", ""));
    writer.write(v);
    // one more time
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    values = c.createQueryTable("EXPECTED_VALUES", "SELECT value FROM values_string WHERE idstructure=100214");
    Assert.assertEquals(1, values.getRowCount());
    Object o = values.getValue(0, "value");
    if (o instanceof String)
        Assert.assertEquals("TESTVALUE", (String) o);
    else
        Assert.assertEquals("TESTVALUE", new String((byte[]) o));
    c.close();
}
Also used : StringDescriptorResultType(ambit2.core.data.StringDescriptorResultType) StructureRecord(ambit2.base.data.StructureRecord) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Example 5 with XLogPDescriptor

use of org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor in project ambit-mirror by ideaconsult.

the class DbDescriptorWriterTest method test.

@Test
public void test() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    DbDescriptorWriter writer = new DbDescriptorWriter();
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(5, names.getRowCount());
    writer.setConnection(c.getConnection());
    writer.open();
    XLogPDescriptor xlogp = new XLogPDescriptor();
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    DescriptorValue v = new DescriptorValue(new DescriptorSpecification("XLogPReference", "XLogPTitle", "XLogPIdentifier", "XLogPVendor"), new String[] {}, new Object[] {}, new DoubleResult(5), new String[] { "XLogP" });
    writer.write(xlogp.calculate(MoleculeFactory.makeAlkane(10)));
    writer.write(v);
    c.close();
    c = getConnection();
    names = c.createQueryTable("EXPECTED_NAMES", "SELECT * FROM properties");
    Assert.assertEquals(7, names.getRowCount());
    ITable values = c.createQueryTable("EXPECTED_VALUES", "SELECT * FROM property_values");
    Assert.assertEquals(2, values.getRowCount());
    c.close();
}
Also used : DbDescriptorWriter(ambit2.db.processors.DbDescriptorWriter) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) DescriptorSpecification(org.openscience.cdk.qsar.DescriptorSpecification) XLogPDescriptor(org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Aggregations

IDatabaseConnection (org.dbunit.database.IDatabaseConnection)5 ITable (org.dbunit.dataset.ITable)5 Test (org.junit.Test)5 XLogPDescriptor (org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor)5 DescriptorSpecification (org.openscience.cdk.qsar.DescriptorSpecification)4 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)4 IStructureRecord (ambit2.base.interfaces.IStructureRecord)3 DoubleResult (org.openscience.cdk.qsar.result.DoubleResult)3 StructureRecord (ambit2.base.data.StructureRecord)2 DbDescriptorWriter (ambit2.db.processors.DbDescriptorWriter)2 StringDescriptorResultType (ambit2.core.data.StringDescriptorResultType)1 RepositoryReader (ambit2.db.RepositoryReader)1 StringReader (java.io.StringReader)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)1 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)1 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)1