Search in sources :

Example 1 with IChemical

use of ambit2.base.interfaces.IChemical in project ambit-mirror by ideaconsult.

the class Chemical_crud_test method deleteQuery.

@Override
protected IQueryUpdate<Object, IChemical> deleteQuery() throws Exception {
    IChemical c = new StructureRecord();
    c.setIdchemical(10);
    DeleteChemical q = new DeleteChemical(c);
    q.setForceStructureDelete(true);
    return q;
}
Also used : DeleteChemical(ambit2.db.update.chemical.DeleteChemical) StructureRecord(ambit2.base.data.StructureRecord) IChemical(ambit2.base.interfaces.IChemical)

Example 2 with IChemical

use of ambit2.base.interfaces.IChemical in project ambit-mirror by ideaconsult.

the class Chemical_crud_test method createQueryNew.

protected IQueryUpdate<Object, IChemical> createQueryNew() throws Exception {
    IChemical c = new StructureRecord();
    c.setSmiles("CCC");
    c.setInchi("inchi");
    c.setFormula("formula");
    c.setInchiKey("key");
    return new CreateChemical(c);
}
Also used : CreateChemical(ambit2.db.update.chemical.CreateChemical) StructureRecord(ambit2.base.data.StructureRecord) IChemical(ambit2.base.interfaces.IChemical)

Example 3 with IChemical

use of ambit2.base.interfaces.IChemical in project ambit-mirror by ideaconsult.

the class Chemical_crud_test method updateQuery.

@Override
protected IQueryUpdate<Object, IChemical> updateQuery() throws Exception {
    IChemical c = new StructureRecord();
    c.setSmiles("CCC");
    c.setInchi("inchi");
    c.setFormula("formula");
    c.setInchiKey("key");
    c.setIdchemical(10);
    return new UpdateChemical(c);
}
Also used : UpdateChemical(ambit2.db.update.chemical.UpdateChemical) StructureRecord(ambit2.base.data.StructureRecord) IChemical(ambit2.base.interfaces.IChemical)

Example 4 with IChemical

use of ambit2.base.interfaces.IChemical in project ambit-mirror by ideaconsult.

the class Context method parseCommandPreprocessing.

