Search in sources :

Example 1 with CallableFingerprintsModelCreator

use of ambit2.rest.task.CallableFingerprintsModelCreator in project ambit-mirror by ideaconsult.

the class AllAlgorithmsResource method createCallable.

@Override
protected ICallableTask createCallable(Form form, Algorithm<String> algorithm, ModelURIReporter<IQueryRetrieval<ModelQueryResults>> modelReporter, AlgorithmURIReporter algReporter, Object token) throws ResourceException {
    try {
        if (algorithm.hasType(AlgorithmType.Expert)) {
            String userName = "guest";
            try {
                userName = getRequest().getClientInfo().getUser().getIdentifier();
            } catch (Exception x) {
                userName = "guest";
            }
            Object datasetURI = OpenTox.params.dataset_uri.getFirstValue(form);
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new ExpertModelBuilder(datasetURI == null ? null : datasetURI.toString(), userName, getRequest().getRootRef(), modelReporter, algReporter, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.SuperService)) {
            return new CallablePOST(form, getRequest().getRootRef(), token, getRequest().getResourceRef().toString());
        } else if (algorithm.hasType(AlgorithmType.SuperBuilder)) {
            return new CallableBuilder(form, getRequest().getRootRef(), token, getRequest().getResourceRef().toString());
        } else if (algorithm.hasType(AlgorithmType.Mockup)) {
            return new CallableMockup(form, token);
        } else if (algorithm.hasType(AlgorithmType.ExternalModels))
            return new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, false, token, getRequest().getResourceRef().toString(), getClientInfo());
        else if (algorithm.hasType(AlgorithmType.Rules))
            return new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, false, token, getRequest().getResourceRef().toString(), getClientInfo());
        else if (algorithm.hasType(AlgorithmType.Finder)) {
            return new CallableFinder(form, getRequest().getRootRef(), getContext(), algorithm, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.Structure)) {
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new OptimizerModelBuilder(getRequest().getRootRef(), form, modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.Structure2D)) {
            try {
                CallableSimpleModelCreator modelCreator = new CallableSimpleModelCreator(form, getContext(), algorithm, false, new Structure2DModelBuilder(getRequest().getRootRef(), modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
                TaskResult modelRef = modelCreator.call();
                ModelQueryResults model = modelCreator.getModel();
                Structure2DProcessor predictor = new Structure2DProcessor(getRequest().getRootRef(), model, new ModelURIReporter<IQueryRetrieval<ModelQueryResults>>(getRequest()), new PropertyURIReporter(getRequest()), null);
                return new CallableStructureOptimizer(form, getRequest().getRootRef(), getContext(), (Structure2DProcessor) predictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            } catch (ResourceException x) {
                throw x;
            } catch (Exception x) {
                getLogger().log(Level.WARNING, x.getMessage(), x);
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
            }
        } else if (algorithm.hasType(AlgorithmType.TautomerGenerator)) {
            return new CallableSimpleModelCreator(form, getContext(), algorithm, false, new TautomersModelBuilder(getRequest().getRootRef(), modelReporter, algReporter, false, getRequest().getResourceRef().toString()), token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.PreferredStructure)) {
            return new CallableFixPreferredStructure(form, getRequest().getRootRef(), getContext(), null, token, getRequest().getResourceRef().toString(), getClientInfo());
        } else if (algorithm.hasType(AlgorithmType.DescriptorCalculation)) {
            try {
                CallableSimpleModelCreator modelCreator = new CallableSimpleModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, true, token, getRequest().getResourceRef().toString(), getClientInfo());
                TaskResult modelRef = modelCreator.call();
                ModelQueryResults model = modelCreator.getModel();
                if (algorithm.getParameters() != null) {
                    StringBuilder b = new StringBuilder();
                    for (Parameter prm : algorithm.getParameters()) // b.append(String.format("-%s\t'%s'\t",
                    // prm.getName(),prm.getValue()));
                    b.append(String.format("-%s\t'%s'\t", prm.getName(), prm.getValue()));
                    // this is wrong, the parameters should be stored in the
                    // model already (and in the database!)
                    model.setParameters(b.toString().split("\t"));
                }
                DescriptorPredictor predictor = new DescriptorPredictor(getRequest().getRootRef(), model, modelReporter, new PropertyURIReporter(getRequest()), null);
                return new CallableDescriptorCalculator(form, getRequest().getRootRef(), getContext(), predictor, token, getRequest().getResourceRef().toString(), getClientInfo());
            } catch (ResourceException x) {
                throw x;
            } catch (Exception x) {
                getLogger().log(Level.WARNING, x.getMessage(), x);
                throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
            }
        } else if (algorithm.hasType(AlgorithmType.AppDomain)) {
            switch(algorithm.getRequirement()) {
                case structure:
                    {
                        return new CallableFingerprintsModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
                    }
                case property:
                    {
                        return new CallableNumericalModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
                    }
                default:
                    {
                        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, algorithm.toString());
                    }
            }
        } else if (algorithm.hasType(AlgorithmType.Fingerprints.toString())) {
            return new CallableFingerprintsCalculator(form, getRequest().getRootRef(), getContext(), algorithm, token, getRequest().getResourceRef().toString(), getClientInfo());
        /*
				 * } else if
				 * (AlgorithmFormat.WAFFLES_JSON.equals(algorithm.getFormat()))
				 * { return new CallableWafflesModelCreator(form,
				 * getRequest().getRootRef(), getContext(), algorithm,
				 * modelReporter, algReporter,
				 * token,getRequest().getResourceRef().toString());
				 */
        } else {
            return new CallableWekaModelCreator(form, getRequest().getRootRef(), getContext(), algorithm, modelReporter, algReporter, token, getRequest().getResourceRef().toString(), getClientInfo());
        }
    } catch (ResourceException x) {
        throw x;
    } catch (Exception x) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL);
    } finally {
    // try { connection.close(); } catch (Exception x) {}
    }
}
Also used : CallableBuilder(ambit2.rest.task.CallableBuilder) OptimizerModelBuilder(ambit2.rest.task.OptimizerModelBuilder) CallablePOST(ambit2.rest.task.CallablePOST) PropertyURIReporter(ambit2.rest.property.PropertyURIReporter) CallableStructureOptimizer(ambit2.rest.task.CallableStructureOptimizer) DescriptorPredictor(ambit2.rest.model.predictor.DescriptorPredictor) CallableSimpleModelCreator(ambit2.rest.task.CallableSimpleModelCreator) CallableNumericalModelCreator(ambit2.rest.task.CallableNumericalModelCreator) CallableFingerprintsCalculator(ambit2.rest.task.dbpreprocessing.CallableFingerprintsCalculator) ResourceException(org.restlet.resource.ResourceException) TautomersModelBuilder(ambit2.rest.task.tautomers.TautomersModelBuilder) ModelQueryResults(ambit2.core.data.model.ModelQueryResults) ExpertModelBuilder(ambit2.rest.model.builder.ExpertModelBuilder) CallableFixPreferredStructure(ambit2.rest.task.dbpreprocessing.CallableFixPreferredStructure) Structure2DProcessor(ambit2.rest.model.predictor.Structure2DProcessor) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) CallableMockup(ambit2.rest.task.CallableMockup) CallableWekaModelCreator(ambit2.rest.task.weka.CallableWekaModelCreator) CallableFinder(ambit2.rest.task.dbpreprocessing.CallableFinder) TaskResult(ambit2.rest.task.TaskResult) Parameter(ambit2.core.data.model.Parameter) CallableDescriptorCalculator(ambit2.rest.task.CallableDescriptorCalculator) Structure2DModelBuilder(ambit2.rest.task.Structure2DModelBuilder) CallableFingerprintsModelCreator(ambit2.rest.task.CallableFingerprintsModelCreator)

