Search in sources :

Example 96 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class CreateAtomEnvironment method getParameters.

@Override
public List<QueryParam> getParameters(int index) throws AmbitException {
    List<QueryParam> params = new ArrayList<QueryParam>();
    params.add(new QueryParam<Integer>(Integer.class, getGroup().getIdchemical()));
    AtomEnvironment ae = ((AtomEnvironmentList) getGroup().getRecordProperty(property)).get(index);
    params.add(new QueryParam<String>(String.class, ae.getCentral_atom()));
    params.add(new QueryParam<Integer>(Integer.class, ae.getFrequency()));
    for (int i = 1; i < 7; i++) {
        String p = ae.getLevel2String(i);
        params.add(new QueryParam<String>(String.class, p == null ? "" : p));
    }
    params.add(new QueryParam<String>(String.class, "valid"));
    return params;
}
Also used : AtomEnvironment(ambit2.descriptors.AtomEnvironment) QueryParam(net.idea.modbcum.i.query.QueryParam) ArrayList(java.util.ArrayList) AtomEnvironmentList(ambit2.descriptors.processors.AtomEnvironmentList)

Example 97 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class ProcessorOntologyEditorTest method testCreateProperty.

@Test
public void testCreateProperty() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable names = c.createQueryTable("expected", "SELECT * FROM template_properties where template=\"Physicochemical effects\" and property=\"Boling point\"");
    Assert.assertEquals(0, names.getRowCount());
    editor.setConnection(c.getConnection());
    editor.setOperation(OP.CREATE);
    editor.setTemplate(new Dictionary(null, null), SIDE.LEFT);
    editor.setTemplate(new Dictionary("Physicochemical effects", null), SIDE.RIGHT);
    editor.setCurrentSide(SIDE.RIGHT);
    editor.process(Property.getInstance("Boiling point", "My new reference"));
    names = c.createQueryTable("expected", "SELECT * FROM template_properties where template=\"Physicochemical effects\" and property=\"Boiling point\"");
    Assert.assertEquals(1, names.getRowCount());
    c.close();
}
Also used : Dictionary(ambit2.base.data.Dictionary) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 98 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testImportDX.

@Test
public void testImportDX() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/dataset-properties.xml");
    IDatabaseConnection c = getConnection();
    ITable chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(5, chemicals.getRowCount());
    ITable strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(5, strucs.getRowCount());
    ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset");
    Assert.assertEquals(1, srcdataset.getRowCount());
    ITable struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(2, struc_src.getRowCount());
    ITable property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(4, property.getRowCount());
    ITable property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(4, property_values.getRowCount());
    ITable template_def = c.createQueryTable("EXPECTED", "SELECT * FROM template_def");
    Assert.assertEquals(3, template_def.getRowCount());
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/core/data/dx/predictions.sdf");
    Assert.assertNotNull(in);
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
    // reader.setReference("predictions.sdf");
    write(reader, c.getConnection(), new CASKey());
    reader.close();
    c.close();
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(6, chemicals.getRowCount());
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(6, strucs.getRowCount());
    // srcdataset =
    // c.createQueryTable("EXPECTED","SELECT * FROM src_dataset where name='Imported properties'");
    // Assert.assertEquals(1,srcdataset.getRowCount());
    // struc_src =
    // c.createQueryTable("EXPECTED","SELECT * FROM struc_dataset join src_dataset using(id_srcdataset) where name='Imported properties'");
    // Assert.assertEquals(1,struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(31, property.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(31, property_values.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values where idstructure=100215");
    Assert.assertEquals(2, property_values.getRowCount());
    // ITable p_tuples =
    // c.createQueryTable("EXPECTED","SELECT * FROM property_tuples join tuples using(idtuple) join src_dataset using(id_srcdataset) where name='Imported properties'");
    // Assert.assertEquals(66,p_tuples.getRowCount());
    c.close();
    c = getConnection();
    in = this.getClass().getClassLoader().getResourceAsStream("ambit2/core/data/dx/predictions1.sdf");
    Assert.assertNotNull(in);
    reader = new RawIteratingSDFReader(new InputStreamReader(in));
    // reader.setReference(LiteratureEntry.getDXReference());
    write(reader, c.getConnection(), new CASKey());
    reader.close();
    c = getConnection();
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(31, property.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(47, property_values.getRowCount());
    template_def = c.createQueryTable("EXPECTED", "SELECT * FROM template_def");
    Assert.assertEquals(30, template_def.getRowCount());
    c.close();
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) CASKey(ambit2.core.processors.structure.key.CASKey) InputStream(java.io.InputStream) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 99 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testImportByInChI.

