Search in sources :

Example 1 with IStructureDiagramHighlights

use of ambit2.core.data.IStructureDiagramHighlights in project ambit-mirror by ideaconsult.

the class ModelImageReporter method getImage.

protected BufferedImage getImage(ModelPredictor predictor, String resultsURI) throws ResourceException {
    if (dataset == null) {
        // legend only
        if (predictor instanceof IStructureDiagramHighlights)
            try {
                return ((IStructureDiagramHighlights) predictor).getLegend(d.width, d.height);
            } catch (AmbitException x) {
                throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
            }
        else
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, OpenTox.params.dataset_uri.getDescription());
    }
    Reference firstmol = new Reference(dataset);
    firstmol.addQueryParameter(OpenTox.params.feature_uris.toString(), resultsURI);
    firstmol.addQueryParameter("max", "1");
    ClientResourceWrapper client = new ClientResourceWrapper(firstmol);
    Representation r = null;
    IteratingSDFReader reader = null;
    try {
        r = client.get(ChemicalMediaType.CHEMICAL_MDLSDF);
        reader = new IteratingSDFReader(r.getStream(), SilentChemObjectBuilder.getInstance());
        while (reader.hasNext()) {
            Object o = reader.next();
            if (o instanceof IAtomContainer)
                return predictor.getImage((IAtomContainer) o, param, d.width, d.height, false);
        }
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(x);
    } finally {
        try {
            reader.close();
        } catch (Exception x) {
        }
        try {
            r.release();
        } catch (Exception x) {
        }
        try {
            client.release();
        } catch (Exception x) {
        }
    }
    return null;
}
Also used : ClientResourceWrapper(net.idea.restnet.c.task.ClientResourceWrapper) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Reference(org.restlet.data.Reference) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) ResourceException(org.restlet.resource.ResourceException) Representation(org.restlet.representation.Representation) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) ResourceException(org.restlet.resource.ResourceException) IStructureDiagramHighlights(ambit2.core.data.IStructureDiagramHighlights) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Aggregations

IStructureDiagramHighlights (ambit2.core.data.IStructureDiagramHighlights)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1 ClientResourceWrapper (net.idea.restnet.c.task.ClientResourceWrapper)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IteratingSDFReader (org.openscience.cdk.io.iterator.IteratingSDFReader)1 Reference (org.restlet.data.Reference)1 Representation (org.restlet.representation.Representation)1 ResourceException (org.restlet.resource.ResourceException)1