use of ambit2.base.data.ISourceDataset in project ambit-mirror by ideaconsult.
the class ChartResource method createImage.
protected BufferedImage createImage() throws ResourceException {
BufferedImage image = null;
Connection connection = null;
try {
DBConnection dbc = new DBConnection(getContext());
connection = dbc.getConnection();
ambit2.base.data.Template profile = new ambit2.base.data.Template();
ProfileReader reader = new ProfileReader(getRequest().getRootRef(), profile, getApplication().getContext(), getToken(), getRequest().getCookies(), getRequest().getClientInfo() == null ? null : getRequest().getClientInfo().getAgent(), getRequest().getResourceRef().toString());
reader.setCloseConnection(false);
reader.setConnection(connection);
for (String p : property) reader.process(new Reference(p));
switch(mode) {
case pie:
{
Iterator<Property> i = profile.getProperties(true);
while (i.hasNext()) {
PieChartGenerator<ISourceDataset> chart = new PieChartGenerator<ISourceDataset>();
chart.setProperty(i.next());
chart.setConnection(connection);
chart.setLegend(legend);
chart.setThumbnail(thumbnail);
chart.setWidth(w);
chart.setHeight(h);
chart.setLogX(logX);
chart.setLogY(logY);
image = chart.process(dataset);
// ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
break;
}
break;
}
case histogram:
{
Iterator<Property> i = profile.getProperties(true);
while (i.hasNext()) {
HistogramChartGenerator chart = new HistogramChartGenerator();
chart.setLogX(logX);
chart.setLogY(logY);
chart.setMinX(minX);
chart.setMaxX(maxX);
chart.setPropertyX(i.next());
chart.setConnection(connection);
chart.setLegend(legend);
chart.setThumbnail(thumbnail);
chart.setWidth(w);
chart.setHeight(h);
image = chart.process(dataset);
// ChartUtilities.writeImageMap(writer, name, info, useOverLibForToolTips)
break;
}
break;
}
case xy:
{
Property[] p = new Property[2];
int i = 0;
Iterator<Property> it = profile.getProperties(true);
while (it.hasNext()) {
p[i] = it.next();
i++;
if (i >= 2)
break;
}
PropertiesChartGenerator chart = new PropertiesChartGenerator();
chart.setLogX(logX);
chart.setLogY(logY);
chart.setThumbnail(thumbnail);
chart.setPropertyX(p[0]);
chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
chart.setConnection(connection);
chart.setWidth(w);
chart.setHeight(h);
chart.setLegend(legend);
image = chart.process(dataset);
break;
}
case bar:
{
Property[] p = new Property[2];
int i = 0;
Iterator<Property> it = profile.getProperties(true);
while (it.hasNext()) {
p[i] = it.next();
i++;
if (i >= 2)
break;
}
if (i == 0) {
FingerprintHistogramDataset chart = new FingerprintHistogramDataset();
chart.setLogX(logX);
chart.setLogY(logY);
chart.setConnection(connection);
chart.setLegend(legend);
chart.setParam(param);
chart.setThumbnail(thumbnail);
chart.setWidth(w);
chart.setHeight(h);
image = chart.process(dataset);
} else {
BarChartGeneratorDataset chart = new BarChartGeneratorDataset();
chart.setLogX(logX);
chart.setLogY(logY);
chart.setPropertyX(p[0]);
chart.setPropertyY(p.length < 2 ? p[0] : p[1]);
chart.setConnection(connection);
chart.setLegend(legend);
chart.setThumbnail(thumbnail);
chart.setWidth(w);
chart.setHeight(h);
image = chart.process(dataset);
}
break;
}
default:
{
image = null;
}
}
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
} finally {
try {
connection.close();
} catch (Exception x) {
}
}
if (image == null)
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
return image;
}
use of ambit2.base.data.ISourceDataset in project ambit-mirror by ideaconsult.
the class ChartResource method getDataset.
protected ISourceDataset getDataset(String uri) throws InvalidResourceIDException {
Map<String, Object> vars = new HashMap<String, Object>();
Template template = OpenTox.URI.dataset.getTemplate(getRequest().getRootRef());
String id = null;
try {
template.parse(uri, vars);
id = vars.get(OpenTox.URI.dataset.getKey()).toString();
} catch (Exception x) {
return null;
}
if (id != null)
try {
Integer idnum = new Integer(Reference.decode(id.toString()));
SourceDataset dataset = new SourceDataset();
dataset.setID(idnum);
return dataset;
} catch (NumberFormatException x) {
if (id.toString().startsWith(DatasetStructuresResource.QR_PREFIX)) {
String key = id.toString().substring(DatasetStructuresResource.QR_PREFIX.length());
try {
ISourceDataset dataset = new StoredQuery();
dataset.setID(Integer.parseInt(key.toString()));
return dataset;
} catch (NumberFormatException xx) {
throw new InvalidResourceIDException(id);
}
}
} catch (Exception x) {
throw new InvalidResourceIDException(id);
}
return null;
}
use of ambit2.base.data.ISourceDataset in project ambit-mirror by ideaconsult.
the class MetadatasetResource method createObjectIterator.
@Override
protected RDFObjectIterator<M> createObjectIterator(Representation entity) throws ResourceException {
RDFMetaDatasetIterator iterator = new RDFMetaDatasetIterator(entity, entity.getMediaType()) {
@Override
protected ISourceDataset createRecord() {
return new SourceDataset();
}
};
iterator.setForceReadRDFLocalObjects(true);
iterator.setBaseReference(getRequest().getRootRef());
return iterator;
}
use of ambit2.base.data.ISourceDataset 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.base.data.ISourceDataset in project ambit-mirror by ideaconsult.
the class StructureRelationJSONReporter method header.
@Override
public void header(Writer output, Q query) {
try {
output.write("{\n");
Reference datasetURI = baseReference.clone();
datasetURI.addSegment(OpenTox.URI.dataset.name());
Object dataset = (query instanceof AbstractQuery) ? ((AbstractQuery) query).getValue() : null;
if (dataset instanceof IStoredQuery)
datasetURI.addSegment(String.format("R%d", ((IStoredQuery) dataset).getID()));
else if (dataset instanceof SourceDataset)
datasetURI.addSegment(Integer.toString(((ISourceDataset) dataset).getID()));
output.write(String.format("\"%s\":\"%s\",\n", jsonFeature.datasetURI.jsonname(), datasetURI));
output.write("\"links\":[");
} catch (Exception x) {
x.printStackTrace();
}
}
Aggregations