summaryrefslogtreecommitdiff
path: root/bin/classification-summary.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2021-03-08 17:41:26 +0100
committerChristoph Helma <helma@in-silico.ch>2021-03-08 17:41:26 +0100
commit08e5768e9a446db8ab95152d2e9403a0e635ec63 (patch)
tree6f4486c6bfd84b69febcb9d3a4d9de8fee1b1a26 /bin/classification-summary.rb
parenta29eb3e38414cd252850c9c4fb356f8b2bef6fb4 (diff)
cdk predictions fixed
Diffstat (limited to 'bin/classification-summary.rb')
-rwxr-xr-xbin/classification-summary.rb70
1 files changed, 68 insertions, 2 deletions
diff --git a/bin/classification-summary.rb b/bin/classification-summary.rb
index a3e4172..c6755a1 100755
--- a/bin/classification-summary.rb
+++ b/bin/classification-summary.rb
@@ -1,4 +1,70 @@
#!/usr/bin/env ruby
require_relative "../lib/lazar"
-stat = ClassificationStatistics.new ARGV[0]
-stat.summary
+#stat = ClassificationStatistics.new ARGV[0]
+#stat.summary
+dir = File.join(File.dirname(ARGV[0]),"crossvalidation")
+folds = Dir[File.join(dir,"[0-9]*")]
+
+predictions = []
+tp=0
+tn=0
+fp=0
+fn=0
+n=0
+experimental = {}
+
+lines = File.readlines(File.join(ARGV[0]))
+lines.shift
+lines.each do |line|
+ items = line.chomp.split(',')
+ experimental[items[0]] ||= []
+ experimental[items[0]] << items[1].to_i
+end
+
+File.open(File.join(dir,"predictions.csv"),"w+") do |f|
+ folds.each do |fold|
+ pred = File.readlines(File.join(fold,"test-prediction.csv")).collect{|row| row.chomp.split(",")}
+ pred.shift
+ pred.each do |prediction|
+ smi = prediction[0]
+ exp = experimental[smi]
+ unless exp.nil? or prediction[2].empty? or exp.empty?
+ p = prediction[2].to_i
+ n+=1
+ v = "NA"
+ exp.each do |e|
+ if p and e
+ if p == 1 and e == 1
+ v = "TP"
+ tp+=1
+ elsif p == 0 and e == 0
+ v = "TN"
+ tn+=1
+ elsif p == 1 and e == 0
+ v = "FP"
+ fp+=1
+ elsif p == 0 and e == 1
+ v = "FN"
+ fn+=1
+ end
+ end
+ predictions << v
+ end
+ f.puts([smi,v].join(","))
+ end
+ end
+ end
+end
+
+File.open(File.join(dir,"confusion-matrix.csv"),"w+") do |f|
+ f.puts "#{tp},#{fp}\n#{fn},#{tn}"
+end
+
+File.open(File.join(dir,"summary.csv"),"w+") do |f|
+ f.puts "accuracy,#{(tp+tn)/(tp+fp+tn+fn).to_f}"
+ f.puts "true_positive_rate,#{tp/(tp+fn).to_f}"
+ f.puts "true_negative_rate,#{tn/(tn+fp).to_f}"
+ f.puts "positive_predictive_value,#{tp/(tp+fp).to_f}"
+ f.puts "negative_predictive_value,#{tn/(tn+fn).to_f}"
+end
+