use of ambit2.core.processors.structure.key.CASKey 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();
}
use of ambit2.core.processors.structure.key.CASKey in project ambit-mirror by ideaconsult.
the class Context method importI5Z.
protected int importI5Z(IStructureKey keytomatch, boolean i6, StructureRecordValidator validator) throws Exception {
// validator uses parsertype
setParserType(i6 ? _parsertype.i6z : _parsertype.i5z);
logger_cli.log(Level.INFO, "MSG_IMPORT", new Object[] { String.format("i%sz", i6 ? "6" : "5"), inputFile.getAbsolutePath() });
IZReader reader = null;
Connection c = null;
try {
DBConnectionConfigurable<Context> dbc = null;
dbc = getConnection(getConfigFile());
c = dbc.getConnection();
c.setAutoCommit(true);
I5Options options = new I5Options();
options.setMaxReferenceStructures(maxRefSubstances);
options.setExceptionOnMaxReferenceStructures(false);
options.setAllowMultipleSubstances(false);
if (i6)
reader = new I6ZReader<>(inputFile, options);
else
reader = new I5ZReader<>(inputFile, options);
QASettings qa = new QASettings(false);
qa.setAll();
reader.setQASettings(qa);
matchByKey = keytomatch == null ? new CASKey() : keytomatch;
return write(reader, c, matchByKey, true, clearMeasurements, clearComposition, validator, null, true, false);
} catch (Exception x) {
throw x;
} finally {
if (reader != null)
reader.close();
try {
if (c != null)
c.close();
} catch (Exception x) {
}
}
}
use of ambit2.core.processors.structure.key.CASKey in project ambit-mirror by ideaconsult.
the class RepositoryWriterTest method testImportTox21.
@Test
public void testImportTox21() 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/core/pubchem/tox21_excerpt.sdf");
Assert.assertNotNull(in);
IRawReader<IStructureRecord> reader = new RawIteratingSDFReader(new InputStreamReader(in));
// reader.setReference("predictions.sdf");
write((RawIteratingSDFReader) reader, c.getConnection(), new CASKey());
reader.close();
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='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(19, property.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
Assert.assertEquals(57, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = 'PUBCHEM_SID'");
Assert.assertEquals(3, 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/pubchem/aid720516.csv");
Assert.assertNotNull(in);
reader = new RawIteratingWrapper<IIteratingChemObjectReader>(FileInputState.getReader(in, ".csv"));
// reader.setReference(LiteratureEntry.getDXReference());
write(reader, c.getConnection(), new PubchemSID(), true);
reader.close();
c = getConnection();
strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
// Assert.assertEquals(3,strucs.getRowCount());
property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
// does not write
Assert.assertEquals(19 + 9, property.getRowCount());
// another
// PUBCHEM_SID
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = 'PUBCHEM_CID'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = 'PUBCHEM_ACTIVITY_OUTCOME'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = 'PUBCHEM_ACTIVITY_SCORE'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '1^Activity_Summary^STRING^^^^'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '2^ATAD5_Activity^STRING^^^^'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '3^ATAD5 Potency (uM)^FLOAT^uM^AC^^'");
Assert.assertEquals(0, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '4^ATAD5_Efficacy_(_)^FLOAT^_^^^'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '5^Viability_Activity^STRING^^^^'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '6^Viability_Potency (uM)^FLOAT^uM^^^'");
Assert.assertEquals(0, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '7^Viability_Efficacy_(_)^FLOAT^_^^^'");
Assert.assertEquals(3, property_values.getRowCount());
property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values join properties using(idproperty) where name = '8^Sample_Source^STRING^^^^'");
Assert.assertEquals(3, property_values.getRowCount());
// Assert.assertEquals(57+9*3,property_values.getRowCount());
c.close();
}
use of ambit2.core.processors.structure.key.CASKey in project ambit-mirror by ideaconsult.
the class CallableStructureEntry method createReference.
@Override
protected TaskResult createReference(Connection connection) throws Exception {
final RepositoryWriter writer = new RepositoryWriter();
writer.setUseExistingStructure(isPropertyOnly());
writer.setPropertyKey(new CASKey());
SourceDataset dataset;
if (isPropertyOnly()) {
dataset = new SourceDataset("Properties registration", LiteratureEntry.getInstance());
} else
dataset = new SourceDataset("Chemical structure registration", LiteratureEntry.getInstance());
dataset.setStars(6);
writer.setDataset(dataset);
writer.setConnection(connection);
writer.setCloseConnection(true);
try {
List<IStructureRecord> records = writer.write(record);
for (IStructureRecord result : records) {
// what about policies
if (isPropertyOnly()) {
return new TaskResult(String.format("%s?feature_uris=%s/dataset/Properties+registration/feature", cmpreporter.getURI(result), applicationRootReference), false);
} else {
return new TaskResult(String.format("%s?feature_uris=%s/dataset/Chemical+structure+registration/feature", cmpreporter.getURI(result), applicationRootReference), false);
}
}
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
} catch (Exception x) {
throw x;
} finally {
writer.close();
}
}
Aggregations