Search in sources :

Example 1 with NoneKey

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

the class RepositoryWriterTest method main.

public static void main(String[] args) {
    if (args == null || args.length == 0)
        System.exit(-1);
    RepositoryWriterTest w = new RepositoryWriterTest();
    File file = new File(args[0]);
    RawIteratingSDFReader reader = null;
    IDatabaseConnection c = null;
    long now = System.currentTimeMillis();
    try {
        w.setUpDatabaseFromResource("ambit2/db/processors/test/empty-datasets.xml");
        c = w.getConnection();
        reader = new RawIteratingSDFReader(new FileReader(file));
        reader.setReference(LiteratureEntry.getInstance(file.getName()));
        w.write(reader, c.getConnection(), new NoneKey(), false, 1000000);
        c.close();
    } catch (Exception x) {
        x.printStackTrace();
    } finally {
        try {
            if (reader != null)
                reader.close();
        } catch (Exception x) {
        }
        try {
            if (c != null)
                c.close();
        } catch (Exception x) {
        }
        System.out.print("Elapsed ");
        System.out.println(System.currentTimeMillis() - now);
    }
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) FileReader(java.io.FileReader) NoneKey(ambit2.core.processors.structure.key.NoneKey) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) File(java.io.File) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with NoneKey

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

the class Context method parseCommandDataset.

protected long parseCommandDataset(long now) throws Exception {
    RawIteratingSDFReader reader = null;
    try {
        File file = new File(options.input);
        reader = new RawIteratingSDFReader(new FileReader(file));
        reader.setReference(LiteratureEntry.getInstance(file.getName()));
        SourceDataset dataset = new SourceDataset(file.getName(), LiteratureEntry.getInstance("File", file.getName()));
        return write(reader, new NoneKey(), dataset, -1);
    } catch (Exception x) {
        throw x;
    } finally {
        logger_cli.log(Level.INFO, "MSG_INFO_COMPLETED", (System.currentTimeMillis() - now));
        try {
            if (reader != null)
                reader.close();
        } catch (Exception x) {
        }
        if (options.output != null) {
            logger_cli.log(Level.INFO, "MSG_INFO_RESULTSWRITTEN", options.output);
        }
    }
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) IteratingDelimitedFileReader(ambit2.core.io.IteratingDelimitedFileReader) FileReader(java.io.FileReader) SourceDataset(ambit2.base.data.SourceDataset) NoneKey(ambit2.core.processors.structure.key.NoneKey) File(java.io.File) 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)

Example 3 with NoneKey

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

the class CallableFinder method createProcessors.