@Test
public void testImportByInChI() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/match/atropine.sdf");
    Assert.assertNotNull(in);
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
    reader.setReference(LiteratureEntry.getInstance("input.sdf"));
    write(reader, c.getConnection());
    c.close();
    c = getConnection();
    ITable chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(1, chemicals.getRowCount());
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals where smiles is not null and inchi is not null and formula is not null");
    Assert.assertEquals(1, chemicals.getRowCount());
    ITable strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(1, strucs.getRowCount());
    ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT id_srcdataset,idtemplate FROM src_dataset where name='TEST INPUT'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    // verifies if trigger insert_dataset_template works ok
    Assert.assertNotNull(srcdataset.getValue(0, "idtemplate"));
    ITable struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(1, struc_src.getRowCount());
    ITable property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(2, property.getRowCount());
    ITable property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(2, property_values.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset join template_def using(idtemplate) where name='TEST INPUT'");
    Assert.assertEquals(2, srcdataset.getRowCount());
    c.close();
    c = getConnection();
    // now import properties and match by inchi
    in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/match/props.csv");
    Assert.assertNotNull(in);
    IIteratingChemObjectReader reader1 = FileInputState.getReader(in, ".csv");
    importProperties(reader1, c.getConnection(), new InchiKey());
    // importProperties(reader1,c.getConnection(),new InchiPropertyKey());
    c.close();
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(1, chemicals.getRowCount());
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(1, strucs.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset where name='Imported properties'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset join src_dataset using(id_srcdataset) where name='Imported properties'");
    Assert.assertEquals(1, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertTrue(property.getRowCount() >= 6);
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(6, property_values.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name='chiSquared'");
    Assert.assertEquals(1, property_values.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset join template_def using(idtemplate) where name='Imported properties'");
    Assert.assertEquals(4, srcdataset.getRowCount());
    c.close();
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) InputStream(java.io.InputStream) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) InchiKey(ambit2.core.processors.structure.key.InchiKey) Test(org.junit.Test)

Example 100 with Property

use of ambit2.base.data.Property in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testWriteMultipleFiles_i5d.

@Test
public void testWriteMultipleFiles_i5d() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(0, chemicals.getRowCount());
    ITable strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(0, strucs.getRowCount());
    ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset");
    Assert.assertEquals(0, srcdataset.getRowCount());
    ITable struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(0, struc_src.getRowCount());
    ITable property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(0, property.getRowCount());
    ITable property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(0, property_values.getRowCount());
    File dir = new File("src/test/resources/ambit2/db/processors/i5d");
    FilenameFilter filter = new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return !name.startsWith(".");
        }
    };
    File[] files = dir.listFiles(filter);
    Assert.assertEquals(3, files.length);
    RawIteratingFolderReader reader = new RawIteratingFolderReader(files);
    write(reader, c.getConnection(), new EINECSKey());
    reader.close();
    c.close();
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(3, chemicals.getRowCount());
    // there are two empty file without $$$$ sign, which are skipped
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(3, strucs.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset where name='TEST INPUT'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(3, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties join catalog_references using(idreference) where name='Names' and title in ('IUCLID5 SYNONYM#2','IUCLID5')");
    Assert.assertEquals(2, property.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties join catalog_references using(idreference) order by name");
    // Assert.assertEquals(34,property.getRowCount());
    Assert.assertEquals(7, property.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(19, property_values.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset join template_def using(idtemplate) where name='TEST INPUT'");
    Assert.assertEquals(7, srcdataset.getRowCount());
    ITable p_cas = c.createQueryTable("EXPECTED", "SELECT idchemical,idstructure,value FROM property_values join property_string using(idvalue_string) join properties using(idproperty) where name='CasRN'");
    Assert.assertEquals(3, p_cas.getRowCount());
    ITable p_ec = c.createQueryTable("EXPECTED", "SELECT idchemical,idstructure,value FROM property_values join property_string using(idvalue_string) join properties using(idproperty) where name='EC'");
    Assert.assertEquals(3, p_ec.getRowCount());
    ITable p_uuid = c.createQueryTable("EXPECTED", "SELECT idchemical,idstructure,value FROM property_values join property_string using(idvalue_string) join properties using(idproperty) where name='I5UUID'");
    Assert.assertEquals(3, p_uuid.getRowCount());
    c.close();
}
Also used : FilenameFilter(java.io.FilenameFilter) EINECSKey(ambit2.core.processors.structure.key.EINECSKey) ITable(org.dbunit.dataset.ITable) RawIteratingFolderReader(ambit2.core.io.RawIteratingFolderReader) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) File(java.io.File) Test(org.junit.Test)

Aggregations

Property (ambit2.base.data.Property)247 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)113 Test (org.junit.Test)69 IStructureRecord (ambit2.base.interfaces.IStructureRecord)56 ResourceException (org.restlet.resource.ResourceException)46 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)44 ITable (org.dbunit.dataset.ITable)44 Reference (org.restlet.data.Reference)37 LiteratureEntry (ambit2.base.data.LiteratureEntry)36 IOException (java.io.IOException)30 ArrayList (java.util.ArrayList)30 SQLException (java.sql.SQLException)28 InputStream (java.io.InputStream)27 StructureRecord (ambit2.base.data.StructureRecord)26 Form (org.restlet.data.Form)25 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)24 ResourceTest (ambit2.rest.test.ResourceTest)22 PropertyAnnotation (ambit2.base.data.PropertyAnnotation)19 SourceDataset (ambit2.base.data.SourceDataset)16 Template (ambit2.base.data.Template)16