use of ambit2.db.update.structure.ChemicalByDataset 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.update.structure.ChemicalByDataset in project ambit-mirror by ideaconsult.
the class DatasetResource method createQueryIntersection.
protected Q createQueryIntersection(Context context, Request request, Response response) throws ResourceException {
Form form = getResourceRef(request).getQueryAsForm();
String[] datasetsURI = form.getValuesArray(dataset_intersection_uri);
if ((datasetsURI != null) && (datasetsURI.length > 0)) {
QueryCombinedStructure qc = new QueryCombinedStructure() {
/**
*/
private static final long serialVersionUID = -9042008008516030524L;
@Override
protected String getMainSQL() {
return "select idchemical from chemicals\n";
}
@Override
protected String groupBy() {
return "";
}
};
qc.setChemicalsOnly(true);
qc.setCombine_as_and(true);
try {
ChemicalByDataset cd = new ChemicalByDataset(new Integer(getRequest().getAttributes().get(datasetKey).toString()));
qc.add(cd);
} catch (Exception x) {
}
Template t = new Template(String.format("%s%s/{%s}", getRequest().getRootRef(), DatasetStructuresResource.dataset, DatasetStructuresResource.datasetKey));
for (String datasetURI : datasetsURI) {
Map<String, Object> vars = new HashMap<String, Object>();
t.parse(datasetURI, vars);
try {
qc.add(new ChemicalByDataset(new Integer(vars.get(DatasetStructuresResource.datasetKey).toString())));
} catch (Exception x) {
}
}
return (Q) qc;
}
return null;
}
use of ambit2.db.update.structure.ChemicalByDataset in project ambit-mirror by ideaconsult.
the class DatasetResource method createQueryComplement.
/**
* Finds compounds which are in the dataset {dataset_id} , but not in the
* datasets , given in "complement" query Two sets can also be "subtracted".
* The relative complement of A in B (also called the set theoretic
* difference of B and A), denoted by \A, or (B-A) is the set of all
* elements which are members of B, but not members of A
*
* @param context
* @param request
* @param response
* @return
* @throws ResourceException
*/
protected Q createQueryComplement(Context context, Request request, Response response) throws ResourceException {
Form form = getResourceRef(request).getQueryAsForm();
String[] datasetsURI = form.getValuesArray(dataset_complement_uri);
if ((datasetsURI != null) && (datasetsURI.length > 0)) {
QueryComplement qc = new QueryComplement();
qc.setChemicalsOnly(true);
try {
ChemicalByDataset cd = new ChemicalByDataset(new Integer(getRequest().getAttributes().get(datasetKey).toString()));
qc.setScope(cd);
} catch (Exception x) {
}
Template t = new Template(String.format("%s%s/{%s}", getRequest().getRootRef(), DatasetStructuresResource.dataset, DatasetStructuresResource.datasetKey));
for (String datasetURI : datasetsURI) {
Map<String, Object> vars = new HashMap<String, Object>();
t.parse(datasetURI, vars);
try {
qc.add(new ChemicalByDataset(new Integer(vars.get(DatasetStructuresResource.datasetKey).toString())));
} catch (Exception x) {
}
}
return (Q) qc;
}
return null;
}
Aggregations