summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compound.rb6
-rw-r--r--lib/dataset.rb35
-rw-r--r--lib/environment.rb17
-rw-r--r--lib/features.rb6
4 files changed, 50 insertions, 14 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 6ab78e0..7c7c3d8 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -69,6 +69,12 @@ module OpenTox
smarts_array.collect{|s| s if match?(s)}.compact
end
+ # AM
+ # Match an array of smarts features, returns (0)1 for (non)matching features at each pos
+ def match_all(smarts_array)
+ smarts_array.collect{|s| match?(s) ? 1 : 0 }
+ end
+
def sdf2inchi(sdf)
obconversion(sdf,'sdf','inchi')
end
diff --git a/lib/dataset.rb b/lib/dataset.rb
index 1254992..af72403 100644
--- a/lib/dataset.rb
+++ b/lib/dataset.rb
@@ -86,8 +86,10 @@ module OpenTox
def get_predicted_class(compound, feature)
v = get_value(compound, feature)
if v.is_a?(Hash)
- if v.has_key?(:classification)
- return v[:classification]
+ k = v.keys.grep(/classification/).first
+ unless k.empty?
+ #if v.has_key?(:classification)
+ return v[k]
else
return "no classification key"
end
@@ -103,12 +105,37 @@ module OpenTox
end
end
+ # returns regression value
+ def get_predicted_regression(compound, feature)
+ v = get_value(compound, feature)
+ if v.is_a?(Hash)
+ k = v.keys.grep(/regression/).first
+ unless k.empty?
+ return v[k]
+ else
+ return "no regression key"
+ end
+ elsif v.is_a?(Array)
+ raise "predicted regression value is an array\n"+
+ "value "+v.to_s+"\n"+
+ "value-class "+v.class.to_s+"\n"+
+ "dataset "+@uri.to_s+"\n"+
+ "compound "+compound.to_s+"\n"+
+ "feature "+feature.to_s+"\n"
+ else
+ return v
+ end
+ end
+
# returns prediction confidence if available
def get_prediction_confidence(compound, feature)
v = get_value(compound, feature)
if v.is_a?(Hash)
- if v.has_key?(:confidence)
- return v[:confidence].abs
+ k = v.keys.grep(/confidence/).first
+ unless k.empty?
+ #if v.has_key?(:confidence)
+ return v[k].abs
+ #return v["http://ot-dev.in-silico.ch/model/lazar#confidence"].abs
else
# PENDING: return nil isntead of raising an exception
raise "no confidence key"
diff --git a/lib/environment.rb b/lib/environment.rb
index b53167b..abc7287 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -41,7 +41,7 @@ if @@config[:database]
end
end
-# mail for error messages
+# 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
@@ -107,12 +107,11 @@ end
logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log"
LOGGER = MyLogger.new(logfile,'daily') # daily rotation
-LOGGER.level = Logger::WARN if ENV["RACK_ENV"] == 'production'
-
-#LOGGER = MyLogger.new(STDOUT)
-#LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
-
-#LOGGER.level = Logger::DEBUG
+if @@config[:logger] and @@config[:logger] == "debug"
+ LOGGER.level = Logger::DEBUG
+else
+ LOGGER.level = Logger::WARN
+end
if File.exist?(user_file)
@@users = YAML.load_file(user_file)
@@ -137,8 +136,8 @@ OT = Redland::Namespace.new 'http://www.opentox.org/api/1.1#'
XML = Redland::Namespace.new 'http://www.w3.org/2001/XMLSchema#'
# Regular expressions for parsing classification data
-TRUE_REGEXP = /^(true|active|$1^)/
-FALSE_REGEXP = /^(false|inactive|$0^)/
+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]
diff --git a/lib/features.rb b/lib/features.rb
index c56f3e4..0fa1cf0 100644
--- a/lib/features.rb
+++ b/lib/features.rb
@@ -1,3 +1,7 @@
+# CH: should go into validation service
+# - not a complete OT object
+# - only used twice
+# - what about ./validation/validation/validation_service.rb:241: value = OpenTox::Feature.new(:uri => a.uri).value(prediction_feature).to_s
module OpenTox
module Feature
@@ -12,4 +16,4 @@ module OpenTox
end
end
-end \ No newline at end of file
+end