From 3a11ba2918795821600b7113d0758415718d263a Mon Sep 17 00:00:00 2001 From: gebele Date: Mon, 11 Jun 2018 12:46:06 +0200 Subject: combine gui with rest --- lib/model.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/model.rb (limited to 'lib/model.rb') diff --git a/lib/model.rb b/lib/model.rb new file mode 100644 index 0000000..9fbd90f --- /dev/null +++ b/lib/model.rb @@ -0,0 +1,38 @@ + +# Get a list of all prediction models +# @param [Header] Accept one of text/uri-list, +# @return [text/uri-list] list of all prediction models +get "/model/?" do + models = Model::Validation.all + case @accept + when "text/uri-list" + uri_list = models.collect{|model| uri("/model/#{model.id}")} + return uri_list.join("\n") + "\n" + when "application/json" + models = JSON.parse models.to_json + list = [] + models.each{|m| list << uri("/model/#{m["_id"]["$oid"]}")} + return list.to_json + else + bad_request_error "Mime type #{@accept} is not supported." + end +end + +get "/model/:id/?" do + model = Model::Validation.find params[:id] + not_found_error "Model with id: #{params[:id]} not found." unless model + return model.to_json +end + + +post "/model/:id/?" do + identifier = params[:identifier].split(",") + compounds = identifier.collect{ |i| Compound.from_smiles i.strip } + model = Model::Validation.find params[:id] + batch = {} + compounds.each do |compound| + prediction = model.predict(compound) + batch[compound] = {:id => compound.id, :inchi => compound.inchi, :smiles => compound.smiles, :model => model, :prediction => prediction} + end + return batch.to_json +end -- cgit v1.2.3