Aggregations

ModelQueryResults (ambit2.core.data.model.ModelQueryResults)1 Parameter (ambit2.core.data.model.Parameter)1 ExpertModelBuilder (ambit2.rest.model.builder.ExpertModelBuilder)1 DescriptorPredictor (ambit2.rest.model.predictor.DescriptorPredictor)1 Structure2DProcessor (ambit2.rest.model.predictor.Structure2DProcessor)1 PropertyURIReporter (ambit2.rest.property.PropertyURIReporter)1 CallableBuilder (ambit2.rest.task.CallableBuilder)1 CallableDescriptorCalculator (ambit2.rest.task.CallableDescriptorCalculator)1 CallableFingerprintsModelCreator (ambit2.rest.task.CallableFingerprintsModelCreator)1 CallableMockup (ambit2.rest.task.CallableMockup)1 CallableNumericalModelCreator (ambit2.rest.task.CallableNumericalModelCreator)1 CallablePOST (ambit2.rest.task.CallablePOST)1 CallableSimpleModelCreator (ambit2.rest.task.CallableSimpleModelCreator)1 CallableStructureOptimizer (ambit2.rest.task.CallableStructureOptimizer)1 OptimizerModelBuilder (ambit2.rest.task.OptimizerModelBuilder)1 Structure2DModelBuilder (ambit2.rest.task.Structure2DModelBuilder)1 TaskResult (ambit2.rest.task.TaskResult)1 CallableFinder (ambit2.rest.task.dbpreprocessing.CallableFinder)1 CallableFingerprintsCalculator (ambit2.rest.task.dbpreprocessing.CallableFingerprintsCalculator)1 CallableFixPreferredStructure (ambit2.rest.task.dbpreprocessing.CallableFixPreferredStructure)1