summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrautenberg <rautenberg@in-silico.ch>2015-10-28 18:31:48 +0100
committerrautenberg <rautenberg@in-silico.ch>2015-10-28 18:31:48 +0100
commit89425b508010a8309c8dc3200765f8eea2173886 (patch)
tree699a6360508de68361d3b2b3666d245da97c9404
parent273a84e20db312e04e81449856e7ed88b59da773 (diff)
parent398baa38e0fb9d0f9566bc2d59617bdee85bb2a8 (diff)
Merge branch 'development' of github.com:/opentox/lazar-rest into development
-rw-r--r--application.rb20
1 files 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"