Search in sources :

Example 1 with QuerySimilarityBitset

use of ambit2.db.search.structure.QuerySimilarityBitset in project ambit-mirror by ideaconsult.

the class SimilarityResource method createQuery.

@Override
protected Q createQuery(Context context, Request request, Response response) throws ResourceException {
    Form form = getResourceRef(getRequest()).getQueryAsForm();
    try {
        Object bundleURI = OpenTox.params.bundle_uri.getFirstValue(form);
        Integer idbundle = bundleURI == null ? null : getIdBundle(bundleURI, request);
        SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(idbundle);
        bundles = new SubstanceEndpointsBundle[1];
        bundles[0] = bundle;
    } catch (Exception x) {
        bundles = null;
    }
    try {
        includeMol = "true".equals(form.getFirstValue("mol"));
    } catch (Exception x) {
        includeMol = false;
    }
    folders = form.getValuesArray("folder");
    filterBySubstance = false;
    try {
        String filter = form.getFirstValue("filterBySubstance");
        if (filter != null) {
            filter = filter.toLowerCase();
            filterBySubstance = "yes".equals(filter) || "on".equals(filter) || "true".equals(filter);
        }
    } catch (Exception x) {
        filterBySubstance = false;
    }
    QueryAtomEnvironment.q_modifier ae = null;
    try {
        String filter = form.getFirstValue("mode");
        if (filter != null) {
            filter = filter.toLowerCase();
            ae = QueryAtomEnvironment.q_modifier.valueOf(filter.replace("ae", ""));
        }
    } catch (Exception x) {
        ae = null;
    }
    mol = getMolecule(form);
    if ((mol == null) || (mol.getAtomCount() == 0))
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Empty molecule");
    threshold = 0.0;
    try {
        threshold = new Double(Reference.decode(form.getFirstValue("threshold")));
    } catch (Exception x) {
        threshold = 0.9;
    }
    QuerySimilarity q = null;
    if (ae != null) {
        q = new QueryAtomEnvironment(ae);
        try {
            q.setValue(getAE(mol));
        } catch (Exception x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
        }
    } else
        try {
            q = new QuerySimilarityBitset();
            q.setValue(getBitset(mol));
        } catch (Exception x) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x);
        }
    q.setChemicalsOnly(true);
    q.setThreshold(threshold);
    q.setCondition(NumberCondition.getInstance(">"));
    q.setName("Similarity");
    try {
        q.setForceOrdering(((AmbitApplication) getApplication()).isSimilarityOrder());
    } catch (Exception x) {
        q.setForceOrdering(true);
    }
    try {
        if (filterBySubstance) {
            ChemicalBySubstanceRelation qa = new ChemicalBySubstanceRelation();
            QueryCombinedStructure qc = new QueryCombinedStructure();
            qc.add(q);
            qc.setChemicalsOnly(true);
            qc.setScope(qa);
            setTemplate(createTemplate(context, request, response));
            setGroupProperties(context, request, response);
            return (Q) qc;
        } else if ((folders != null) && (folders.length > 0)) {
            ChemicalByQueryFolder qa = new ChemicalByQueryFolder(folders);
            QueryCombinedStructure qc = new QueryCombinedStructure();
            qc.add(q);
            qc.setChemicalsOnly(true);
            qc.setScope(qa);
            setTemplate(createTemplate(context, request, response));
            setGroupProperties(context, request, response);
            return (Q) qc;
        } else {
            Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
            ISourceDataset srcdataset = null;
            if (datasetURI != null)
                try {
                    srcdataset = getDataset(datasetURI.toString());
                    QueryCombinedStructure qc = new QueryCombinedStructure();
                    qc.add(q);
                    qc.setChemicalsOnly(true);
                    if (srcdataset instanceof SourceDataset) {
                        ChemicalByDataset cd = new ChemicalByDataset(new Integer(srcdataset.getID()));
                        qc.setScope(cd);
                        setTemplate(createTemplate(context, request, response));
                        setGroupProperties(context, request, response);
                        return (Q) qc;
                    } else {
                    // TODO, resort to all db
                    }
                } catch (Exception x) {
                    srcdataset = null;
                }
            QueryCombinedStructure qc = null;
            try {
                this.dataset_id = Reference.decode(getRequest().getAttributes().get(DatasetResource.datasetKey).toString());
                qc = new QueryCombinedStructure();
                qc.add(q);
                qc.setChemicalsOnly(true);
                ChemicalByDataset cd = new ChemicalByDataset(new Integer(dataset_id));
                qc.setScope(cd);
                setTemplate(createTemplate(context, request, response));
                setGroupProperties(context, request, response);
                return (Q) qc;
            } catch (Exception x) {
                setTemplate(createTemplate(context, request, response));
                setGroupProperties(context, request, response);
                return (Q) q;
            }
        }
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x);
    }
}
Also used : ChemicalByQueryFolder(ambit2.db.search.structure.ChemicalByQueryFolder) QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) Form(org.restlet.data.Form) ChemicalBySubstanceRelation(ambit2.db.substance.relation.ChemicalBySubstanceRelation) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) InvalidResourceIDException(ambit2.rest.error.InvalidResourceIDException) QueryAtomEnvironment(ambit2.db.search.structure.QueryAtomEnvironment) ISourceDataset(ambit2.base.data.ISourceDataset) ChemicalByDataset(ambit2.db.update.structure.ChemicalByDataset) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) ResourceException(org.restlet.resource.ResourceException) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) QuerySimilarity(ambit2.db.search.structure.QuerySimilarity) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure)

