tests for all rules
authorChristoph Helma <helma@in-silico.ch>
Tue, 22 Aug 2017 17:58:41 +0000 (19:58 +0200)
committerChristoph Helma <helma@in-silico.ch>
Tue, 22 Aug 2017 17:58:41 +0000 (19:58 +0200)
lib/toxtree.rb
test/toxtree.rb

index 3234f6a..f395968 100644 (file)
@@ -3,13 +3,6 @@ require 'tempfile'
 
 class Toxtree
   RULES = {
-#toxtree.plugins.lewis.LewisTree
-#toxtree.plugins.moa.MOARules
-#toxtree.plugins.search.CompoundLookup
-#toxtree.plugins.smartcyp.rules.SMARTCYPRuleHigherRank
-#toxtree.plugins.smartcyp.rules.SMARTCYPRuleRank1
-#toxtree.plugins.smartcyp.rules.SMARTCYPRuleRank2
-#toxtree.plugins.smartcyp.rules.SMARTCYPRuleRank3
     "Cramer rules" => {
       :java_class => "toxTree.tree.cramer.CramerRules",
       :url => "http://toxtree.sourceforge.net/cramer.html"
@@ -80,12 +73,13 @@ class Toxtree
         `cd #{File.join(File.dirname(__FILE__),"..","Toxtree-v2.6.13","Toxtree")}; java -jar Toxtree-2.6.13.jar -i #{input.path} -m #{RULES[name][:java_class]} -n -o #{output}`
         prediction = CSV.read(output)
         header = prediction.shift
+        header.pop # remove last empty element
         prediction.each do |line|
           p = {"rule" => name}
           header.each_with_index do |h,i|
-            p[h] = line[i] unless h == ""
+            p[h] = line[i]
           end
-          predictions << p#{:smiles => line[0], :prediction => line[2], :rule => name}
+          predictions << p
         end
       end
     ensure
index 9f67967..80733d1 100644 (file)
@@ -3,18 +3,25 @@ require 'minitest/autorun'
 require_relative '../lib/toxtree.rb'
 
 class ToxtreeTest < MiniTest::Test
+
   def test_cramer
-    skip
-    assert_equal Toxtree.predict("c1ccccc1NN"), {:smiles=>"c1ccccc1NN", :prediction=>"High (Class III)", :rule=>"Cramer rules"}
+    assert_equal Toxtree.predict("c1ccccc1NN"), {"rule"=>"Cramer rules", "SMILES"=>"c1ccccc1NN", "CRAMERFLAGS"=>nil, "Cramer rules"=>"High (Class III)", "toxTree.tree.cramer.CramerTreeResult"=>"1N,2N,3N,5N,6N,7N,16N,17N,19N,23Y,27Y,28N,30Y,31N,32N,22N,33N"}
   end
+
   def test_all_rules
     smiles = ["c1ccccc1NN","c1ccccc1N","CCC(CC)CC#N"]
     Toxtree::RULES.each do |name,rule|
-      puts JSON.pretty_generate(Toxtree.predict(smiles,name))
+      Toxtree.predict(smiles,name).each do |prediction|
+        refute_nil prediction
+        assert_equal name, prediction["rule"]
+        assert smiles.include?(prediction["SMILES"])
+      end
     end
   end
+
   def test_urls
     skip
   end
+
 end