From fc3bda0095ca7e6968edf01bec034a243d294af4 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 14 Dec 2009 09:41:59 +0100 Subject: Initial adaptation to RDF/OWL --- lib/compound.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/compound.rb') 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 :uri => uri, :smiles => smiles or :name => name (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 -- cgit v1.2.3