Search in sources :

Example 1 with ModelPredictor

use of ambit2.rest.model.predictor.ModelPredictor in project ambit-mirror by ideaconsult.

the class ModelResource method createCallable.

@Override
protected CallableQueryProcessor createCallable(Form form, ModelQueryResults model) throws ResourceException {
    try {
        readVariables(model);
        Object token = getToken();
        final ModelPredictor thepredictor = ModelResource.getPredictor(model, getRequest());
        if (model.getContentMediaType().equals(AlgorithmFormat.WWW_FORM.getMediaType())) {
            if (thepredictor instanceof ExpertModelpredictor)
                return new CallableModelPredictor<IStructureRecord, ExpertModelpredictor, Object>(form, getRequest().getRootRef(), getContext(), (ExpertModelpredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo()) {

                    @Override
                    protected void processForm(Reference applicationRootReference, Form form) {
                        super.processForm(applicationRootReference, form);
                        ((ExpertModelpredictor) thepredictor).setValue(form.getFirstValue("value"));
                    }
                };
            else
                return new CallableModelPredictor<IStructureRecord, ModelPredictor, Object>(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.WEKA.getMediaType())) {
            return // reads Instances, instead of IStructureRecord
            new CallableWekaPredictor<Object, Object>(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        /*
				 * } else if (model.getContentMediaType().equals(
				 * 
				 * AlgorithmFormat.WAFFLES_JSON.getMediaType())) { return new
				 * CallableWafflesPredictor(form, getRequest() .getRootRef(),
				 * getContext(), (WafflesPredictor) thepredictor,
				 * token,getRequest().getResourceRef().toString());
				 */
        } else if (model.getContentMediaType().equals(AlgorithmFormat.COVERAGE_SERIALIZED.getMediaType())) {
            if (model.getPredictors().size() == 0) {
                // based AD
                if (thepredictor instanceof FingerprintsPredictor)
                    return new CallableModelPredictor<IStructureRecord, FingerprintsPredictor, Object>(form, getRequest().getRootRef(), getContext(), (FingerprintsPredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
                else
                    throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Not supported %s", thepredictor.getClass().getName()));
            } else {
                return new CallableModelPredictor(form, getRequest().getRootRef(), getContext(), thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            /*
					 * return new CallableWekaPredictor<DataCoverage>( //reads
					 * Instances, instead of IStructureRecord form,
					 * getRequest().getRootRef(), getContext(), predictor) ;
					 */
            }
        } else if (model.getContentMediaType().equals(AlgorithmFormat.Structure2D.getMediaType())) {
            return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (Structure2DProcessor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.MOPAC.getMediaType())) {
            return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (StructureProcessor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.TAUTOMERS.getMediaType())) {
            return new CallableTautomersGenerator(form, getRequest().getRootRef(), getContext(), (TautomersGenerator) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (model.getContentMediaType().equals(AlgorithmFormat.JAVA_CLASS.getMediaType())) {
            return new CallableDescriptorCalculator(form, getRequest().getRootRef(), getContext(), (DescriptorPredictor) thepredictor, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else
            throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE, model.getContentMediaType());
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
    } finally {
    }
}
Also used : ExpertModelpredictor(ambit2.rest.model.predictor.ExpertModelpredictor) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) Structure2DProcessor(ambit2.rest.model.predictor.Structure2DProcessor) CallableTautomersGenerator(ambit2.rest.task.tautomers.CallableTautomersGenerator) TautomersGenerator(ambit2.rest.task.tautomers.TautomersGenerator) ModelPredictor(ambit2.rest.model.predictor.ModelPredictor) CallableModelPredictor(ambit2.rest.model.task.CallableModelPredictor) ExternalModelPredictor(ambit2.rest.model.predictor.ExternalModelPredictor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) FingerprintsPredictor(ambit2.rest.model.predictor.FingerprintsPredictor) CallableStructureOptimizer(ambit2.rest.task.CallableStructureOptimizer) IStructureRecord(ambit2.base.interfaces.IStructureRecord) CallableModelPredictor(ambit2.rest.model.task.CallableModelPredictor) CallableTautomersGenerator(ambit2.rest.task.tautomers.CallableTautomersGenerator) CallableDescriptorCalculator(ambit2.rest.task.CallableDescriptorCalculator) ResourceException(org.restlet.resource.ResourceException)

Example 2 with ModelPredictor

use of ambit2.rest.model.predictor.ModelPredictor in project ambit-mirror by ideaconsult.

the class ModelTextReporter method processItem.

@Override
public Object processItem(ModelQueryResults model) throws AmbitException {
    try {
        ModelPredictor predictor = ModelResource.getPredictor(model, request);
        getOutput().write(predictor.toString());
        return null;
    } catch (AmbitException x) {
        throw x;
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : ModelPredictor(ambit2.rest.model.predictor.ModelPredictor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with ModelPredictor

use of ambit2.rest.model.predictor.ModelPredictor in project ambit-mirror by ideaconsult.

the class ModelImageReporter method processItem.

@Override
public Object processItem(ModelQueryResults model) throws Exception {
    ModelPredictor predictor = ModelResource.getPredictor(model, request);
    String resultsURI = String.format("%s/%s", modelURIReporter.getURI(model), OpenTox.URI.feature);
    setOutput(getImage(predictor, resultsURI));
    return model;
}
Also used : ModelPredictor(ambit2.rest.model.predictor.ModelPredictor)

Example 4 with ModelPredictor

use of ambit2.rest.model.predictor.ModelPredictor 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

ModelPredictor (ambit2.rest.model.predictor.ModelPredictor)3 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)3 Reference (org.restlet.data.Reference)2 ResourceException (org.restlet.resource.ResourceException)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 IStructureDiagramHighlights (ambit2.core.data.IStructureDiagramHighlights)1 ExpertModelpredictor (ambit2.rest.model.predictor.ExpertModelpredictor)1 ExternalModelPredictor (ambit2.rest.model.predictor.ExternalModelPredictor)1 FingerprintsPredictor (ambit2.rest.model.predictor.FingerprintsPredictor)1 Structure2DProcessor (ambit2.rest.model.predictor.Structure2DProcessor)1 CallableModelPredictor (ambit2.rest.model.task.CallableModelPredictor)1 CallableDescriptorCalculator (ambit2.rest.task.CallableDescriptorCalculator)1 CallableStructureOptimizer (ambit2.rest.task.CallableStructureOptimizer)1 CallableTautomersGenerator (ambit2.rest.task.tautomers.CallableTautomersGenerator)1 TautomersGenerator (ambit2.rest.task.tautomers.TautomersGenerator)1 BatchProcessingException (net.idea.modbcum.i.exceptions.BatchProcessingException)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1 NotFoundException (net.idea.modbcum.i.exceptions.NotFoundException)1 ClientResourceWrapper (net.idea.restnet.c.task.ClientResourceWrapper)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1