diff options
author | rautenberg <rautenberg@in-silico.ch> | 2016-08-29 09:49:32 +0200 |
---|---|---|
committer | rautenberg <rautenberg@in-silico.ch> | 2016-08-29 09:49:32 +0200 |
commit | 452e50bb4760176f004b8c7faff379f69564b3d0 (patch) | |
tree | 1a7a854c7ed8db9735076a105d86f3f99d16c1f8 | |
parent | e3284e859455db4e773d1005ff8ecdb87a6233b1 (diff) |
add initial validation routes
-rw-r--r-- | api/api.json | 103 | ||||
-rw-r--r-- | application.rb | 56 |
2 files changed, 156 insertions, 3 deletions
diff --git a/api/api.json b/api/api.json index 5672f64..476b941 100644 --- a/api/api.json +++ b/api/api.json @@ -1,9 +1,9 @@ { "swagger": "2.0", "info": { - "description": "REST Webservice for lazar\n", + "description": "REST Webservice for lazar and nano-lazar\n", "version": "0.0.1", - "title": "Lazar REST Service", + "title": "Lazar & Nano-Lazar REST Service", "contact": { "name": "in silico toxicology gmbh", "email": "service@in-silico.ch", @@ -143,6 +143,92 @@ } } }, + "/validation": { + "get": { + "tags": [ + "validation" + ], + "description": "Get a list of all validation types", + "parameters": [ + { + "name": "accept", + "in": "header", + "description": "requested Content-Type", + "required": true, + "type": "string", + "enum": [ + "text/uri-list", + "application/json" + ] + } + ], + "produces": [ + "text/uri-list", + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "404": { + "$ref": "#/responses/404" + }, + "500": { + "$ref": "#/responses/500" + } + } + } + }, + "/validation/{validationtype}/{id}": { + "tags": [ + "model" + ], + "description": "Get model representation", + "parameters": [ + { + "name": "Content-Type", + "in": "header", + "description": "body Content-Type", + "required": true, + "type": "string", + "enum": [ + "application/json" + ] + }, + { + "$ref": "#/parameters/valtype" + }, + { + "$ref": "#/parameters/modelid" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "$ref": "#/responses/200" + }, + "400": { + "$ref": "#/responses/400" + }, + "401": { + "$ref": "#/responses/401" + }, + "403": { + "$ref": "#/responses/403" + }, + "404": { + "$ref": "#/responses/404" + } + } + }, "/compound/descriptor": { "get": { "tags": [ @@ -387,6 +473,13 @@ "description": "InChI String", "required": true, "type": "string" + }, + "valtype": { + "name": "validationtype", + "in": "path", + "description": "validation type", + "required": true, + "type": "string" } }, "responses": { @@ -429,6 +522,10 @@ { "name": "compound", "description": "Compound" + }, + { + "name": "validation", + "description": "Validation" } ] -} +}
\ No newline at end of file diff --git a/application.rb b/application.rb index 8535a9f..6fc5936 100644 --- a/application.rb +++ b/application.rb @@ -81,6 +81,62 @@ post "/model/:id/?" do return batch.to_json end +VALIDATION_TYPES = ["repeatedcrossvalidation", "leaveoneout", "crossvalidation", "regressioncrossvalidation"] + +# Get a list of all validations +# @param [Header] Accept one of text/uri-list, application/json +# @param [Path] Validationtype One of "repeatedcrossvalidation", "leaveoneout", "crossvalidation", "regressioncrossvalidation" +# @return [text/uri-list] list of all prediction models +get "/validation/:validationtype/?" do + bad_request_error "There is no such validation type as: #{params[:validationtype]}" unless VALIDATION_TYPES.include? params[:validationtype] + case params[:validationtype] + when "repeatedcrossvalidation" + validations = OpenTox::Validation::RepeatedCrossValidation.all + when "leaveoneout" + validations = OpenTox::Validation::LeaveOneOut.all + when "crossvalidation" + validations = OpenTox::Validation::CrossValidation.all + when "regressioncrossvalidation" + validations = OpenTox::Validation::RegressionCrossValidation.all + end + + case @accept + when "text/uri-list" + uri_list = validations.collect{|validation| uri("/validation/#{params[:validationtype]}/#{validation.id}")} + return uri_list.join("\n") + "\n" + when "application/json" + validations = JSON.parse validations.to_json + validations.each_index do |idx| + validations[idx][:URI] = uri("/validation/#{params[:validationtype]}/#{validations[idx]["$oid"]}") + #models[idx][:crossvalidation_uri] = uri("/crossvalidation/#{models[idx]["crossvalidation_id"]["$oid"]}") if models[idx]["crossvalidation_id"] + end + return validations.to_json + else + bad_request_error "Mime type #{@accept} is not supported." + end +end + +get "/validation/:validationtype/:id/?" do + bad_request_error "There is no such validation type as: #{params[:validationtype]}" unless VALIDATION_TYPES.include? params[:validationtype] + case params[:validationtype] + when "repeatedcrossvalidation" + validation = OpenTox::Validation::RepeatedCrossValidation.find params[:id] + when "leaveoneout" + validation = OpenTox::Validation::LeaveOneOut.find params[:id] + when "crossvalidation" + validation = OpenTox::Validation::CrossValidation.find params[:id] + when "regressioncrossvalidation" + validation = OpenTox::Validation::RegressionCrossValidation.find params[:id] + end + + resource_not_found_error "#{params[:validationtype]} with id: #{params[:id]} not found." unless validation + #model[:URI] = uri("/model/#{model.id}") + #model[:neighbor_algorithm_parameters][:feature_dataset_uri] = uri("/dataset/#{model[:neighbor_algorithm_parameters][:feature_dataset_id]}") if model[:neighbor_algorithm_parameters][:feature_dataset_id] + #model[:training_dataset_uri] = uri("/dataset/#{model.training_dataset_id}") if model.training_dataset_id + #model[:prediction_feature_uri] = uri("/dataset/#{model.prediction_feature_id}") if model.prediction_feature_id + return validation.to_json +end + # Get a list of a single or all descriptors # @param [Header] Accept one of text/plain, application/json # @param [Path] Descriptor name (e.G.: Openbabel.HBA1) |