Search in sources :

Example 1 with ReferenceSubstanceUUID

use of ambit2.core.processors.structure.key.ReferenceSubstanceUUID 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)

Example 2 with ReferenceSubstanceUUID

use of ambit2.core.processors.structure.key.ReferenceSubstanceUUID in project ambit-mirror by ideaconsult.

the class SubstanceWriterTest method testWriteJSONStudies.

@Test
public void testWriteJSONStudies() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    ITable substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_experiment");
    Assert.assertEquals(0, substance.getRowCount());
    substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
    Assert.assertEquals(0, substance.getRowCount());
    substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_protocolapplication");
    Assert.assertEquals(0, substance.getRowCount());
    try {
        IRawReader<IStructureRecord> parser = getJSONReader("study.json");
        write(null, parser, c.getConnection(), new ReferenceSubstanceUUID(), false, false, false);
        parser.close();
        c = getConnection();
        substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
        Assert.assertEquals(2, substance.getRowCount());
        substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_protocolapplication");
        Assert.assertEquals(7, substance.getRowCount());
        substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance_experiment");
        Assert.assertEquals(21, substance.getRowCount());
    } finally {
        c.close();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 3 with ReferenceSubstanceUUID

use of ambit2.core.processors.structure.key.ReferenceSubstanceUUID in project ambit-mirror by ideaconsult.

the class I5SubstanceWriterTest 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());
    /**
     * Now reading only substances and reference substances Document types:
     * EndpointStudyRecord: 877 AttachmentDocument: 5 LegalEntity: 1
     * ReferenceSubstance: 6 Substance: 1 EndpointRecord: 14
     */
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/substance/testNM.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-efdb21bb-e79f-3286-a988-b6f6944d3734.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-e2b69497-1c50-3d0b-a2b2-41d0a4d74c54.i5z");
    // InputStream in =
    // I5AmbitProcessor.class.getClassLoader().getResourceAsStream("net/idea/i5/_5/substance/i5z/IUC4-f5dd46ce-6fc9-316f-a468-c4f9acfcfc3c.i5z");
    Assert.assertNotNull(in);
    File i5z = File.createTempFile("test_", ".i5z");
    try {
        DownloadTool.download(in, i5z);
    } finally {
        in.close();
    }
    Assert.assertTrue(i5z.exists());
    I5ZReader reader = null;
    int records = 0;
    try {
        reader = new I5ZReader(i5z);
        QASettings qa = new QASettings(false);
        qa.setAll();
        reader.setQASettings(qa);
        PropertyKey key = new ReferenceSubstanceUUID();
        records = write(null, reader, c.getConnection(), key, true, false, false);
    } finally {
        try {
            reader.close();
        } catch (Exception x) {
        }
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            i5z.delete();
        } catch (Exception x) {
        }
    }
    Assert.assertEquals(8, records);
    c = getConnection();
    ITable substance = c.createQueryTable("EXPECTED", "SELECT * FROM substance");
    Assert.assertEquals(1, substance.getRowCount());
    Assert.assertNotNull(substance.getValue(0, "uuid"));
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(1, chemicals.getRowCount());
    // there are two empty file without $$$$ sign, which are skipped
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(1, strucs.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset where name='IUCLID5 .i5z file'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(1, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM substance_protocolapplication where topcategory='P-CHEM' and endpointcategory='ASPECT_RATIO_SHAPE_SECTION' and interpretation_result='spherical'");
    Assert.assertEquals(1, property.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM substance_experiment where topcategory='P-CHEM' and endpointcategory='ASPECT_RATIO_SHAPE_SECTION'");
    Assert.assertEquals(4, property.getRowCount());
    c.close();
}
Also used : ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) InputStream(java.io.InputStream) QASettings(net.idea.i5.io.QASettings) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) I5ZReader(net.idea.i5.io.I5ZReader) File(java.io.File) PropertyKey(ambit2.core.processors.structure.key.PropertyKey) Test(org.junit.Test)

Example 4 with ReferenceSubstanceUUID

use of ambit2.core.processors.structure.key.ReferenceSubstanceUUID in project ambit-mirror by ideaconsult.

