summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/algorithm.rb14
-rw-r--r--lib/compound.rb8
-rw-r--r--lib/dataset.rb6
-rw-r--r--lib/environment.rb95
-rw-r--r--lib/model.rb8
-rw-r--r--lib/opentox-ruby-api-wrapper.rb2
-rw-r--r--lib/owl.rb8
-rw-r--r--lib/task.rb4
-rw-r--r--lib/tasks/opentox.rb22
-rw-r--r--lib/validation.rb2
10 files changed, 54 insertions, 115 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index cc06032..de5902b 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 a293df0..45b96b8 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]
diff --git a/lib/dataset.rb b/lib/dataset.rb
index af72403..776a55b 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 312eec4..46f8933 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -1,6 +1,6 @@
require 'logger'
# set default environment
-ENV['RACK_ENV'] = 'test' unless ENV['RACK_ENV']
+ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV']
# load/setup configuration
basedir = File.join(ENV['HOME'], ".opentox")
@@ -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,91 +24,30 @@ 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
# load mail settings for error messages
load File.join config_dir,"mail.rb" if File.exists?(File.join config_dir,"mail.rb")
-# 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
-
-# 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
-
-
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
@@ -128,18 +67,10 @@ rescue
raise "Please edit #{user_file} and restart your application. Create at least one user with password."
end
-# RDF namespaces
-RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
-OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
-DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
-OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
-#OT = Redland::Namespace.new 'http://ortona.informatik.uni-freiburg.de/opentox.owl#'
-XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
-
# Regular expressions for parsing classification data
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 b6cef46..db9efd4 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 16c23fe..4a6f811 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', 'rest_client_wrapper'].each do |lib|
+['owl', 'compound','dataset','algorithm','model','task','validation','utils','authorization','features', 'logger', 'overwrite', 'rest_client_wrapper'].each do |lib|
require lib
end
diff --git a/lib/owl.rb b/lib/owl.rb
index 700e6ee..a3000e4 100644
--- a/lib/owl.rb
+++ b/lib/owl.rb
@@ -1,3 +1,11 @@
+# RDF namespaces
+RDF = Redland::Namespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
+OWL = Redland::Namespace.new 'http://www.w3.org/2002/07/owl#'
+DC = Redland::Namespace.new 'http://purl.org/dc/elements/1.1/'
+OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
+#OT = Redland::Namespace.new 'http://ortona.informatik.uni-freiburg.de/opentox.owl#'
+XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
+
class Redland::Literal
def self.create(value, datatype=nil)
diff --git a/lib/task.rb b/lib/task.rb
index 88bcb71..e1c1cb5 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 7fce35b..6962407 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 bd38488..f1cc987 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]