summaryrefslogtreecommitdiff
path: root/scripts/mg2mmol.rb
blob: dc6b9532614315808a47ec0a2be6b7948ae1804d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env ruby
require_relative '../lazar/lib/lazar'
include OpenTox
newfile = ARGV[0].sub(/.csv/,"_mmol.csv") 
p newfile
CSV.open(newfile, "wb") do |csv|
  CSV.read(ARGV[0]).each do |line|
    smi,mg = line
    if mg.numeric?
      c = Compound.from_smiles smi
      mmol = c.mg_to_mmol mg.to_f
      csv << [smi, mmol]
    else
      csv << [smi, mg.gsub(/mg/,'mmol')]
    end
  end
end