the class ISATABImportTest method testWriteISATAB.

@Test
public void testWriteISATAB() throws Exception {
    setUpDatabase("src/test/resources/ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    IRawReader<IStructureRecord> parser = null;
    try {
        LiteratureEntry entry = new LiteratureEntry("ISA-TAB", "test");
        entry.setType(_type.Dataset);
        String root = "C://ToxBank//ISAcreator.SEURAT-v1.7.2//ISAcreator.SEURAT";
        // String investigation = root + "//isatab files//BII-I-1";
        String investigation = root + "//isatab files//qHTSexample";
        ISAConfigurationSet.setConfigPath(root + "//Configurations/toxbank-config");
        parser = new ISAReader(new File(investigation));
        validator = new StructureRecordValidator(investigation, true);
        write(parser, c.getConnection(), new ReferenceSubstanceUUID(), false);
    } finally {
        parser.close();
        c.close();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) LiteratureEntry(ambit2.base.data.LiteratureEntry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) StructureRecordValidator(ambit2.base.data.study.StructureRecordValidator) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) File(java.io.File) ISAReader(net.idea.loom.isa.ISAReader) DbUnitTest(ambit2.db.processors.test.DbUnitTest) Test(org.junit.Test)

Example 5 with ReferenceSubstanceUUID

use of ambit2.core.processors.structure.key.ReferenceSubstanceUUID in project ambit-mirror by ideaconsult.

the class Context method parse.

public boolean parse(String[] args) throws Exception {
    final Options options = createOptions();
    CommandLineParser parser = new PosixParser();
    try {
        CommandLine line = parser.parse(options, args, false);
        if (line.hasOption("h")) {
            printHelp(options, null);
            return false;
        }
        setParserType(getParserType(line));
        try {
            matchByKey = getStructureMatchMode(line).getKey();
        } catch (Exception x) {
            matchByKey = new ReferenceSubstanceUUID();
        }
        setInputFile(getInput(line));
        if (inputFile == null)
            throw new Exception("Missing input file");
        jsonConfig = getJSONConfig(line);
        if ("xslx".equals(getParserType()))
            if (jsonConfig == null)
                throw new Exception("Missing JSON config file, mandatory for importing XLSX!");
        setPrefix(getPrefix(line));
        outputFile = getOutput(line);
        String config = getConfig(line);
        if (config == null || !(new File(config)).exists())
            throw new Exception("Missing database connection config folder");
        setConfig(new File(config));
        setClearComposition(isClearComposition(line));
        setClearMeasurements(isClearMeasurements(line));
        setKeepEffectRecords(isKeepEffectRecords(line));
        setSplitRecord(isSplitRecord(line));
        setAddDefaultComposition(addDefaultComposition(line));
        setUpdated(timestamp_release(line));
        setExpandMap(getExpandMap(line));
        maxRefSubstances = getMaxRefSubstances(line);
        return true;
    } catch (Exception x) {
        x.printStackTrace();
        printHelp(options, x.getMessage());
        throw x;
    } finally {
    }
}
Also used : Options(org.apache.commons.cli.Options) I5Options(net.idea.i5.io.I5Options) CommandLine(org.apache.commons.cli.CommandLine) ReferenceSubstanceUUID(ambit2.core.processors.structure.key.ReferenceSubstanceUUID) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) CommunicationsException(com.mysql.jdbc.CommunicationsException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException)

Aggregations

ReferenceSubstanceUUID (ambit2.core.processors.structure.key.ReferenceSubstanceUUID)12 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)10 Test (org.junit.Test)10 IStructureRecord (ambit2.base.interfaces.IStructureRecord)9 ITable (org.dbunit.dataset.ITable)7 File (java.io.File)5 DbUnitTest (ambit2.db.processors.test.DbUnitTest)3 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)2 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)2 StructureRecordValidator (ambit2.base.data.study.StructureRecordValidator)1 AmbitIOException (ambit2.base.exceptions.AmbitIOException)1 PropertyKey (ambit2.core.processors.structure.key.PropertyKey)1 ImportSubstanceException (ambit2.rest.exception.ImportSubstanceException)1 CommunicationsException (com.mysql.jdbc.CommunicationsException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1