summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2015-08-24 12:17:07 +0200
committerChristoph Helma <helma@in-silico.ch>2015-08-24 12:17:07 +0200
commit8c6c59980bc82dc2177147f2fe34adf8bfbc1539 (patch)
tree35fb78389a9ac2d54d4d2190c41a8269a754f205 /test
parent398d8ca681db3aa0a0552eee026705e60dd8449d (diff)
Model::Prediction with tests, initial indexesv0.0.8
Diffstat (limited to 'test')
-rw-r--r--test/compound.rb4
-rw-r--r--test/data/hamster_carcinogenicity.json3
-rw-r--r--test/prediction_models.rb23
-rw-r--r--test/setup.rb3
4 files changed, 30 insertions, 3 deletions
diff --git a/test/compound.rb b/test/compound.rb
index 7265ef5..06c19a2 100644
--- a/test/compound.rb
+++ b/test/compound.rb
@@ -54,7 +54,6 @@ print c.sdf
def test_inchikey
c = OpenTox::Compound.from_inchi "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"
- p c
assert_equal "UHOVQNZJYSORNB-UHFFFAOYSA-N", c.inchikey
end
@@ -88,7 +87,8 @@ print c.sdf
refute_nil c.fp4
end
c = d.compounds[371]
- assert c.neighbors.size >= 19
+ n = c.neighbors
+ assert n.size >= 18, "Neighbors size (#{n.size}) should be larger than 17"
end
def test_openbabel_segfault
diff --git a/test/data/hamster_carcinogenicity.json b/test/data/hamster_carcinogenicity.json
new file mode 100644
index 0000000..8c17d9d
--- /dev/null
+++ b/test/data/hamster_carcinogenicity.json
@@ -0,0 +1,3 @@
+{ "species": "Hamster",
+"endpoint": "Carcinogenicity",
+"source": "http://www.epa.gov/ncct/dsstox/sdf_cpdbas.html" }
diff --git a/test/prediction_models.rb b/test/prediction_models.rb
new file mode 100644
index 0000000..b4ad415
--- /dev/null
+++ b/test/prediction_models.rb
@@ -0,0 +1,23 @@
+require_relative "setup.rb"
+
+class PredictionModelTest < MiniTest::Test
+
+ def test_prediction_model
+ dataset = Dataset.from_csv_file "#{DATA_DIR}/hamster_carcinogenicity.csv"
+ model = Model::LazarFminerClassification.create dataset
+ cv = ClassificationCrossValidation.create model
+ metadata = JSON.parse(File.read("#{DATA_DIR}/hamster_carcinogenicity.json"))
+
+ metadata[:model_id] = model.id
+ metadata[:crossvalidation_id] = cv.id
+ pm = Model::Prediction.new(metadata)
+ pm.save
+ [:endpoint,:species,:source].each do |p|
+ refute_empty pm[p]
+ end
+ assert pm.crossvalidation.accuracy > 0.8
+ prediction = pm.predict Compound.from_smiles("CCCC(NN)C")
+ assert_equal "true", prediction[:value]
+ pm.delete
+ end
+end
diff --git a/test/setup.rb b/test/setup.rb
index 379fa53..538853d 100644
--- a/test/setup.rb
+++ b/test/setup.rb
@@ -3,4 +3,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
+$mongo.database.drop
+$gridfs = $mongo.database.fs # recreate GridFS indexes