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);
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations