summaryrefslogtreecommitdiff
path: root/scripts/mmol2-log10.rb
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mmol2-log10.rb')
-rwxr-xr-xscripts/mmol2-log10.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/mmol2-log10.rb b/scripts/mmol2-log10.rb
new file mode 100755
index 0000000..ff4af2a
--- /dev/null
+++ b/scripts/mmol2-log10.rb
@@ -0,0 +1,32 @@
+#!/usr/bin/env ruby
+require_relative '../lib/lazar'
+include OpenTox
+
+newfile = ARGV[0].sub(/.csv/,"_log10.csv")
+p newfile
+CSV.open(newfile, "wb") do |csv|
+ i = 1
+ CSV.read(ARGV[0]).each do |line|
+ type,mmol = line
+ if i == 1
+ @type = type
+ csv << ["SMILES", "-log10(#{mmol})"]
+ else
+ if mmol.numeric?
+ if @type =~ /smiles/i
+ c = Compound.from_smiles type
+ elsif @type =~ /inchi/i
+ c = Compound.from_inchi type
+ type = c.smiles
+ else
+ p "Unknown type '#{type}' at line 1."
+ end
+ mmol = -Math.log10(mmol.to_f)
+ csv << [type, mmol]
+ else
+ p "Line #{i}: '#{mmol}' is not a numeric value."
+ end
+ end
+ i += 1
+ end
+end