summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-07-22 17:12:51 +0200
committerChristoph Helma <helma@in-silico.ch>2010-07-22 17:12:51 +0200
commit34a7b50fb278fc37c937f2fe170b86332eb054c5 (patch)
treee1debcb36000764b5c7e69e0f2d7e5b92fcb9833
parent05084b1127f0d2498240472cca8a475f48f1fcc4 (diff)
CONFIG reverted to @@config
-rw-r--r--lib/algorithm.rb14
-rw-r--r--lib/compound.rb11
-rw-r--r--lib/dataset.rb6
-rw-r--r--lib/environment.rb26
-rw-r--r--lib/model.rb8
-rw-r--r--lib/opentox-ruby-api-wrapper.rb2
-rw-r--r--lib/ot-logger.rb48
-rw-r--r--lib/overwrite.rb14
-rw-r--r--lib/task.rb4
-rw-r--r--lib/tasks/opentox.rb22
-rw-r--r--lib/validation.rb2
11 files changed, 110 insertions, 47 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index de5902b..cc06032 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -12,7 +12,7 @@ module OpenTox
end
def self.uri
- File.join(CONFIG[:services]["opentox-algorithm"], "fminer")
+ File.join(@@config[:services]["opentox-algorithm"], "fminer")
end
end
@@ -21,15 +21,15 @@ module OpenTox
def self.create_model(params)
LOGGER.debug params
LOGGER.debug File.basename(__FILE__) + ": creating model"
- LOGGER.debug File.join(CONFIG[:services]["opentox-algorithm"], "lazar")
- #resource = RestClient::Resource.new(File.join(CONFIG[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "application/x-yaml")
- resource = RestClient::Resource.new(File.join(CONFIG[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "application/x-yaml")
- #@uri = resource.post(:dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(CONFIG[:services]["opentox-algorithm"], "fminer")).chomp
- @uri = resource.post(:dataset_uri => params[:dataset_uri], :prediction_feature => params[:prediction_feature], :feature_generation_uri => File.join(CONFIG[:services]["opentox-algorithm"], "fminer")).body.chomp
+ LOGGER.debug File.join(@@config[:services]["opentox-algorithm"], "lazar")
+ #resource = RestClient::Resource.new(File.join(@@config[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "application/x-yaml")
+ resource = RestClient::Resource.new(File.join(@@config[:services]["opentox-algorithm"], "lazar"), :user => @@users[:users].keys[0], :password => @@users[:users].values[0], :content_type => "application/x-yaml")
+ #@uri = resource.post(:dataset_uri => params[:dataset_uri], :feature_uri => params[:feature_uri], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")).chomp
+ @uri = resource.post(:dataset_uri => params[:dataset_uri], :prediction_feature => params[:prediction_feature], :feature_generation_uri => File.join(@@config[:services]["opentox-algorithm"], "fminer")).body.chomp
end
def self.uri
- File.join(CONFIG[:services]["opentox-algorithm"], "lazar")
+ File.join(@@config[:services]["opentox-algorithm"], "lazar")
end
end
diff --git a/lib/compound.rb b/lib/compound.rb
index 45b96b8..9366db4 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -11,19 +11,19 @@ module OpenTox
def initialize(params)
if params[:smiles]
@inchi = smiles2inchi(params[:smiles])
- @uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(@inchi))
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:inchi]
@inchi = params[:inchi]
- @uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(@inchi))
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:sdf]
@inchi = sdf2inchi(params[:sdf])
- @uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(@inchi))
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:name]
# paranoid URI encoding to keep SMILES charges and brackets
@inchi = RestClient.get("#{@@cactus_uri}#{URI.encode(params[:name], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}/stdinchi").body.chomp
# this was too hard for me to debug and leads to additional errors (ch)
#@inchi = RestClientWrapper.get("#{@@cactus_uri}#{URI.encode(params[:name], Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}/stdinchi").chomp
- @uri = File.join(CONFIG[:services]["opentox-compound"],URI.escape(@inchi))
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:uri]
@uri = params[:uri]
case params[:uri]
@@ -56,7 +56,8 @@ module OpenTox
end
def image_uri
- "#{@@ambit_uri}#{smiles}"
+ File.join @uri, "image"
+ #"#{@@ambit_uri}#{smiles}"
#"#{@@cactus_uri}#{@inchi}/image"
end
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 776a55b..af72403 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -15,8 +15,8 @@ module OpenTox
def self.find(uri, accept_header=nil)
unless accept_header
- #if uri.match(CONFIG[:services]["opentox-dataset"]) || uri=~ /188.40.32.88/ || uri =~ /informatik/
- if !CONFIG[:accept_headers]["opentox-dataset"].grep(/yaml/).empty?
+ #if uri.match(@@config[:services]["opentox-dataset"]) || uri=~ /188.40.32.88/ || uri =~ /informatik/
+ if !@@config[:accept_headers]["opentox-dataset"].grep(/yaml/).empty?
accept_header = 'application/x-yaml'
else
accept_header = "application/rdf+xml"
@@ -203,7 +203,7 @@ module OpenTox
@features.uniq!
@compounds.uniq!
- OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
+ OpenTox::RestClientWrapper.post(@@config[:services]["opentox-dataset"],{:content_type => "application/x-yaml"},self.to_yaml).strip
end
def init_dirty_features(owl)
diff --git a/lib/environment.rb b/lib/environment.rb
index 46f8933..917011d 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -1,4 +1,4 @@
-require 'logger'
+require "ot-logger"
# set default environment
ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV']
@@ -12,8 +12,8 @@ TMP_DIR = File.join(basedir, "tmp")
LOG_DIR = File.join(basedir, "log")
if File.exist?(config_file)
- CONFIG = YAML.load_file(config_file)
- raise "could not load config, config file: "+config_file.to_s unless CONFIG
+ @@config = YAML.load_file(config_file)
+ raise "could not load config, config file: "+config_file.to_s unless @@config
else
FileUtils.mkdir_p TMP_DIR
FileUtils.mkdir_p LOG_DIR
@@ -24,20 +24,20 @@ else
end
# database
-if CONFIG[:database]
+if @@config[:database]
['dm-core', 'dm-serializer', 'dm-timestamps', 'dm-types', 'dm-migrations' ].each{|lib| require lib }
- case CONFIG[:database][:adapter]
+ 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]})
+ :adapter => @@config[:database][:adapter],
+ :database => @@config[:database][:database],
+ :username => @@config[:database][:username],
+ :password => @@config[:database][:password],
+ :host => @@config[:database][:host]})
end
end
@@ -47,7 +47,7 @@ load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.r
logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log"
LOGGER = MyLogger.new(logfile,'daily') # daily rotation
LOGGER.formatter = Logger::Formatter.new #this is neccessary to restore the formating in case active-record is loaded
-if CONFIG[:logger] and CONFIG[:logger] == "debug"
+if @@config[:logger] and @@config[:logger] == "debug"
LOGGER.level = Logger::DEBUG
else
LOGGER.level = Logger::WARN
@@ -72,5 +72,5 @@ TRUE_REGEXP = /^(true|active|1|1.0)$/i
FALSE_REGEXP = /^(false|inactive|0|0.0)$/i
# Task durations
-DEFAULT_TASK_MAX_DURATION = CONFIG[:default_task_max_duration]
-EXTERNAL_TASK_MAX_DURATION = CONFIG[:external_task_max_duration]
+DEFAULT_TASK_MAX_DURATION = @@config[:default_task_max_duration]
+EXTERNAL_TASK_MAX_DURATION = @@config[:external_task_max_duration]
diff --git a/lib/model.rb b/lib/model.rb
index db9efd4..b6cef46 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -86,8 +86,8 @@ module OpenTox
def initialize
@source = "http://github.com/helma/opentox-model"
- @algorithm = File.join(CONFIG[:services]["opentox-algorithm"],"lazar")
- #@independent_variables = File.join(CONFIG[:services]["opentox-algorithm"],"fminer#BBRC_representative")
+ @algorithm = File.join(@@config[:services]["opentox-algorithm"],"lazar")
+ #@independent_variables = File.join(@@config[:services]["opentox-algorithm"],"fminer#BBRC_representative")
@features = []
@effects = {}
@activities = {}
@@ -97,12 +97,12 @@ module OpenTox
def save
@features.uniq!
- resource = RestClient::Resource.new(CONFIG[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
+ resource = RestClient::Resource.new(@@config[:services]["opentox-model"], :user => @@users[:users].keys[0], :password => @@users[:users].values[0])
resource.post(self.to_yaml, :content_type => "application/x-yaml").chomp.to_s
end
def self.find_all
- RestClientWrapper.get(CONFIG[:services]["opentox-model"]).chomp.split("\n")
+ RestClientWrapper.get(@@config[:services]["opentox-model"]).chomp.split("\n")
end
end
end
diff --git a/lib/opentox-ruby-api-wrapper.rb b/lib/opentox-ruby-api-wrapper.rb
index 4a6f811..45a3428 100644
--- a/lib/opentox-ruby-api-wrapper.rb
+++ b/lib/opentox-ruby-api-wrapper.rb
@@ -8,6 +8,6 @@ rescue LoadError
puts "Please install Openbabel with 'rake openbabel:install' in the compound component"
end
-['owl', 'compound','dataset','algorithm','model','task','validation','utils','authorization','features', 'logger', 'overwrite', 'rest_client_wrapper'].each do |lib|
+['owl', 'compound','dataset','algorithm','model','task','validation','utils','authorization','features', 'ot-logger', 'overwrite', 'rest_client_wrapper'].each do |lib|
require lib
end
diff --git a/lib/ot-logger.rb b/lib/ot-logger.rb
new file mode 100644
index 0000000..6c35ed2
--- /dev/null
+++ b/lib/ot-logger.rb
@@ -0,0 +1,48 @@
+require 'logger'
+# logging
+class MyLogger < Logger
+
+ def pwd
+ path = Dir.pwd.to_s
+ index = path.rindex(/\//)
+ return path if index==nil
+ path[(index+1)..-1]
+ end
+
+ def trace()
+ lines = caller(0)
+ n = 2
+ line = lines[n]
+
+ while (line =~ /spork.rb/ or line =~ /as_task/ or line =~ /environment.rb/)
+ n += 1
+ line = lines[n]
+ end
+
+ index = line.rindex(/\/.*\.rb/)
+ return line if index==nil
+ line[index..-1]
+ end
+
+ def format(msg)
+ pwd.ljust(18)+" :: "+msg.to_s+" :: "+trace+" :: "+($sinatra ? $sinatra.request.env['REMOTE_ADDR'] : nil).to_s
+ end
+
+ def debug(msg)
+ super format(msg)
+ end
+
+ def info(msg)
+ super format(msg)
+ end
+
+ def warn(msg)
+ super format(msg)
+ end
+
+ def error(msg)
+ super format(msg)
+ end
+
+end
+
diff --git a/lib/overwrite.rb b/lib/overwrite.rb
new file mode 100644
index 0000000..1d0161b
--- /dev/null
+++ b/lib/overwrite.rb
@@ -0,0 +1,14 @@
+# class overwrites aka monkey patches
+# hack: store sinatra in global var to make url_for and halt methods accessible
+before{ $sinatra = self unless $sinatra }
+
+class Sinatra::Base
+ # overwriting halt to log halts (!= 202)
+ def halt(*response)
+ LOGGER.error "halt "+response.first.to_s+" "+(response.size>1 ? response[1].to_s : "") if response and response.first and response.first >= 300
+ # orig sinatra code:
+ response = response.first if response.length == 1
+ throw :halt, response
+ end
+end
+
diff --git a/lib/task.rb b/lib/task.rb
index e1c1cb5..88bcb71 100644
--- a/lib/task.rb
+++ b/lib/task.rb
@@ -18,7 +18,7 @@ module OpenTox
# create is private now, use OpenTox::Task.as_task
def self.create(max_duration)
- task_uri = RestClientWrapper.post(CONFIG[:services]["opentox-task"], {:max_duration => max_duration}, nil, false).to_s
+ task_uri = RestClientWrapper.post(@@config[:services]["opentox-task"], {:max_duration => max_duration}, nil, false).to_s
Task.find(task_uri.chomp)
end
@@ -94,7 +94,7 @@ module OpenTox
# waits for a task, unless time exceeds or state is no longer running
def wait_for_completion(dur=0.3)
- if (@uri.match(CONFIG[:services]["opentox-task"]))
+ if (@uri.match(@@config[:services]["opentox-task"]))
due_to_time = Time.parse(@due_to_time)
running_time = due_to_time - Time.parse(@date)
else
diff --git a/lib/tasks/opentox.rb b/lib/tasks/opentox.rb
index 6962407..7fce35b 100644
--- a/lib/tasks/opentox.rb
+++ b/lib/tasks/opentox.rb
@@ -6,9 +6,9 @@ namespace :opentox do
desc "Run opentox services"
task :start do
- CONFIG[:services].each do |service,uri|
- dir = File.join(CONFIG[:base_dir], service)
- server = CONFIG[:webserver]
+ @@config[:services].each do |service,uri|
+ dir = File.join(@@config[:base_dir], service)
+ server = @@config[:webserver]
case server
when /thin|mongrel|webrick/
port = uri.sub(/^.*:/,'').sub(/\/$/,'')
@@ -32,9 +32,9 @@ namespace :opentox do
desc "Stop opentox services"
task :stop do
- server = CONFIG[:webserver]
+ server = @@config[:webserver]
if server =~ /thin|mongrel|webrick/
- CONFIG[:services].each do |service,uri|
+ @@config[:services].each do |service,uri|
port = uri.sub(/^.*:/,'').sub(/\/$/,'')
pid_file = File.join(TMP_DIR,"#{service}.pid")
begin
@@ -54,8 +54,8 @@ namespace :opentox do
desc "Run all OpenTox tests"
task :test do
- CONFIG[:services].each do |service,uri|
- dir = File.join(CONFIG[:base_dir], service)
+ @@config[:services].each do |service,uri|
+ dir = File.join(@@config[:base_dir], service)
Dir.chdir dir
puts "Running tests in #{dir}"
`rake test -t 1>&2`
@@ -67,10 +67,10 @@ end
desc "Start service in current directory"
task :start do
service = File.basename(Dir.pwd).intern
- server = CONFIG[:webserver]
+ server = @@config[:webserver]
case server
when /thin|mongrel|webrick/
- port = CONFIG[:services][service].sub(/^.*:/,'').sub(/\/$/,'')
+ port = @@config[:services][service].sub(/^.*:/,'').sub(/\/$/,'')
pid_file = File.join(TMP_DIR,"#{service}.pid")
begin
`#{server} --trace --rackup config.ru start -p #{port} -e #{ENV['RACK_ENV']} -P #{pid_file} -d &`
@@ -90,9 +90,9 @@ end
desc "Stop service in current directory"
task :stop do
service = File.basename(Dir.pwd).intern
- server = CONFIG[:webserver]
+ server = @@config[:webserver]
if server =~ /thin|mongrel|webrick/
- port = CONFIG[:services][service].sub(/^.*:/,'').sub(/\/$/,'')
+ port = @@config[:services][service].sub(/^.*:/,'').sub(/\/$/,'')
pid_file = File.join(TMP_DIR,"#{service}.pid")
begin
puts `thin stop -P #{pid_file}`
diff --git a/lib/validation.rb b/lib/validation.rb
index f1cc987..bd38488 100644
--- a/lib/validation.rb
+++ b/lib/validation.rb
@@ -17,7 +17,7 @@ module OpenTox
end
def self.crossvalidation(params)
- params[:uri] = File.join(CONFIG[:services]['opentox-validation'], "crossvalidation")
+ params[:uri] = File.join(@@config[:services]['opentox-validation'], "crossvalidation")
params[:num_folds] = 10 unless params[:num_folds]
params[:random_seed] = 2 unless params[:random_seed]
params[:stratified] = false unless params[:stratified]