Search in sources :

Example 1 with IRawReader

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);
}
Also used : InputStreamReader(java.io.InputStreamReader) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) IStructureRecord(ambit2.base.interfaces.IStructureRecord) ICiteable(ambit2.base.interfaces.ICiteable) FileReader(java.io.FileReader)

Example 2 with IRawReader

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;
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RepositoryWriter(ambit2.db.processors.RepositoryWriter) SourceDataset(ambit2.base.data.SourceDataset)

Example 3 with IRawReader

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;
}
Also used : DeleteMatrixValue(ambit2.db.update.bundle.matrix.DeleteMatrixValue) ProtocolApplication(ambit2.base.data.study.ProtocolApplication) UpdateExecutor(net.idea.modbcum.p.UpdateExecutor) ValueAnnotated(ambit2.base.data.study.ValueAnnotated) SubstanceRecord(ambit2.base.data.SubstanceRecord) IQueryUpdate(net.idea.modbcum.i.query.IQueryUpdate) ProtocolApplicationAnnotated(ambit2.base.data.study.ProtocolApplicationAnnotated)

Example 4 with IRawReader

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;
}
Also used : DBSubstanceWriter(ambit2.db.substance.processor.DBSubstanceWriter) IStructureRecord(ambit2.base.interfaces.IStructureRecord) DBBundleStudyWriter(ambit2.db.substance.processor.DBBundleStudyWriter) SubstanceRecord(ambit2.base.data.SubstanceRecord)

Example 5 with IRawReader

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();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Aggregations

IStructureRecord (ambit2.base.interfaces.IStructureRecord)29 Test (org.junit.Test)15 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)14 ITable (org.dbunit.dataset.ITable)11 ReferenceSubstanceUUID (ambit2.core.processors.structure.key.ReferenceSubstanceUUID)9 SubstanceRecord (ambit2.base.data.SubstanceRecord)7 DBSubstanceWriter (ambit2.db.substance.processor.DBSubstanceWriter)7 SourceDataset (ambit2.base.data.SourceDataset)6 RepositoryWriter (ambit2.db.processors.RepositoryWriter)5 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)4 IRawReader (ambit2.core.io.IRawReader)4 DbUnitTest (ambit2.db.processors.test.DbUnitTest)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)4 LiteratureEntry (ambit2.base.data.LiteratureEntry)3 StructureRecordValidator (ambit2.base.data.study.StructureRecordValidator)3 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)3