summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2016-03-15 18:46:34 +0100
committerChristoph Helma <helma@in-silico.ch>2016-03-15 18:46:34 +0100
commitabc3526e318a2bfa24dfe033d8879e7657c2ae5c (patch)
treeb11500952085d6a771f845431258c7befae5fd04
parent7c3bd90c26dfeea2db3cf74a1cefc23d8dece7c0 (diff)
single tests pass
-rw-r--r--lib/lazar.rb2
-rw-r--r--lib/model.rb3
-rw-r--r--lib/physchem.rb6
-rw-r--r--lib/regression.rb2
-rw-r--r--test/regression.rb2
-rw-r--r--test/setup.rb4
6 files changed, 6 insertions, 13 deletions
diff --git a/lib/lazar.rb b/lib/lazar.rb
index 0125d27..b4293e9 100644
--- a/lib/lazar.rb
+++ b/lib/lazar.rb
@@ -86,4 +86,4 @@ CLASSES = ["Feature","Compound","Dataset","Validation","CrossValidation","LeaveO
"leave-one-out-validation.rb",
"experiment.rb",
].each{ |f| require_relative f }
-
+OpenTox::PhysChem.descriptors # load descriptor features
diff --git a/lib/model.rb b/lib/model.rb
index f21ea54..5da5dc8 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -66,6 +66,7 @@ module OpenTox
prediction.merge!({:value => nil,:confidence => nil,:warning => "Could not find similar compounds with experimental data in the training dataset."})
else
prediction.merge!(Algorithm.run(prediction_algorithm, compound, {:neighbors => neighbors,:training_dataset_id=> training_dataset_id,:prediction_feature_id => prediction_feature.id}))
+ prediction[:neighbors] = neighbors
end
prediction
end
@@ -95,7 +96,7 @@ module OpenTox
case object.class.to_s
when "OpenTox::Compound"
prediction = predictions.first
- prediction[:neighbors] = neighbors.sort{|a,b| b[1] <=> a[1]} # sort according to similarity
+ prediction[:neighbors].sort!{|a,b| b[1] <=> a[1]} # sort according to similarity
return prediction
when "Array"
return predictions
diff --git a/lib/physchem.rb b/lib/physchem.rb
index 067cd59..f7b880f 100644
--- a/lib/physchem.rb
+++ b/lib/physchem.rb
@@ -37,15 +37,9 @@ module OpenTox
DESCRIPTORS = OBDESCRIPTORS.merge(CDKDESCRIPTORS.merge(JOELIBDESCRIPTORS))
- DESCRIPTORS.each do |name,description|
- lib,desc = name.split('.',2)
- self.find_or_create_by(:name => name, :library => lib, :descriptor => desc, :description => description, :measured => false, :calculated => true, :numeric => true, :nominal => false)
- end
-
require_relative "unique_descriptors.rb"
def self.descriptors desc=DESCRIPTORS
- # TODO create PhysChem features @startup
desc.collect do |name,description|
lib,desc = name.split('.',2)
self.find_or_create_by(:name => name, :library => lib, :descriptor => desc, :description => description, :measured => false, :calculated => true, :numeric => true, :nominal => false)
diff --git a/lib/regression.rb b/lib/regression.rb
index b8efd30..6b08fd8 100644
--- a/lib/regression.rb
+++ b/lib/regression.rb
@@ -62,7 +62,7 @@ module OpenTox
else
compound_features = variables.collect{|f| compound.fingerprint.include?(f) ? "T" : "F"}
prediction = r_model_prediction method, data_frame, variables, weights, compound_features
- if prediction.nil?
+ if prediction.nil? or prediction[:value].nil?
prediction = local_weighted_average(compound, params)
prediction[:warning] = "Could not create local PLS model. Using weighted average of similar compounds."
return prediction
diff --git a/test/regression.rb b/test/regression.rb
index 6936eb6..8dfb6d7 100644
--- a/test/regression.rb
+++ b/test/regression.rb
@@ -26,7 +26,6 @@ class LazarRegressionTest < MiniTest::Test
model = Model::LazarRegression.create(training_dataset, :prediction_algorithm => "OpenTox::Algorithm::Regression.local_fingerprint_regression")
compound = Compound.from_smiles "NC(=O)OCCC"
prediction = model.predict compound
- p prediction
refute_nil prediction[:value]
end
@@ -35,7 +34,6 @@ class LazarRegressionTest < MiniTest::Test
model = Model::LazarRegression.create(training_dataset, :prediction_algorithm => "OpenTox::Algorithm::Regression.local_physchem_regression")
compound = Compound.from_smiles "NC(=O)OCCC"
prediction = model.predict compound
- p prediction
refute_nil prediction[:value]
end
diff --git a/test/setup.rb b/test/setup.rb
index 3825282..dc577b3 100644
--- a/test/setup.rb
+++ b/test/setup.rb
@@ -4,5 +4,5 @@ require_relative '../lib/lazar.rb'
include OpenTox
TEST_DIR ||= File.expand_path(File.dirname(__FILE__))
DATA_DIR ||= File.join(TEST_DIR,"data")
-#$mongo.database.drop
-#$gridfs = $mongo.database.fs
+$mongo.database.drop
+$gridfs = $mongo.database.fs