summaryrefslogtreecommitdiff
path: root/scripts/pa-predictions-latex.rb
blob: d97f3d960058b23f07939050c5ef87dcc3c5b155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby

group_lines = File.readlines(ARGV[0]) # groups
group_names = []
group_lines.shift.chomp.split(",")[1..-1].each_with_index do |g,i|
  group_names << "#{i}: #{g}"
end
groups = {}
group_lines.each do |l|
  items = l.chomp.split(",")
  smi = items.shift
  groups[smi] = items
end
pred_lines = File.readlines(ARGV[1]) # predictions
algo_names = pred_lines.shift.chomp.split(",")[1..-1]

print '
\documentclass[]{scrartcl}
\usepackage{color, colortbl}
\usepackage{longtable}
\begin{document}
\definecolor{red}{rgb}{1,0,0}
\definecolor{darkred}{rgb}{0.5,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\definecolor{grey}{rgb}{0.5,0.5,0.5}
\definecolor{black}{rgb}{0,0,0}
\definecolor{white}{rgb}{1,1,1}
\tiny
\begin{longtable}{rrrrrrrrrcccccccccccccc}
\caption{Summary of pyrrolizidine alkaloid predictions: red: mutagen, green: non-mutagen, grey: no prediction, dark red/green: low confidence; '
print "#{group_names.join(', ')}"
puts '} \\\\
\label{tab:pa}'
header2 = ((1..9).to_a + algo_names.select{|a| !a.match(/high/)}.collect{|a| a.sub(/mp2d|cdk/,'').sub('-','').upcase.sub("LAZAR-ALL","lazar")}).join(" & ")
print header2
puts ' \\kill % needed as guide for multicolumn'
puts '\multicolumn{9}{c}{PA Group} & \multicolumn{6}{c}{MP2D} & \multicolumn{6}{c}{CDK}\\\\'
puts header2 + '\\\\'
puts '\hline
\renewcommand{\arraystretch}{0.075}
'

pred_lines.each do |l|
  row = []
  values = l.chomp.split(",")
  smi = values.shift
  groups[smi].each do |v|
    v == "1" ? row << '\cellcolor{black}' : row << '\cellcolor{white}'
  end
  values.each_with_index do |v,i|
    case algo_names[i]
    when /lazar-all/
      if v == "1"
        values[i+1] == "1" ? row << '\cellcolor{red}' : row << '\cellcolor{darkred}' 
      elsif v == "0"
        values[i+1] == "0" ? row << '\cellcolor{green}' : row << '\cellcolor{darkgreen}' 
      else
        row << '\cellcolor{grey}'
      end
    when /lazar-high-confidence/ # do nothing
    else
      if v == "1"
        row << '\cellcolor{red}'
      elsif v == "0"
        row << '\cellcolor{green}'
      else
        row << '\cellcolor{grey}'
      end
    end
  end
  puts row.join(" & ") + ' \\\\'
end
puts '
\end{longtable}
\normalsize
\end{document}
'