From 09974c5a920bbb07475d8e48a725ef3780e60dbe Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 22 Jan 2010 11:16:13 +0100 Subject: central config.ru, generic compound API --- lib/compound.rb | 9 +++++++-- lib/model.rb | 8 +++++++- lib/templates/config.ru | 18 ++++-------------- 3 files changed, 18 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/compound.rb b/lib/compound.rb index 4385a7d..0a90663 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -20,14 +20,19 @@ module OpenTox @inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi)) elsif params[:uri] - @inchi = params[:uri].sub(/^.*InChI/, 'InChI') + if params[:uri].match(/InChI/) # shortcut for IST services + @inchi = params[:uri].sub(/^.*InChI/, 'InChI') + else + @inchi = RestClient.get @uri, :accept => 'chemical/x-inchi' + end @uri = params[:uri] end end # Get the (canonical) smiles def smiles - obconversion(@inchi,'inchi','can') + RestClient.get(@uri, :accept => 'chemical/x-daylight-smiles').split(/\s+/).first # fix ambit output + #obconversion(@inchi,'inchi','can') end def sdf diff --git a/lib/model.rb b/lib/model.rb index 24f6e52..c4041f2 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -31,6 +31,12 @@ module OpenTox def self.find_all RestClient.get(@@config[:services]["opentox-model"]).split("\n") end + + def self.find(uri) + puts uri + yaml = RestClient.get(uri, :accept => "application/x-yaml") + OpenTox::Model::Lazar.from_yaml(yaml) + end # Predict a compound def predict(compound) @@ -46,7 +52,7 @@ module OpenTox end def endpoint - YAML.load(RestClient.get uri)[:endpoint] + YAML.load(RestClient.get(uri))[:endpoint] end def algorithm=(algorithm) diff --git a/lib/templates/config.ru b/lib/templates/config.ru index 63dd2ce..81cea9d 100644 --- a/lib/templates/config.ru +++ b/lib/templates/config.ru @@ -1,23 +1,13 @@ require 'rubygems' -require 'sinatra' +require 'opentox-ruby-api-wrapper' require 'application.rb' require 'rack' require 'rack/contrib' -FileUtils.mkdir_p 'log' unless File.exists?('log') -log = File.new("log/#{ENV["RACK_ENV"]}.log", "a") +FileUtils.mkdir_p @@tmp_dir +log = File.new("#{@@tmp_dir}/#{ENV["RACK_ENV"]}.log", "a+") $stdout.reopen(log) $stderr.reopen(log) -if ENV['RACK_ENV'] == 'production' - use Rack::MailExceptions do |mail| - mail.to 'helma@in-silico.ch' - mail.subject '[ERROR] %s' - end -elsif ENV['RACK_ENV'] == 'development' - use Rack::Reloader - use Rack::ShowExceptions -end - +use Rack::ShowExceptions run Sinatra::Application - -- cgit v1.2.3