Search in sources :

Example 1 with PubChemRestFinder

use of ambit2.pubchem.rest.PubChemRestFinder 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

LiteratureEntry (ambit2.base.data.LiteratureEntry)1 SourceDataset (ambit2.base.data.SourceDataset)1 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 NoneKey (ambit2.core.processors.structure.key.NoneKey)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 IBatchStatistics (net.idea.modbcum.i.batch.IBatchStatistics)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 IProcessor (net.idea.modbcum.i.processors.IProcessor)1 ProcessorsChain (net.idea.modbcum.i.processors.ProcessorsChain)1