summaryrefslogtreecommitdiff
path: root/scripts/pa-summary.rb
blob: 418aa18a3a3ca8f2492d6a426fb3afb5237593ff (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
#!/usr/bin/env ruby
require 'yaml'

lines = File.readlines(ARGV[0])
header = lines.shift.chomp.split(",")
summary = {:n => lines.size}
lines.each do |line|
  items = line.chomp.split(",")
  items.each_with_index do |v,i|
    unless header[i].match (/SMILES/)
      key = header[i].gsub("-","_").downcase.to_sym
      summary[key] ||= { :n => 0, :mut => 0, :non_mut => 0 }
      case v
      when "1"
        summary[key][:n] += 1
        summary[key][:mut] += 1
      when "0"
        summary[key][:n] += 1
        summary[key][:non_mut] += 1
      end
    end
  end
end
summary.each do |k,a|
  unless k == :n
    a[:n_perc] = (100.0*a[:n]/summary[:n]).round
    a[:mut_perc] = (100.0*a[:mut]/a[:n]).round
    a[:non_mut_perc] = (100.0*a[:non_mut]/a[:n]).round
  end
end
summary = {:pa => summary}
puts summary.to_yaml