summaryrefslogtreecommitdiff
path: root/scripts/pa-table.rb
blob: af3ab21197bd90db25e2c09e4a33c50a3cc7f90e (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
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby

puts '
\definecolor{red}{rgb}{1,0,0}
\definecolor{lightred}{rgb}{0.5,0,0}
\definecolor{green}{rgb}{0,1,0}
\definecolor{lightgreen}{rgb}{0,0.5,0}
\definecolor{grey}{rgb}{0.5,0.5,0.5}
\tiny
\begin{longtable}{rcccccc}
\caption{Summary of pyrrolizidine alkaloid predictions: red: mutagen, green: non-mutagen, grey: no prediction, dark red|green: low confidence} \\\\
\label{tab:pa}
 & & \multicolumn{2}{c}{lazar} & \multicolumn{3}{c}{R} \\\\
'
#header = ["ID","measured","lazar"]
header = ["ID","Measured","MP2D","PaDEL"]
tab = []
=begin
File.read("pyrrolizidine-alkaloids/180920_PA_complete_SMILES.csv").each_line do |l|
  unless l.match("SMILES")
    #tab << '\verb '+l.chomp.split(";")[2].sub('1: ','')#+'}'
    tab << l.chomp.split(";")[0]
  end
end
i = 0
=end
File.read("pyrrolizidine-alkaloids/lazar/pa-mp2d-predictions.csv").each_line do |l|
  unless l.match("SMILES")
    id,smi,exp,mut,p0,p1,max_sim,nn = l.chomp.split(",")
    row = id
    if exp == "1"
      row += ' & \cellcolor{red} '
    elsif exp == "0"
      row += ' & \cellcolor{green} '
    else
      row += ' & \cellcolor{grey} '
    end
    if mut == "1"
      max_sim.to_f < 0.5 ? row += '& \cellcolor{lightred}  ' : row += '& \cellcolor{red}  '
    elsif mut == "0"
      max_sim.to_f < 0.5 ? row += '& \cellcolor{lightgreen}  ' : row += '& \cellcolor{green}  '
    else #if mut.nil? or mut.empty?
      row += '& \cellcolor{grey} '
    end
    tab << row
    #i += 1
  end
end
i=0
File.read("pyrrolizidine-alkaloids/lazar/pa-padel-predictions.csv").each_line do |l|
  smi,exp,mut,p0,p1,max_sim,nn = l.chomp.split(",")
  #p mut
  if mut == "1"
    max_sim.to_f < 0.5 ? tab[i] += '& \cellcolor{lightred}  ' : tab[i] += '& \cellcolor{red}  '
  elsif mut == "0"
    max_sim.to_f < 0.5 ? tab[i] += '& \cellcolor{lightgreen}  ' : tab[i] += '& \cellcolor{green}  '
  else #if mut.nil? or mut.empty?
    tab[i] += '& \cellcolor{grey} '
  end
  i += 1
end
Dir["pyrrolizidine-alkaloids/PA.*.outcome.csv"].each do |r|
  header << r.sub('pyrrolizidine-alkaloids/PA.','').sub('.outcome.csv','')
  i = 0
  File.read(r).each_line do |l|
    if i > 0
      items = l.chomp.split(";")
      items.shift
      if items.uniq.include? "1"
        tab[i-1] << ' & \cellcolor{red}'
      elsif items.uniq.include? "0"
        tab[i-1] << ' & \cellcolor{green}'
      end
    end
    i += 1
  end
end
#tab.collect!{|t| t + '\cellcolor{grey}  \\\\'}
puts header.join(" & ")+" \\\\"
puts '\hline'
puts '\renewcommand{\arraystretch}{0.075}'
tab.collect!{|t| t + ''}
puts tab.join(" \\\\ \n")
puts '
\end{longtable}
\normalsize
'