From 398baa38e0fb9d0f9566bc2d59617bdee85bb2a8 Mon Sep 17 00:00:00 2001 From: Micha Rautenberg Date: Wed, 28 Oct 2015 17:56:15 +0100 Subject: add POST route /algorithm/descriptor to calculate descriptors --- application.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/application.rb b/application.rb index 092369e..06aa8fe 100644 --- a/application.rb +++ b/application.rb @@ -89,13 +89,29 @@ get "/algorithm/descriptor/?:descriptor?" do end end +post "/algorithm/descriptor/?" do + bad_request_error "Missing Parameter " unless params[:file] or params[:descriptor] + descriptor = params['descriptor'].split(',') + dataset = OpenTox::Dataset.from_csv_file params[:file][:tempfile] + d = Algorithm::Descriptor.physchem dataset, descriptor + case @accept + when "application/csv" + return d.to_csv + when "application/json" + lines=CSV.parse(d.to_csv) + keys = lines.delete lines.first + data = lines.collect{|values|Hash[keys.zip(values)]} + return JSON.pretty_generate(data) + end +end + get %r{/compound/(.+)} do |inchi| - inchi = "InChI=#{inchi}" unless inchi.match(/^InChI/) + bad_request_error "Input parameter #{inchi} is not an InChI" unless inchi.match(/^InChI=/) compound = OpenTox::Compound.from_inchi inchi response['Content-Type'] = @accept case @accept when "application/json" - return compound.to_json + return JSON.pretty_generate JSON.parse(compound.to_json) when "chemical/x-daylight-smiles" return compound.smiles when "chemical/x-inchi" -- cgit v1.2.3