From 3d65a42cf68bd5128666d810ec3c29673624ee5d Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Tue, 2 Feb 2010 17:00:48 +0100 Subject: centralized database configuration --- Rakefile | 2 +- lib/algorithm.rb | 1 + lib/compound.rb | 10 +++++----- lib/config/config_ru.rb | 19 +++++++++++++++++++ lib/environment.rb | 22 +++++++++++++++++++++- lib/task.rb | 2 +- lib/tasks/config.rb | 19 ------------------- opentox-ruby-api-wrapper.gemspec | 10 ++++++++-- 8 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 lib/config/config_ru.rb delete mode 100644 lib/tasks/config.rb diff --git a/Rakefile b/Rakefile index ba06640..e585ca6 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", "rack-flash", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core", "sinatra-static-assets"].each do |dep| + ["sinatra", "rest-client", "rack", "rack-contrib", "rack-flash", "thin", "emk-sinatra-url-for", "cehoffman-sinatra-respond_to", "dm-more", "dm-core", "sinatra-static-assets", "do_sqlite3", "do_postgres"].each do |dep| gem.add_dependency dep end gem.add_development_dependency "cucumber" diff --git a/lib/algorithm.rb b/lib/algorithm.rb index c5d162a..25ae4cb 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -39,6 +39,7 @@ module OpenTox end def self.create_model(params) + LOGGER.debug params @uri = RestClient.post File.join(@@config[:services]["opentox-algorithm"], "lazar"), :dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer") end diff --git a/lib/compound.rb b/lib/compound.rb index 562baaa..56646c0 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -21,20 +21,20 @@ module OpenTox @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi)) elsif params[:uri] @uri = params[:uri] - if params[:uri].match(/InChI/) # shortcut for IST services + case params[:uri] + when /ambit/ # Ambit does not deliver InChIs reliably + smiles = RestClient.get @uri, :accept => 'chemical/x-daylight-smiles' + @inchi = obconversion(smiles,'smi','inchi') + when /InChI/ # shortcut for IST services @inchi = params[:uri].sub(/^.*InChI/, 'InChI') else @inchi = RestClient.get @uri, :accept => 'chemical/x-inchi' - # AMBIT does not provide InChIs - #smiles = RestClient.get(@uri, :accept => 'chemical/x-daylight-smiles').split(/\s+/).first # fix ambit output - #@inchi = obconversion(smiles,'smi','inchi') end end end # Get the (canonical) smiles def smiles - #RestClient.get(@uri, :accept => 'chemical/x-daylight-smiles').split(/\s+/).first # fix ambit output obconversion(@inchi,'inchi','can') end diff --git a/lib/config/config_ru.rb b/lib/config/config_ru.rb new file mode 100644 index 0000000..3720ef3 --- /dev/null +++ b/lib/config/config_ru.rb @@ -0,0 +1,19 @@ +require 'rubygems' +require 'rack' +require 'rack/contrib' +require 'application.rb' + +# log at centralized place +logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log" +log = File.new(logfile, "a+") +$stdout.reopen(log) +$stderr.reopen(log) +$stdout.sync = true +$stderr.sync = true +set :raise_errors, true + +['public','tmp'].each do |dir| + FileUtils.mkdir_p dir unless File.exists?(dir) +end + +use Rack::ShowExceptions diff --git a/lib/environment.rb b/lib/environment.rb index a9d0797..fedc3cf 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -2,7 +2,7 @@ require 'logger' # set default environment ENV['RACK_ENV'] = 'test' unless ENV['RACK_ENV'] -# load configuration +# load/setup configuration basedir = File.join(ENV['HOME'], ".opentox") config_dir = File.join(basedir, "config") config_file = File.join(config_dir, "#{ENV['RACK_ENV']}.yaml") @@ -19,6 +19,26 @@ else puts "Please edit #{config_file} and restart your application." exit end + +# database +if @@config[:database] + ['dm-core', 'dm-serializer', 'dm-timestamps', 'dm-types'].each{|lib| require lib } + case @@config[:database][:adapter] + when /sqlite/i + db_dir = File.join(basedir, "db") + FileUtils.mkdir_p db_dir + DataMapper::setup(:default, "sqlite3://#{db_dir}/opentox.sqlite3") + else + DataMapper.setup(:default, { + :adapter => @@config[:database][:adapter], + :database => @@config[:database][:database], + :username => @@config[:database][:username], + :password => @@config[:database][:password], + :host => @@config[:database][:host]}) + end +end + +# logging logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log" LOGGER = Logger.new(logfile,'daily') # daily rotation LOGGER.level = Logger::DEBUG diff --git a/lib/task.rb b/lib/task.rb index 24bd944..9e60c2e 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -10,7 +10,7 @@ module OpenTox end def self.create - uri = RestClient.post @@config[:services]["opentox-task"], nil + uri = RestClient.post @@config[:services]["opentox-task"], {} Task.new(uri) end diff --git a/lib/tasks/config.rb b/lib/tasks/config.rb deleted file mode 100644 index 3720ef3..0000000 --- a/lib/tasks/config.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'rubygems' -require 'rack' -require 'rack/contrib' -require 'application.rb' - -# log at centralized place -logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log" -log = File.new(logfile, "a+") -$stdout.reopen(log) -$stderr.reopen(log) -$stdout.sync = true -$stderr.sync = true -set :raise_errors, true - -['public','tmp'].each do |dir| - FileUtils.mkdir_p dir unless File.exists?(dir) -end - -use Rack::ShowExceptions diff --git a/opentox-ruby-api-wrapper.gemspec b/opentox-ruby-api-wrapper.gemspec index c803a5c..36ae17b 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.6" + s.version = "1.2.7" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Christoph Helma"] - s.date = %q{2010-01-31} + s.date = %q{2010-02-02} 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"] @@ -62,6 +62,8 @@ Gem::Specification.new do |s| s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) @@ -75,6 +77,8 @@ Gem::Specification.new do |s| s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end else @@ -89,6 +93,8 @@ Gem::Specification.new do |s| s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end end -- cgit v1.2.3