From 10b3774101226beb1f03dd1deb76b8f2c539b9a1 Mon Sep 17 00:00:00 2001 From: dv Date: Wed, 20 Jul 2011 17:22:44 +0200 Subject: Added test_match_hits to compound and modified test_p_sum_support /test_tanimoto in algorithm --- algorithm.rb | 46 ++++++++++++++++++++++++++-------------------- compound.rb | 4 ++++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/algorithm.rb b/algorithm.rb index 66a230b..4acfeec 100644 --- a/algorithm.rb +++ b/algorithm.rb @@ -28,12 +28,9 @@ class AlgorithmTest < Test::Unit::TestCase params = {} params[:compound_features_hits] = { "c:c" => 10, "c:c:c" => 5, "O:N" => 2} params[:training_compound] = "http://localhost/compound/InChI=1S/CH2O/c1-2/h1H2" - params[:training_compound2] = "http://localhost/compound/InChI=1S/c1-2/h1H2" - params[:fingerprints] = {} - params[:fingerprints][params[:training_compound]] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} - params[:fingerprints][params[:training_compound2]] = {"c:c" => 2, "O:N" => 2} + params[:training_compound_features_hits] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} params[:weights] = { "c:c" => 0.95, "c:c:c" => 0.96, "O:N" => 0.97, "O:O" => 0.98} - params[:features] = (params[:compound_features_hits].keys + params[:fingerprints][params[:training_compound2]].keys + params[:fingerprints][params[:training_compound]].keys).uniq + params[:features] = (params[:compound_features_hits].keys + params[:training_compound_features_hits].keys).uniq 2.times{ params[:mode] = "min" assert_in_delta OpenTox::Algorithm.p_sum_support(params), 12.8762796504849, 0.00001 @@ -44,32 +41,41 @@ class AlgorithmTest < Test::Unit::TestCase def test_tanimoto params = {} - params[:compound_features_hits] = { "c:c" => 10, "c:c:c" => 5, "O:N" => 2} params[:training_compound] = "http://localhost/compound/InChI=1S/CH2O/c1-2/h1H2" - params[:training_compound2] = "http://localhost/compound/InChI=1S/c1-2/h1H2" - params[:fingerprints] = {} - params[:fingerprints][params[:training_compound]] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} - params[:fingerprints][params[:training_compound2]] = {"c:c" => 2, "O:N" => 2} weights = { "c:c" => 0.95, "c:c:c" => 0.96, "O:N" => 0.97, "O:O" => 0.98} + params[:compound_features_hits] = { "c:c" => 10, "c:c:c" => 5, "O:N" => 2} features_a = params[:compound_features_hits].keys - features_b = params[:fingerprints][params[:training_compound]].keys - features_c = params[:fingerprints][params[:training_compound2]].keys - + params[:training_compound_features_hits] = {"c:c" => 6, "c:c:c" => 3, "O:O" => 2} + features_b = params[:training_compound_features_hits].keys 2.times{ - params[:nr_hits] = nil + params[:nr_hits] = false #test without weights assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, nil, params), 0.5, 0.000001 - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, nil, params), 0.666666666666667, 0.000001 #test with weights assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, weights, params), 0.498056105472291, 0.000001 - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.666545393630348, 0.000001 #test with weights and nr_hits true - params[:nr_hits] = "true" + params[:nr_hits] = true assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_b, weights, params), 0.472823526091916, 0.000001 - assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.470450908604158, 0.000001 - } - end + } + + params[:training_compound_features_hits] = {"c:c" => 2, "O:N" => 2} + features_c = params[:training_compound_features_hits].keys + + 2.times{ + params[:nr_hits] = false + #test without weights + assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, nil, params), 0.666666666666667, 0.000001 + + #test with weights + assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.666545393630348, 0.000001 + + #test with weights and nr_hits true + params[:nr_hits] = true + assert_in_delta OpenTox::Algorithm::Similarity.tanimoto(features_a, features_c, weights, params), 0.235749338271022, 0.000001 + } + + end end diff --git a/compound.rb b/compound.rb index 048e012..5165f31 100644 --- a/compound.rb +++ b/compound.rb @@ -39,4 +39,8 @@ class CompoundTest < Test::Unit::TestCase assert_equal "CCC=C(CC)N(=O)=O", c.to_smiles end + def test_match_hits + c = OpenTox::Compound.from_smiles "N=C=C1CCC(=F=FO)C1" + assert_equal ({"FF"=>2, "CC"=>10, "C"=>6, "C1CCCC1"=>10, "C=C"=>2}), c.match_hits(['CC','F=F','C','C=C','FF','C1CCCC1','OO']) + end end -- cgit v1.2.3