From 160e75e696452ac61e651664ac56d16ce1c9c4b6 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 13 Oct 2016 19:17:03 +0200 Subject: model tests separated and cleaned --- test/model-nanoparticle.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/model-nanoparticle.rb (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb new file mode 100644 index 0000000..fb81b83 --- /dev/null +++ b/test/model-nanoparticle.rb @@ -0,0 +1,42 @@ +require_relative "setup.rb" + +class NanoparticleTest < MiniTest::Test + include OpenTox::Validation + + def setup + @training_dataset = Dataset.where(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first + unless @training_dataset + Import::Enanomapper.import File.join(File.dirname(__FILE__),"data","enm") + @training_dataset = Dataset.where(name: "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first + end + @prediction_feature = @training_dataset.features.select{|f| f["name"] == 'log2(Net cell association)'}.first + end + + def test_nanoparticle_model + assert true, @prediction_feature.measured + model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature + refute_empty model.dependent_variables + refute_empty model.descriptor_ids + refute_empty model.independent_variables + assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method] + assert_equal "Algorithm::Similarity.weighted_cosine", model.algorithms[:similarity][:method] + nanoparticle = @training_dataset.nanoparticles[-34] + assert_includes nanoparticle.dataset_ids, @training_dataset.id + prediction = model.predict nanoparticle + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + prediction = model.predict @training_dataset.substances[14] + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + model.delete + end + + def test_nanoparticle_parameters + skip + end + + def test_import_ld + skip # Ambit JSON-LD export defunct + dataset_ids = Import::Enanomapper.import_ld + end +end -- cgit v1.2.3 From 2dc66aef3b7932105868ee8c7d32ad975e142d1b Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 13 Oct 2016 19:48:21 +0200 Subject: compound tests fixed --- test/model-nanoparticle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index fb81b83..6e18add 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -1,6 +1,6 @@ require_relative "setup.rb" -class NanoparticleTest < MiniTest::Test +class NanoparticleModelTest < MiniTest::Test include OpenTox::Validation def setup -- cgit v1.2.3 From 09452bba5c407c27721223d126e3f45c12b20a0c Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 13 Oct 2016 22:59:45 +0200 Subject: tests pass --- test/model-nanoparticle.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index 6e18add..7244a29 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -31,10 +31,6 @@ class NanoparticleModelTest < MiniTest::Test model.delete end - def test_nanoparticle_parameters - skip - end - def test_import_ld skip # Ambit JSON-LD export defunct dataset_ids = Import::Enanomapper.import_ld -- cgit v1.2.3 From 9e7b36613e98601de7b2ceb2d4442e11f1ae868a Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 10 Nov 2016 12:23:46 +0100 Subject: intermediate commit, may be defunct --- test/model-nanoparticle.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index 7244a29..88032bc 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -31,6 +31,70 @@ class NanoparticleModelTest < MiniTest::Test model.delete end + def test_nanoparticle_fingerprint_model + assert true, @prediction_feature.measured + algorithms = { + :descriptors => { + :method => "fingerprint", + :type => "MP2D", + }, + :similarity => { + :method => "Algorithm::Similarity.tanimoto", + :min => 0.1 + }, + :feature_selection => nil + } + model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature, algorithms: algorithms + refute_empty model.dependent_variables + refute_empty model.descriptor_ids + refute_empty model.independent_variables + assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method] + assert_equal "Algorithm::Similarity.tanimoto", model.algorithms[:similarity][:method] + nanoparticle = @training_dataset.nanoparticles[-34] + assert_includes nanoparticle.dataset_ids, @training_dataset.id + prediction = model.predict nanoparticle + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + prediction = model.predict @training_dataset.substances[14] + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + model.delete + end + + def test_nanoparticle_calculated_properties_model + skip "Nanoparticle calculate_properties similarity not yet implemented" + assert true, @prediction_feature.measured + algorithms = { + :descriptors => { + :method => "calculate_properties", + :features => PhysChem.openbabel_descriptors, + }, + :similarity => { + :method => "Algorithm::Similarity.weighted_cosine", + :min => 0.5 + }, + :prediction => { + :method => "Algorithm::Regression.weighted_average", + }, + } + model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature, algorithms: algorithms + p model + refute_empty model.dependent_variables + refute_empty model.descriptor_ids + refute_empty model.independent_variables + assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method] + assert_equal "Algorithm::Similarity.weighted", model.algorithms[:similarity][:method] + nanoparticle = @training_dataset.nanoparticles[-34] + assert_includes nanoparticle.dataset_ids, @training_dataset.id + prediction = model.predict nanoparticle + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + prediction = model.predict @training_dataset.substances[14] + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + model.delete + end + def test_import_ld skip # Ambit JSON-LD export defunct dataset_ids = Import::Enanomapper.import_ld -- cgit v1.2.3 From 9a06f2ff5ae6bdbe7dc90555599e186f1585e0d2 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 10 Nov 2016 15:27:26 +0100 Subject: Model::NanoPrediction parameters --- test/model-nanoparticle.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index 88032bc..c5f3223 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -61,6 +61,36 @@ class NanoparticleModelTest < MiniTest::Test model.delete end + def test_nanoparticle_fingerprint_model_with_feature_selection + assert true, @prediction_feature.measured + algorithms = { + :descriptors => { + :method => "fingerprint", + :type => "MP2D", + }, + :similarity => { + :method => "Algorithm::Similarity.tanimoto", + :min => 0.1 + }, + } + model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature, algorithms: algorithms + refute_empty model.algorithms[:feature_selection] + refute_empty model.dependent_variables + refute_empty model.descriptor_ids + refute_empty model.independent_variables + assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method] + assert_equal "Algorithm::Similarity.tanimoto", model.algorithms[:similarity][:method] + nanoparticle = @training_dataset.nanoparticles[-34] + assert_includes nanoparticle.dataset_ids, @training_dataset.id + prediction = model.predict nanoparticle + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + prediction = model.predict @training_dataset.substances[14] + refute_nil prediction[:value] + assert_includes prediction[:prediction_interval][0]..prediction[:prediction_interval][1], prediction[:measurements].median, "This assertion assures that measured values are within the prediction interval. It may fail in 5% of the predictions." + model.delete + end + def test_nanoparticle_calculated_properties_model skip "Nanoparticle calculate_properties similarity not yet implemented" assert true, @prediction_feature.measured -- cgit v1.2.3 From b6116bc4705066da30668ff3370f3b1c307e44e7 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 11 Nov 2016 13:07:53 +0100 Subject: enm import fixed --- test/model-nanoparticle.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index c5f3223..7fb944e 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -108,7 +108,6 @@ class NanoparticleModelTest < MiniTest::Test }, } model = Model::Lazar.create training_dataset: @training_dataset, prediction_feature: @prediction_feature, algorithms: algorithms - p model refute_empty model.dependent_variables refute_empty model.descriptor_ids refute_empty model.independent_variables -- cgit v1.2.3 From 99c42f76b02f9084d0757eb0c52b4a55fa295a95 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 11 Nov 2016 17:19:13 +0100 Subject: p-chem regression and enm import fixed --- test/model-nanoparticle.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/model-nanoparticle.rb') diff --git a/test/model-nanoparticle.rb b/test/model-nanoparticle.rb index 7fb944e..8dc6830 100644 --- a/test/model-nanoparticle.rb +++ b/test/model-nanoparticle.rb @@ -5,10 +5,6 @@ class NanoparticleModelTest < MiniTest::Test def setup @training_dataset = Dataset.where(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first - unless @training_dataset - Import::Enanomapper.import File.join(File.dirname(__FILE__),"data","enm") - @training_dataset = Dataset.where(name: "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles").first - end @prediction_feature = @training_dataset.features.select{|f| f["name"] == 'log2(Net cell association)'}.first end @@ -50,6 +46,7 @@ class NanoparticleModelTest < MiniTest::Test refute_empty model.independent_variables assert_equal "Algorithm::Caret.rf", model.algorithms[:prediction][:method] assert_equal "Algorithm::Similarity.tanimoto", model.algorithms[:similarity][:method] + assert_nil model.algorithms[:descriptors][:categories] nanoparticle = @training_dataset.nanoparticles[-34] assert_includes nanoparticle.dataset_ids, @training_dataset.id prediction = model.predict nanoparticle -- cgit v1.2.3