use of ambit2.core.io.IRawReader in project ambit-mirror by ideaconsult.
the class RawIteratingFolderReader method getItemReader.
protected IRawReader<IStructureRecord> getItemReader(int index) throws Exception {
String name = files[index].getName().toLowerCase();
if (name.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
RawIteratingSDFReader r = new RawIteratingSDFReader(new FileReader(files[index]));
r.setReference(LiteratureEntry.getInstance(files[index].getName(), "file:///" + files[index].getAbsolutePath()));
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.MOL_INDEX.getExtension())) {
RawIteratingMOLReader r = new RawIteratingMOLReader(new FileReader(files[index]));
r.setReference(LiteratureEntry.getInstance(files[index].getName(), "file:///" + files[index].getAbsolutePath()));
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.I5D_INDEX.getExtension())) {
IIteratingChemObjectReader r = FileInputState.getI5DReader(files[index]);
if (r instanceof ICiteable) {
((ICiteable) r).setReference(LiteratureEntry.getI5UUIDReference());
}
return (IRawReader<IStructureRecord>) r;
} else if (name.endsWith(FileInputState._FILE_TYPE.ZIP_INDEX.getExtension())) {
return new ZipReader(files[index]);
} else if (name.endsWith(FileInputState._FILE_TYPE.GZ_INDEX.getExtension())) {
// assuming gzipped sdf only...
InputStreamReader reader = new InputStreamReader(new GZIPInputStream(new FileInputStream(files[index])));
return new RawIteratingSDFReader(reader);
} else
throw new Exception("Unsupported format " + name);
}
use of ambit2.core.io.IRawReader in project ambit-mirror by ideaconsult.
the class RepositoryWriterToXMLTest method write.
public int write(IRawReader<IStructureRecord> reader, Connection connection, PropertyKey key) throws Exception {
RepositoryWriter writer = new RepositoryWriter();
if (key != null)
writer.setPropertyKey(key);
writer.setDataset(new SourceDataset("TEST INPUT", LiteratureEntry.getInstance("File", "file:study.toxml")));
writer.setConnection(connection);
writer.open();
int records = 0;
while (reader.hasNext()) {
IStructureRecord record = reader.nextRecord();
writer.write(record);
records++;
}
reader.close();
writer.close();
return records;
}
use of ambit2.core.io.IRawReader in project ambit-mirror by ideaconsult.
the class SubstanceWriterTest method delete.
public int delete(SubstanceEndpointsBundle bundle, IRawReader<IStructureRecord> reader, Connection connection) throws Exception {
/*
* DBSubstanceWriter writer; if (bundle != null) writer = new
* DBBundleStudyWriter(bundle, DBSubstanceWriter.datasetMeta(), new
* SubstanceRecord()); else writer = new
* DBSubstanceWriter(DBSubstanceWriter.datasetMeta(), new
* SubstanceRecord(), clearMeasurements, clearComposition);
* writer.setSplitRecord(splitRecord); writer.setConnection(connection);
* writer.open();
*/
UpdateExecutor<IQueryUpdate> writer = new UpdateExecutor<IQueryUpdate>();
writer.setConnection(connection);
DeleteMatrixValue q = new DeleteMatrixValue();
q.setGroup(bundle);
int records = 0;
while (reader.hasNext()) {
Object record = reader.next();
if (record == null)
continue;
Assert.assertTrue(record instanceof SubstanceRecord);
Assert.assertEquals("IUC4-efdb21bb-e79f-3286-a988-b6f6944d3734", ((SubstanceRecord) record).getSubstanceUUID());
for (ProtocolApplication pa : ((SubstanceRecord) record).getMeasurements()) {
Assert.assertTrue(pa instanceof ProtocolApplicationAnnotated);
// System.out.println(((ProtocolApplicationAnnotated) pa)getRecords_to_delete());
ProtocolApplicationAnnotated paa = (ProtocolApplicationAnnotated) pa;
List<ValueAnnotated> vaa = paa.getRecords_to_delete();
for (ValueAnnotated va : vaa) {
q.setObject(va);
writer.process(q);
}
}
// writer.setImportedRecord((SubstanceRecord) record);
// writer.process((IStructureRecord) record);
records++;
}
writer.close();
return records;
}
use of ambit2.core.io.IRawReader in project ambit-mirror by ideaconsult.
the class SubstanceWriterTest method write.
public int write(SubstanceEndpointsBundle bundle, IRawReader<IStructureRecord> reader, Connection connection, PropertyKey key, boolean splitRecord, boolean clearMeasurements, boolean clearComposition) throws Exception {
DBSubstanceWriter writer;
if (bundle != null)
writer = new DBBundleStudyWriter(bundle, DBSubstanceWriter.datasetMeta(), new SubstanceRecord());
else
writer = new DBSubstanceWriter(DBSubstanceWriter.datasetMeta(), new SubstanceRecord(), clearMeasurements, clearComposition);
writer.setSplitRecord(splitRecord);
writer.setConnection(connection);
writer.open();
int records = 0;
while (reader.hasNext()) {
Object record = reader.next();
if (record == null)
continue;
Assert.assertTrue(record instanceof IStructureRecord);
if (record instanceof SubstanceRecord)
writer.setImportedRecord((SubstanceRecord) record);
writer.process((IStructureRecord) record);
records++;
}
writer.close();
return records;
}
use of ambit2.core.io.IRawReader in project ambit-mirror by ideaconsult.
the class SubstanceWriterTest method testWriteJSONmatrixUpdate.
@Test
public void testWriteJSONmatrixUpdate() throws Exception {
setUpDatabaseFromResource("ambit2/db/processors/test/descriptors-datasets.xml");
IDatabaseConnection c = getConnection();
ITable substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_experiment");
Assert.assertEquals(4, substance.getRowCount());
substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
Assert.assertEquals(1, substance.getRowCount());
substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_protocolapplication");
Assert.assertEquals(4, substance.getRowCount());
try {
IRawReader<IStructureRecord> parser = getJSONReader("matrixupdate.json");
SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(1);
write(bundle, parser, c.getConnection(), new ReferenceSubstanceUUID(), false, false, false);
parser.close();
c = getConnection();
substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
Assert.assertEquals(1, substance.getRowCount());
substance = c.createQueryTable("EXPECTED", "SELECT topcategory,endpointcategory,guidance,interpretation_criteria,reference,studyResultType FROM bundle_substance_protocolapplication where idbundle=1");
// only studies for already existing substances are written
Assert.assertEquals(2, substance.getRowCount());
substance = c.createQueryTable("EXPECTED", "SELECT * FROM bundle_substance_experiment where idbundle=1");
Assert.assertEquals(2, substance.getRowCount());
} finally {
c.close();
}
}
Aggregations