public void parseCommandPreprocessing() throws Exception {
    int pagesize = parsePageSizeParam();
    Set<FPTable> preprocessingOption = new TreeSet<FPTable>();
    /*
		 * try { if ((Boolean)options.getParam(":pubchemfp"))
		 * preprocessingOption.add(FPTable.pc1024); } catch (Exception x) {
		 * x.printStackTrace(); }
		 */
    _preprocessingoptions[] po = _preprocessingoptions.values();
    for (_preprocessingoptions p : po) try {
        if ((Boolean) options.getParam(p.toString())) {
            FPTable[] to = p.getOption();
            for (FPTable t : to) preprocessingOption.add(t);
        }
    } catch (Exception x) {
        logger_cli.log(Level.WARNING, x.toString());
    }
    DbReader<IStructureRecord> batch = new DbReader<IStructureRecord>() {

        /**
         */
        private static final long serialVersionUID = 6777121852891369530L;

        @Override
        public void onItemRead(IStructureRecord input, IBatchStatistics stats) {
            super.onItemRead(input, stats);
            if ((stats.getRecords(RECORDS_STATS.RECORDS_READ) % 5000) == 0)
                try {
                    logger_cli.log(Level.INFO, stats.toString());
                    getConnection().commit();
                } catch (Exception x) {
                    logger_cli.log(Level.WARNING, x.getMessage());
                }
        }

        @Override
        public void onError(IStructureRecord input, Object output, IBatchStatistics stats, Exception x) {
            super.onError(input, output, stats, x);
            logger_cli.log(Level.SEVERE, x.getMessage());
        }
    };
    batch.setProcessorChain(new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>());
    /* structure */
    RetrieveStructure queryP = new RetrieveStructure(true);
    queryP.setFieldname(true);
    queryP.setPageSize(1);
    queryP.setPage(0);
    MasterDetailsProcessor<IStructureRecord, IStructureRecord, IQueryCondition> strucReader = new MasterDetailsProcessor<IStructureRecord, IStructureRecord, IQueryCondition>(queryP) {

        /**
         */
        private static final long serialVersionUID = -5350168222668294207L;

        @Override
        protected void configureQuery(IStructureRecord target, IParameterizedQuery<IStructureRecord, IStructureRecord, IQueryCondition> query) throws AmbitException {
            query.setValue(target);
        // super.configureQuery(target, query);
        }

        @Override
        protected IStructureRecord processDetail(IStructureRecord master, IStructureRecord detail) throws Exception {
            master.setContent(detail.getContent());
            master.setFormat(detail.getFormat());
            master.setType(detail.getType());
            return master;
        }
    };
    strucReader.setCloseConnection(false);
    batch.getProcessorChain().add(strucReader);
    // preprocessing itself
    // query
    IQueryRetrieval<IStructureRecord> query = null;
    AbstractUpdate updateQuery = null;
    if (preprocessingOption.isEmpty())
        preprocessingOption.add(FPTable.inchi);
    if (preprocessingOption.contains(FPTable.inchi)) {
        query = new MissingInChIsQuery("UNKNOWN");
        updateQuery = new UpdateChemical();
        batch.getProcessorChain().add(new DefaultAmbitProcessor<IStructureRecord, IStructureRecord>() {

            /**
             */
            private static final long serialVersionUID = -7628269103516836861L;

            protected transient StructureNormalizer normalizer = new StructureNormalizer();

            @Override
            public IStructureRecord process(IStructureRecord record) throws Exception {
                try {
                    normalizer.process(record);
                    return record;
                } catch (Exception x) {
                    record.setType(STRUC_TYPE.NA);
                    return record;
                }
            }
        });
        batch.getProcessorChain().add(new AbstractUpdateProcessor<Object, IChemical>(OP.CREATE, updateQuery) {

            /**
             */
            private static final long serialVersionUID = 9019409150445247686L;

            @Override
            protected IChemical execute(Object group, IQueryUpdate<Object, IChemical> query) throws SQLException, OperationNotSupportedException, AmbitException {
                if (group instanceof IChemical)
                    query.setObject((IChemical) group);
                return super.execute(group, query);
            }
        });
    } else {
        // add generators
        if (preprocessingOption.contains(FPTable.smarts_accelerator)) {
            query = new MissingFingerprintsQuery(FPTable.smarts_accelerator);
            batch.getProcessorChain().add(new SMARTSPropertiesGenerator());
        }
        if (preprocessingOption.contains(FPTable.fp1024)) {
            query = new FingerprintsByStatus(FPTable.fp1024);
            // updateQuery = new CreateFingerprintChemical(FPTable.fp1024);
            batch.getProcessorChain().add(new BitSetGenerator(FPTable.fp1024));
        }
        if (preprocessingOption.contains(FPTable.sk1024)) {
            query = new FingerprintsByStatus(FPTable.sk1024);
            batch.getProcessorChain().add(new BitSetGenerator(FPTable.sk1024));
        }
        // add writers
        if (preprocessingOption.contains(FPTable.smarts_accelerator)) {
            batch.getProcessorChain().add(new SMARTSAcceleratorWriter());
        }
        if (preprocessingOption.contains(FPTable.fp1024)) {
            batch.getProcessorChain().add(new FP1024Writer(FPTable.fp1024));
        }
        if (preprocessingOption.contains(FPTable.sk1024)) {
            batch.getProcessorChain().add(new FP1024Writer(FPTable.sk1024));
        }
        if (preprocessingOption.contains(FPTable.cf1024)) {
            query = new FingerprintsByStatus(FPTable.cf1024);
            batch.getProcessorChain().add(new BitSetGenerator(FPTable.cf1024));
            batch.getProcessorChain().add(new FP1024Writer(FPTable.cf1024));
        }
    }
    batch.setHandlePrescreen(false);
    Connection c = null;
    DBConnectionConfigurable<Context> dbc = null;
    dbc = getConnection(options.getSQLConfig());
    c = dbc.getConnection();
    c.setAutoCommit(false);
    batch.setCloseConnection(true);
    batch.setConnection(c);
    batch.open();
    IBatchStatistics stats = null;
    try {
        query.setPageSize(pagesize);
        logger_cli.info(query.getSQL());
        try {
            disableIndices(batch.getConnection());
        } catch (Exception x) {
            logger_cli.warning(x.getMessage());
        }
        logger_cli.log(Level.INFO, "MSG_INFO_QUERY", pagesize);
        stats = batch.process(query);
    } catch (Exception x) {
        logger_cli.log(Level.WARNING, x.getMessage(), x);
    } finally {
        try {
            batch.getConnection().commit();
        } catch (Exception x) {
            logger_cli.warning(x.getMessage());
        }
        try {
            enableIndices(batch.getConnection());
        } catch (Exception x) {
            logger_cli.warning(x.getMessage());
        }
        try {
            if (batch != null)
                batch.close();
        } catch (Exception x) {
            logger_cli.warning(x.getMessage());
        }
        if (stats != null)
            logger_cli.log(Level.INFO, stats.toString());
    }
}
Also used : IQueryCondition(net.idea.modbcum.i.IQueryCondition) StructureNormalizer(ambit2.core.processors.StructureNormalizer) SQLException(java.sql.SQLException) CliOptions._preprocessingoptions(ambit2.dbcli.CliOptions._preprocessingoptions) SMARTSPropertiesGenerator(ambit2.smarts.processors.SMARTSPropertiesGenerator) IParameterizedQuery(net.idea.modbcum.i.IParameterizedQuery) UpdateChemical(ambit2.db.update.chemical.UpdateChemical) IStructureRecord(ambit2.base.interfaces.IStructureRecord) BitSetGenerator(ambit2.descriptors.processors.BitSetGenerator) MissingInChIsQuery(ambit2.db.search.structure.MissingInChIsQuery) TreeSet(java.util.TreeSet) MasterDetailsProcessor(net.idea.modbcum.p.MasterDetailsProcessor) MissingFingerprintsQuery(ambit2.db.search.structure.MissingFingerprintsQuery) RetrieveStructure(ambit2.db.readers.RetrieveStructure) DbReader(ambit2.db.DbReader) OperationNotSupportedException(javax.naming.OperationNotSupportedException) FPTable(ambit2.descriptors.processors.FPTable) SMARTSAcceleratorWriter(ambit2.db.update.qlabel.smarts.SMARTSAcceleratorWriter) FP1024Writer(ambit2.db.processors.FP1024Writer) IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) MySQLSingleConnection(net.idea.modbcum.c.MySQLSingleConnection) Connection(java.sql.Connection) IProcessor(net.idea.modbcum.i.processors.IProcessor) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) AbstractUpdate(net.idea.modbcum.q.update.AbstractUpdate) IChemical(ambit2.base.interfaces.IChemical) FingerprintsByStatus(ambit2.db.search.structure.FingerprintsByStatus) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 5 with IChemical

