Search in sources :

Example 1 with RawIteratingWrapper

use of ambit2.core.io.RawIteratingWrapper in project ambit-mirror by ideaconsult.

the class ProteinCoronaPaperReaderTest method test.

@Test
public void test() throws Exception {
    RawIteratingWrapper reader = null;
    try {
        LiteratureEntry entry = new LiteratureEntry("Protein Corona", "http://dx.doi.org/10.1021/nn406018q");
        entry.setType(_type.Dataset);
        File baseDir = new File(System.getProperty("java.io.tmpdir"));
        File datafile = new File(baseDir, "MergedSheets.csv");
        if (!datafile.exists()) {
            URL url = new URL("https://raw.githubusercontent.com/ideaconsult/Protein_Corona/master/MergedSheets.csv");
            DownloadTool.download(url, datafile);
        }
        CSV12Reader chemObjectReader = new CSV12Reader(new FileReader(datafile), entry, "PRCR-");
        reader = new CSV12SubstanceReader(chemObjectReader);
        int r = 0;
        while (reader.hasNext()) {
            IStructureRecord mol = reader.nextRecord();
            Assert.assertTrue(mol instanceof SubstanceRecord);
            System.out.println(((SubstanceRecord) mol).getPublicName());
            System.out.println(((SubstanceRecord) mol).getMeasurements());
            r++;
        }
        Assert.assertTrue(r >= 120);
    } finally {
        reader.close();
    }
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) LiteratureEntry(ambit2.base.data.LiteratureEntry) ILiteratureEntry(ambit2.base.data.ILiteratureEntry) CSV12Reader(net.idea.loom.nm.csv.CSV12Reader) SubstanceRecord(ambit2.base.data.SubstanceRecord) FileReader(java.io.FileReader) File(java.io.File) URL(java.net.URL) CSV12SubstanceReader(net.idea.loom.nm.csv.CSV12SubstanceReader) DbUnitTest(ambit2.db.processors.test.DbUnitTest) Test(org.junit.Test)

Example 2 with RawIteratingWrapper

use of ambit2.core.io.RawIteratingWrapper in project ambit-mirror by ideaconsult.

the class RawIteratingWrapperTest method test.

