summaryrefslogtreecommitdiff
path: root/scripts/noael_loael2mmol.rb
blob: 89ade9b1f1f83a015beca90932fa020f513e420e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env ruby
require_relative '../../lazar/lib/lazar'
include OpenTox
csv_in =  CSV.read(ARGV[0], :encoding => 'windows-1251:utf-8')
head = csv_in.shift
data = []
csv_in.each do |line|
  smi = line[11]
  mg = line[19]
  unless mg.to_f == 0.0
    c = Compound.from_smiles smi
    # round to 5 significant digits in order to detect duplicates 
    mmol = c.mg_to_mmol(mg.to_f).signif(5)
    data << [c.smiles, mmol,"swiss"]
  end
end
data.sort!{|a,b| a[1] <=> b[1]}
File.open(File.join("data","swiss.csv"),"w+") do |f|
  f.puts ["SMILES","LOAEL","Dataset"].join ","
  f.puts data.collect{|row| row.join ","}.join "\n"
end