Example 2 with QuerySimilarityBitset

use of ambit2.db.search.structure.QuerySimilarityBitset in project ambit-mirror by ideaconsult.

the class QueryInfo2Query method createQuerySimilarity.

protected QuerySimilarityBitset createQuerySimilarity(QueryInfo target) throws AmbitException {
    if (QueryInfo.METHOD_SIMILARITY.equals(target.getMethod())) {
        if (target.getMolecule() == null)
            return null;
        FingerprintGenerator g = new FingerprintGenerator(new Fingerprinter());
        BitSet bitset = g.process(target.getMolecule());
        QuerySimilarityBitset qs = new QuerySimilarityBitset();
        qs.setValue(bitset);
        qs.setThreshold(target.getThreshold());
        return qs;
    } else
        return null;
}
Also used : QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter) BitSet(java.util.BitSet) QueryPrescreenBitSet(ambit2.db.search.structure.QueryPrescreenBitSet) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator)

Example 3 with QuerySimilarityBitset

use of ambit2.db.search.structure.QuerySimilarityBitset in project ambit-mirror by ideaconsult.

the class QueryCombinedScopeTest method createQuery.

@Override
protected QueryCombinedStructure createQuery() throws Exception {
    /*
		 * QuerySimilarityBitset q = new QuerySimilarityBitset();
		 * FingerprintGenerator gen = new FingerprintGenerator(); BitSet bitset
		 * = gen.process(MoleculeFactory.makeAlkane(10)); q.setValue(bitset);
		 */
    QueryStructure q = new QueryStructure();
    q.setFieldname(ExactStructureSearchMode.smiles);
    q.setValue("CCCCC(CC)C(=O)[O-].CCCCC(CC)C(=O)[O-].[SnH4+2]");
    ProcessorSetQueryScope p = new ProcessorSetQueryScope();
    p.setQuery(q);
    StoredQuery storedQuery = new StoredQuery();
    storedQuery.setId(1);
    QueryStoredResults query_results = new QueryStoredResults();
    query_results.setFieldname(storedQuery);
    return (QueryCombinedStructure) p.process(query_results);
}
Also used : StoredQuery(ambit2.db.search.StoredQuery) ProcessorSetQueryScope(ambit2.db.processors.ProcessorSetQueryScope) QueryStructure(ambit2.db.search.structure.QueryStructure) QueryStoredResults(ambit2.db.search.structure.QueryStoredResults) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure)

Example 4 with QuerySimilarityBitset

use of ambit2.db.search.structure.QuerySimilarityBitset in project ambit-mirror by ideaconsult.

the class QueryCombinedTest method testStructure.

@Test
public void testStructure() throws Exception {
    QueryCombined qc = new QueryCombinedStructure();
    qc.setId(55);
    QuerySimilarityBitset q = new QuerySimilarityBitset();
    FingerprintGenerator gen = new FingerprintGenerator(new Fingerprinter());
    BitSet bitset = gen.process(MoleculeFactory.makeAlkane(10));
    q.setValue(bitset);
    Assert.assertNotNull(q.getParameters().get(1).getValue());
    qc.add(q);
}
Also used : QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter) BitSet(java.util.BitSet) QueryCombined(ambit2.db.search.QueryCombined) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) Test(org.junit.Test)

Example 5 with QuerySimilarityBitset

use of ambit2.db.search.structure.QuerySimilarityBitset in project ambit-mirror by ideaconsult.

the class QuerySimilarityBitSetTest method createQuery.

@Override
protected QuerySimilarityBitset createQuery() throws Exception {
    Fingerprinter fp = new Fingerprinter();
    QuerySimilarityBitset qf = new QuerySimilarityBitset();
    qf.setValue(fp.getBitFingerprint(MoleculeFactory.makeAlkane(3)).asBitSet());
    qf.setCondition(NumberCondition.getInstance(">"));
    qf.setThreshold(0.24);
    qf.setId(1);
    return qf;
}
Also used : QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter)

Aggregations

QuerySimilarityBitset (ambit2.db.search.structure.QuerySimilarityBitset)5 QueryCombinedStructure (ambit2.db.search.structure.QueryCombinedStructure)4 Fingerprinter (org.openscience.cdk.fingerprint.Fingerprinter)3 FingerprintGenerator (ambit2.core.processors.structure.FingerprintGenerator)2 QueryPrescreenBitSet (ambit2.db.search.structure.QueryPrescreenBitSet)2 QueryStoredResults (ambit2.db.search.structure.QueryStoredResults)2 QueryStructure (ambit2.db.search.structure.QueryStructure)2 BitSet (java.util.BitSet)2 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)2 ISourceDataset (ambit2.base.data.ISourceDataset)1 SourceDataset (ambit2.base.data.SourceDataset)1 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)1 ProcessorSetQueryScope (ambit2.db.processors.ProcessorSetQueryScope)1 QueryCombined (ambit2.db.search.QueryCombined)1 StoredQuery (ambit2.db.search.StoredQuery)1 ChemicalByQueryFolder (ambit2.db.search.structure.ChemicalByQueryFolder)1 QueryAtomEnvironment (ambit2.db.search.structure.QueryAtomEnvironment)1 QueryDataset (ambit2.db.search.structure.QueryDataset)1 QueryField (ambit2.db.search.structure.QueryField)1 QuerySimilarity (ambit2.db.search.structure.QuerySimilarity)1