@Test
public void test() throws Exception {
    IIteratingChemObjectReader reader = FileInputState.getReader(RawIteratingWrapperTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/io/test.txt"), "test.txt");
    Assert.assertTrue(reader != null);
    // Assert.assertTrue(reader instanceof IteratingDelimitedFileReader);
    RawIteratingWrapper wrapper = new RawIteratingWrapper(reader);
    int count = 0;
    while (wrapper.hasNext()) {
        IStructureRecord record = (IStructureRecord) wrapper.next();
        count++;
    }
    Assert.assertEquals(11, count);
    wrapper.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) Test(org.junit.Test)

Example 3 with RawIteratingWrapper

use of ambit2.core.io.RawIteratingWrapper in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testWriteBCFFormat.

@Test
public void testWriteBCFFormat() 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/test/bcf.xls");
    Assert.assertNotNull(in);
    RawIteratingWrapper reader = new RawIteratingWrapper(new EurasBCFReader(in, 0));
    // reader.setReference(LiteratureEntry.getInstance("input.sdf"));
    write(reader, c.getConnection());
    c.close();
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(17, 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(0, chemicals.getRowCount());
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(28, 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(28, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM catalog_references");
    Assert.assertEquals(17, property.getRowCount());
    // was 37
    int n = 36;
    property = c.createQueryTable("EXPECTED", "SELECT name,count(idreference) as c FROM properties  group by name");
    Assert.assertEquals(n, property.getRowCount());
    for (int i = 0; i < n; i++) {
        Assert.assertEquals(new BigInteger("14"), property.getValue(i, "c"));
    }
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    // was 518
    Assert.assertEquals(504, property.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(28 * n, property_values.getRowCount());
    srcdataset = c.createQueryTable("EXPECTED", "SELECT * FROM src_dataset join template_def using(idtemplate) where name='TEST INPUT'");
    Assert.assertEquals(504, 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
 */
}
Also used : RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) InputStream(java.io.InputStream) EurasBCFReader(ambit2.core.io.bcf.EurasBCFReader) BigInteger(java.math.BigInteger) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 4 with RawIteratingWrapper

use of ambit2.core.io.RawIteratingWrapper in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testWriteTXT.

public void testWriteTXT() 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/txt/test.txt");
    Assert.assertNotNull(in);
    IIteratingChemObjectReader reader1 = FileInputState.getReader(in, "test.txt");
    RawIteratingWrapper reader = new RawIteratingWrapper(reader1);
    reader.setReference(LiteratureEntry.getInstance("test.txt"));
    write(reader, c.getConnection());
    c.close();
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    // 8 or 9
    Assert.assertEquals(9, 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(9, chemicals.getRowCount());
    strucs = c.createQueryTable("EXPECTED", "SELECT * FROM structure");
    Assert.assertEquals(9, strucs.getRowCount());
    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"));
    struc_src = c.createQueryTable("EXPECTED", "SELECT * FROM struc_dataset");
    Assert.assertEquals(9, struc_src.getRowCount());
    property = c.createQueryTable("EXPECTED", "SELECT * FROM properties");
    Assert.assertEquals(5, property.getRowCount());
    // verifies if insert_property_tuple works ok
    property = c.createQueryTable("EXPECTED", "SELECT * FROM template_def join src_dataset using(idtemplate) where name='TEST INPUT'");
    Assert.assertEquals(5, property.getRowCount());
    property_values = c.createQueryTable("EXPECTED", "SELECT * FROM property_values");
    Assert.assertEquals(45, property_values.getRowCount());
    ITable tuples = c.createQueryTable("EXPECTED", "SELECT * FROM tuples");
    Assert.assertEquals(9, tuples.getRowCount());
    ITable p_tuples = c.createQueryTable("EXPECTED", "SELECT * FROM property_tuples");
    Assert.assertEquals(45, p_tuples.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
 */
}
Also used : RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) InputStream(java.io.InputStream) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection)

Example 5 with RawIteratingWrapper

use of ambit2.core.io.RawIteratingWrapper in project ambit-mirror by ideaconsult.

the class RepositoryWriterTest method testImport3Same.

@Test
public void testImport3Same() throws Exception {
    setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
    IDatabaseConnection c = getConnection();
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/match/99-72-9.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(2, strucs.getRowCount());
    ITable srcdataset = c.createQueryTable("EXPECTED", "SELECT id_srcdataset,idtemplate FROM src_dataset where name='TEST INPUT'");
    Assert.assertEquals(1, srcdataset.getRowCount());
    in = this.getClass().getClassLoader().getResourceAsStream("ambit2/db/processors/match/99-72-9.csv");
    Assert.assertNotNull(in);
    IIteratingChemObjectReader reader1 = FileInputState.getReader(in, "99-72-9.csv");
    RawIteratingWrapper wrapper = new RawIteratingWrapper(reader1);
    wrapper.setReference(LiteratureEntry.getInstance("input.csv"));
    write(wrapper, c.getConnection());
    c = getConnection();
    chemicals = c.createQueryTable("EXPECTED", "SELECT * FROM chemicals");
    Assert.assertEquals(3, chemicals.getRowCount());
    // Should be 2, but structures from SDF and SMILES come with different
    // stereo ...
    // Assert.assertEquals(2,chemicals.getRowCount());
    c.close();
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) RawIteratingWrapper(ambit2.core.io.RawIteratingWrapper) IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) InputStream(java.io.InputStream) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Aggregations

RawIteratingWrapper (ambit2.core.io.RawIteratingWrapper)6 InputStream (java.io.InputStream)5 Test (org.junit.Test)5 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)5 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)4 ITable (org.dbunit.dataset.ITable)4 IStructureRecord (ambit2.base.interfaces.IStructureRecord)3 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)3 InputStreamReader (java.io.InputStreamReader)3 File (java.io.File)2 ILiteratureEntry (ambit2.base.data.ILiteratureEntry)1 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 SubstanceRecord (ambit2.base.data.SubstanceRecord)1 AmbitIOException (ambit2.base.exceptions.AmbitIOException)1 FileInputState (ambit2.core.io.FileInputState)1 RawIteratingCSVReader (ambit2.core.io.RawIteratingCSVReader)1 RawIteratingFolderReader (ambit2.core.io.RawIteratingFolderReader)1 RawIteratingMOLReader (ambit2.core.io.RawIteratingMOLReader)1 EurasBCFReader (ambit2.core.io.bcf.EurasBCFReader)1 CASKey (ambit2.core.processors.structure.key.CASKey)1