summaryrefslogtreecommitdiff
path: root/lib/compound.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2009-12-14 09:41:59 +0100
committerChristoph Helma <helma@in-silico.de>2009-12-14 09:41:59 +0100
commitfc3bda0095ca7e6968edf01bec034a243d294af4 (patch)
tree6721d1130308ec1543d18acab9610860b6fe116f /lib/compound.rb
parentadfcc9d572a2122b1b030dc04b3abf46007fb3f7 (diff)
Initial adaptation to RDF/OWL
Diffstat (limited to 'lib/compound.rb')
-rw-r--r--lib/compound.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/compound.rb b/lib/compound.rb
index 416acab..9e1cee7 100644
--- a/lib/compound.rb
+++ b/lib/compound.rb
@@ -1,9 +1,8 @@
module OpenTox
- # uri: /compound/:inchi
- class Compound < OpenTox
+ class Compound #< OpenTox
- attr_reader :inchi
+ attr_reader :inchi, :uri
# Initialize with <tt>:uri => uri</tt>, <tt>:smiles => smiles</tt> or <tt>:name => name</tt> (name can be also an InChI/InChiKey, CAS number, etc)
def initialize(params)
@@ -14,6 +13,9 @@ module OpenTox
elsif params[:inchi]
@inchi = params[:inchi]
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
+ elsif params[:sdf]
+ @inchi = sdf2inchi(params[:sdf])
+ @uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
elsif params[:name]
@inchi = RestClient.get("#{@@cactus_uri}#{params[:name]}/stdinchi").chomp
@uri = File.join(@@config[:services]["opentox-compound"],URI.escape(@inchi))
@@ -48,6 +50,10 @@ module OpenTox
smarts_array.collect{|s| s if match?(s)}.compact
end
+ def sdf2inchi(sdf)
+ obconversion(sdf,'sdf','inchi')
+ end
+
def smiles2inchi(smiles)
obconversion(smiles,'smi','inchi')
end
@@ -61,7 +67,12 @@ module OpenTox
obmol = OpenBabel::OBMol.new
obconversion.set_in_and_out_formats input_format, output_format
obconversion.read_string obmol, identifier
- obconversion.write_string(obmol).gsub(/\s/,'').chomp
+ case output_format
+ when /smi|can|inchi/
+ obconversion.write_string(obmol).gsub(/\s/,'').chomp
+ else
+ obconversion.write_string(obmol)
+ end
end
end
end