summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicha Rautenberg <rautenberg@in-silico.ch>2015-10-28 17:56:15 +0100
committerMicha Rautenberg <rautenberg@in-silico.ch>2015-10-28 17:56:15 +0100
commit398baa38e0fb9d0f9566bc2d59617bdee85bb2a8 (patch)
tree6f8cc8d793bbb71bcf5975bc28ed7d70d741a272
parent168c09b3bf992346b1179f99bab26cd75ff796e4 (diff)
add POST route /algorithm/descriptor to calculate descriptors
-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"