use of ambit2.core.io.RawIteratingSDFReader 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();
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class RepositoryWriterTest method testZeroLeadingCAS.
@Test
public void testZeroLeadingCAS() throws Exception {
setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
IDatabaseConnection c = getConnection();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/test/weirdcasformatting.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(10, 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(10, chemicals.getRowCount());
ITable strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
Assert.assertEquals(10, strucs.getRowCount());
ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT id_srcdataset,idtemplate FROM src_dataset where name='TEST INPUT'");
Assert.assertEquals(1, srcdataset.getRowCount());
ITable table = c.createQueryTable("EXPECTED", "SELECT value from property_string where value='1728-95-6'");
Assert.assertEquals(1, table.getRowCount());
table = c.createQueryTable("Z0", "SELECT value,name FROM property_values left join property_string using(idvalue_string) join properties using(idproperty) join catalog_references using(idreference) where comments='http://www.opentox.org/api/1.1#CASRN' and !(value regexp '^0')");
Assert.assertEquals(10, table.getRowCount());
c.close();
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class RepositoryWriterTest method testSeekByCID.
@Test
public void testSeekByCID() 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());
InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/cid/712.sdf");
Assert.assertNotNull(in);
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
reader.setReference(LiteratureEntry.getInstance("712.sdf"));
write(reader, c.getConnection(), new PubchemCID());
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(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");
Assert.assertEquals(38, property.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
Assert.assertEquals(63, property_values.getRowCount());
srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset join template_def using(idtemplate) where name='TEST INPUT'");
Assert.assertEquals(38, srcdataset.getRowCount());
c.close();
/**
* Removing redundant properties insert ignore into property_values
* select id,idproperty,idstructure,idvalue,idtype,user_name,status from
* property_values where idstructure>3 on duplicate key update
* idstructure=3 delete from property_values where idstructure>3
*
* insert ignore into struc_dataset select idstructure,id_srcdataset
* from struc_dataset where idstructure>3 on duplicate key update
* idstructure=3 delete from struc_dataset where idstructure>3
*/
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class RepositoryWriterTest method main.
public static void main(String[] args) {
if (args == null || args.length == 0)
System.exit(-1);
RepositoryWriterTest w = new RepositoryWriterTest();
File file = new File(args[0]);
RawIteratingSDFReader reader = null;
IDatabaseConnection c = null;
long now = System.currentTimeMillis();
try {
w.setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
c = w.getConnection();
reader = new RawIteratingSDFReader(new FileReader(file));
reader.setReference(LiteratureEntry.getInstance(file.getName()));
w.write(reader, c.getConnection(), new NoneKey(), false, 1000000);
c.close();
} catch (Exception x) {
x.printStackTrace();
} finally {
try {
if (reader != null)
reader.close();
} catch (Exception x) {
}
try {
if (c != null)
c.close();
} catch (Exception x) {
}
System.out.print("Elapsed ");
System.out.println(System.currentTimeMillis() - now);
}
}
use of ambit2.core.io.RawIteratingSDFReader in project ambit-mirror by ideaconsult.
the class QuerySmartsTest method testMatchNoAccelerator.
@Test
public void testMatchNoAccelerator() throws Exception {
Preferences.setProperty(Preferences.FASTSMARTS, "false");
QuerySMARTS q = new QuerySMARTS();
q.setValue(new FunctionalGroup("aromatic aldehyde example", "c1ccccc1[$(C(C)C(=O)),$(CC(C)C(=O))]", ""));
// "c1ccccc1C(C)C(=O)",""));
RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/test/smartssearch.sdf")));
int count = 0;
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
Assert.assertEquals(1.0, q.calculateMetric(record));
count++;
}
Assert.assertEquals(2, count);
}
Aggregations