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 --- Rakefile | 2 +- lib/compound.rb | 9 +++++++-- lib/model.rb | 8 +++++++- lib/templates/config.ru | 18 ++++-------------- opentox-ruby-api-wrapper.gemspec | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Rakefile b/Rakefile index 5974a9c..b8bf71c 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ begin gem.email = "helma@in-silico.ch" gem.homepage = "http://github.com/helma/opentox-ruby-api-wrapper" gem.authors = ["Christoph Helma"] - ["sinatra", "rest-client", "rack", "rack-contrib", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core"].each do |dep| + ["sinatra", "rest-client", "rack", "rack-contrib", "rack-flash", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core"].each do |dep| gem.add_dependency dep end gem.add_development_dependency "cucumber" 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 - diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec index 88bed8f..21879b3 100644 --- a/opentox-ruby-api-wrapper.gemspec +++ b/opentox-ruby-api-wrapper.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{opentox-ruby-api-wrapper} - s.version = "1.2.4" + s.version = "1.2.5" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Christoph Helma"] - s.date = %q{2010-01-09} + s.date = %q{2010-01-11} s.description = %q{Ruby wrapper for the OpenTox REST API (http://www.opentox.org)} s.email = %q{helma@in-silico.ch} s.executables = ["opentox-install-debian.sh", "yaml2owl.rb"] -- cgit v1.2.3