use of ambit2.base.interfaces.IChemical in project ambit-mirror by ideaconsult.

the class Chemical_crud_test method createQuery.

@Override
protected IQueryUpdate<Object, IChemical> createQuery() throws Exception {
    IChemical c = new StructureRecord();
    c.setIdchemical(7);
    c.setSmiles("CCC");
    c.setInchi("inchi");
    c.setFormula("formula");
    c.setInchiKey("inchi-key");
    return new CreateChemical(c);
}
Also used : CreateChemical(ambit2.db.update.chemical.CreateChemical) StructureRecord(ambit2.base.data.StructureRecord) IChemical(ambit2.base.interfaces.IChemical)

Aggregations

IChemical (ambit2.base.interfaces.IChemical)6 StructureRecord (ambit2.base.data.StructureRecord)5 UpdateChemical (ambit2.db.update.chemical.UpdateChemical)3 CreateChemical (ambit2.db.update.chemical.CreateChemical)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 StructureNormalizer (ambit2.core.processors.StructureNormalizer)1 DbReader (ambit2.db.DbReader)1 FP1024Writer (ambit2.db.processors.FP1024Writer)1 RetrieveStructure (ambit2.db.readers.RetrieveStructure)1 FingerprintsByStatus (ambit2.db.search.structure.FingerprintsByStatus)1 MissingFingerprintsQuery (ambit2.db.search.structure.MissingFingerprintsQuery)1 MissingInChIsQuery (ambit2.db.search.structure.MissingInChIsQuery)1 DeleteChemical (ambit2.db.update.chemical.DeleteChemical)1 SMARTSAcceleratorWriter (ambit2.db.update.qlabel.smarts.SMARTSAcceleratorWriter)1 CliOptions._preprocessingoptions (ambit2.dbcli.CliOptions._preprocessingoptions)1 BitSetGenerator (ambit2.descriptors.processors.BitSetGenerator)1 FPTable (ambit2.descriptors.processors.FPTable)1 SMARTSPropertiesGenerator (ambit2.smarts.processors.SMARTSPropertiesGenerator)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1