summaryrefslogtreecommitdiff
path: root/bin/sdf2csv.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2019-09-07 18:20:10 +0200
committerChristoph Helma <helma@in-silico.ch>2019-09-07 18:20:10 +0200
commit791398c12af4f8290095425dac87e3c852905ab6 (patch)
tree608ff890a49641ff196b00f1326555da975d3e1b /bin/sdf2csv.rb
parenta35be3d59a513701f8822af5b56510647d8d531c (diff)
obsolete data and java directories deleted
Diffstat (limited to 'bin/sdf2csv.rb')
-rwxr-xr-xbin/sdf2csv.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/bin/sdf2csv.rb b/bin/sdf2csv.rb
new file mode 100755
index 0000000..ba31fad
--- /dev/null
+++ b/bin/sdf2csv.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/env ruby
+require_relative "../lib/compound"
+
+read_result = false
+sdf = ""
+feature_name = ""
+compound = nil
+features = {}
+table = [["ID","SMILES"]]
+
+File.readlines(ARGV[0]).each do |line|
+ if line.match %r{\$\$\$\$}
+ sdf << line
+ id = sdf.split("\n").first.chomp
+ compound = Compound.from_sdf sdf
+ row = [id,compound.smiles]
+ features.each do |f,v|
+ table[0] << f unless table[0].include? f
+ row[table[0].index(f)] = v
+ end
+ table << row
+ sdf = ""
+ features = {}
+ elsif line.match(/^>\s+</)
+ feature_name = line.match(/^>\s+<(.*)>/)[1]
+ read_result = true
+ else
+ if read_result
+ value = line.chomp
+ features[feature_name] = value
+ read_result = false
+ else
+ sdf << line
+ end
+ end
+end
+
+table.each{|row| puts row.join(",")}