@Override
protected ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> createProcessors() throws Exception {
    ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
    // exactly our
    RetrieveStructure r = new RetrieveStructure(false);
    // structure,
    // nothing else
    r.setPageSize(1);
    r.setPage(0);
    p.add(new ProcessorStructureRetrieval(r));
    IProcessor<IStructureRecord, IStructureRecord> valuesReader = getValuesReader();
    if (valuesReader != null)
        p.add(valuesReader);
    IProcessor<String, String> request;
    LiteratureEntry le;
    switch(searchSite) {
        case PUBCHEM_CID:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.cid));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_SID:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.sid));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_NAME:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.name));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        case PUBCHEM_INCHIKEY:
            {
                p.add(new PubChemRestFinder(getProfile(), mode, COMPOUND_DOMAIN_INPUT.inchikey));
                le = new LiteratureEntry(PUGRestRequest.PUGREST_URL, PUGRestRequest.PUGREST_COMPOUND_URL);
                break;
            }
        /*
		 * case PUBCHEM: { p.add(new PubchemFinder(profile,mode)); le = new
		 * LiteratureEntry("PubChem",EntrezSearchProcessor.entrezURL); break; }
		 */
        case OPENTOX:
            {
                request = new OpenToxRequest(searchSite.getURI());
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        case AMBITLRI:
            {
                request = new OpenToxRequest(searchSite.getURI());
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        case NAME2STRUCTURE:
            {
                p.add(new Name2StructureFinder(getProfile(), mode));
                le = new LiteratureEntry(searchSite.getTitle(), searchSite.getURI());
                break;
            }
        /*
		 * case CHEMBL: { p.add(new ChemBLFinder(profile,mode)); le = new
		 * LiteratureEntry(searchSite.name(),"https://www.ebi.ac.uk/chemblws"); break; }
		 */
        case CHEMIDPLUS:
            {
                request = new ChemIdPlusRequest();
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
        /*
		 * case TBWIKI: { mode = MODE.propertyonly; le = new LiteratureEntry("TBWIKI",
		 * "http://wiki.toxbank.net/wiki/Special:SPARQLEndpoint"); p.add(new
		 * TBWikiFinder(profile, le)); break; }
		 */
        default:
            {
                request = new CSLSStringRequest();
                p.add(new AllSourcesFinder(getProfile(), request, mode));
                le = new LiteratureEntry(request.toString(), request.toString());
                break;
            }
    }
    // don't duplicate if there is already a hit
    SourceDataset dataset = new SourceDataset(searchSite.toString(), le);
    dataset = getDataset(dataset);
    QueryStructureByID q = new QueryStructureByID();
    q.setChemicalsOnly(true);
    q.setFieldname(dataset);
    q.setPageSize(1);
    q.setPage(0);
    p.add(new ProcessorStructureRetrieval(q) {

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

        @Override
        public IStructureRecord process(IStructureRecord target) throws AmbitException {
            if (target == null)
                return null;
            if (((QueryStructureByID) getQuery()).getFieldname().getID() >= 0) {
                IStructureRecord record = super.process(target);
                target.setIdchemical(record.getIdchemical());
                target.setIdstructure(record.getIdstructure());
                return target;
            } else
                return target;
        }
    });
    RepositoryWriter writer = new RepositoryWriter() {

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

        @Override
        public List<IStructureRecord> process(IStructureRecord target) throws AmbitException {
            if (target == null)
                return null;
            return super.process(target);
        }
    };
    if (MODE.propertyonly.equals(mode)) {
        writer.setPropertyKey(new NoneKey());
        writer.setUseExistingStructure(true);
        writer.setOperation(OP.CREATE);
    } else
        writer.setOperation(OP.UPDATE);
    writer.setDataset(dataset);
    p.add(writer);
    return p;
}
Also used : Name2StructureFinder(ambit2.namestructure.Name2StructureFinder) CSLSStringRequest(ambit2.search.csls.CSLSStringRequest) OpenToxRequest(ambit2.search.opentox.OpenToxRequest) LiteratureEntry(ambit2.base.data.LiteratureEntry) IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) RepositoryWriter(ambit2.db.processors.RepositoryWriter) NoneKey(ambit2.core.processors.structure.key.NoneKey) IProcessor(net.idea.modbcum.i.processors.IProcessor) ChemIdPlusRequest(ambit2.search.chemidplus.ChemIdPlusRequest) PubChemRestFinder(ambit2.pubchem.rest.PubChemRestFinder) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) IStructureRecord(ambit2.base.interfaces.IStructureRecord) AllSourcesFinder(ambit2.search.AllSourcesFinder) ProcessorsChain(net.idea.modbcum.i.processors.ProcessorsChain) ProcessorStructureRetrieval(ambit2.db.processors.ProcessorStructureRetrieval) SourceDataset(ambit2.base.data.SourceDataset) RetrieveStructure(ambit2.db.readers.RetrieveStructure) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Aggregations

NoneKey (ambit2.core.processors.structure.key.NoneKey)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 SourceDataset (ambit2.base.data.SourceDataset)2 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)2 File (java.io.File)2 FileReader (java.io.FileReader)2 LiteratureEntry (ambit2.base.data.LiteratureEntry)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 IteratingDelimitedFileReader (ambit2.core.io.IteratingDelimitedFileReader)1 ProcessorStructureRetrieval (ambit2.db.processors.ProcessorStructureRetrieval)1 RepositoryWriter (ambit2.db.processors.RepositoryWriter)1 RetrieveStructure (ambit2.db.readers.RetrieveStructure)1 QueryStructureByID (ambit2.db.search.structure.QueryStructureByID)1 Name2StructureFinder (ambit2.namestructure.Name2StructureFinder)1 PubChemRestFinder (ambit2.pubchem.rest.PubChemRestFinder)1 AllSourcesFinder (ambit2.search.AllSourcesFinder)1 ChemIdPlusRequest (ambit2.search.chemidplus.ChemIdPlusRequest)1 CSLSStringRequest (ambit2.search.csls.CSLSStringRequest)1 OpenToxRequest (ambit2.search.opentox.OpenToxRequest)1 FileNotFoundException (java.io.FileNotFoundException)1