changes to catch unpredictable compounds master
authorgebele <gebele@in-silico.ch>
Thu, 12 Oct 2017 11:04:30 +0000 (11:04 +0000)
committergebele <gebele@in-silico.ch>
Thu, 12 Oct 2017 11:04:30 +0000 (11:04 +0000)
lib/toxtree.rb
test/toxtree.rb

index f395968..3677071 100644 (file)
@@ -72,14 +72,24 @@ class Toxtree
       rules.each do |name|
         `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 prediction.empty?
+          header = prediction.shift
+          header.pop # remove last empty element
+          smiles.each do |smi|
+            line = prediction.flatten.include?(smi) ? prediction.find{|array| array[0 ]== smi} : ["nil","nil","nil","nil"]
+            p = {"rule" => name}
+            header.each_with_index do |h,i|
+              p[h] = line[i]
+            end
+            predictions << p
+          end
+        else
+          smiles.each do |smi|
+            p = {"rule" => name}
+            p["SMILES"] = smi
+            p[name] = nil
+            predictions << p
           end
-          predictions << p
         end
       end
     ensure
index b1d6274..772eee8 100644 (file)
@@ -22,5 +22,19 @@ class ToxtreeTest < MiniTest::Test
     skip
   end
 
+  def test_no_prediction
+    assert_equal Toxtree.predict("O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1"), {"rule"=>"Cramer rules", "SMILES"=>"O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1", "Cramer rules"=>nil}
+  end
+
+  def test_no_prediction_array
+    assert_equal Toxtree.predict(["O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1","O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1"]), [{"rule"=>"Cramer rules", "SMILES"=>"O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1", "Cramer rules"=>nil}, {"rule"=>"Cramer rules", "SMILES"=>"O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1", "Cramer rules"=>nil}]
+  end
+
+  def test_with_and_without_prediction_array
+    predictions = Toxtree.predict(["c1ccccc1NN","O=S(=O)(Oc1ccccc1)CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCS(=O)(=O)Oc1ccccc1"])
+    assert_equal predictions.size, 2
+    assert_equal predictions, [{"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"}, {"rule"=>"Cramer rules", "SMILES"=>"nil", "CRAMERFLAGS"=>"nil", "Cramer rules"=>"nil", "toxTree.tree.cramer.CramerTreeResult"=>"nil"}]
+  end
+
 end