diff options
author | davor <vorgrimmlerdavid@gmx.de> | 2012-05-15 11:25:49 +0200 |
---|---|---|
committer | davor <vorgrimmlerdavid@gmx.de> | 2012-05-15 11:25:49 +0200 |
commit | 6e016d24bf6d0272d235c466e0dab3f196f0c0d4 (patch) | |
tree | 2a2593520e41af5960db45e0c527d2a8a7ea5c81 | |
parent | 34c95c24282adb28b4b347ad739da87914f4b338 (diff) |
Checks if given URI is valid.
At the beginning of the compound initialization.
-rw-r--r-- | lib/compound.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/compound.rb b/lib/compound.rb index 8928081..16d266c 100644 --- a/lib/compound.rb +++ b/lib/compound.rb @@ -17,16 +17,20 @@ module OpenTox # @return [Compound] Compound def initialize(uri=nil) @uri = uri - case @uri - when /InChI/ # shortcut for IST services - @inchi = @uri.sub(/^.*InChI/, 'InChI') + if (@uri =~ URI::regexp) || @uri.nil? + case @uri + when /InChI/ # shortcut for IST services + @inchi = @uri.sub(/^.*InChI/, 'InChI') + else + @inchi = RestClientWrapper.get(@uri, :accept => 'chemical/x-inchi').to_s.chomp if @uri + end + + if @uri and @inchi.to_s.size==0 + LOGGER.warn "REMOVE ABMIT HACK: no inchi for compound "+@uri.to_s+", load via smiles" + @inchi = Compound.smiles2inchi(Compound.smiles(@uri)) + end else - @inchi = RestClientWrapper.get(@uri, :accept => 'chemical/x-inchi').to_s.chomp if @uri - end - - if @uri and @inchi.to_s.size==0 - LOGGER.warn "REMOVE ABMIT HACK: no inchi for compound "+@uri.to_s+", load via smiles" - @inchi = Compound.smiles2inchi(Compound.smiles(@uri)) + raise "Not able to create compound with uri: #{@uri}" end end |