Class: OpenTox::Compound

Inherits:
OpenTox show all
Defined in:
lib/opentox-ruby-api-wrapper.rb

Instance Attribute Summary

Attributes inherited from OpenTox

#uri

Instance Method Summary collapse

Methods inherited from OpenTox

#destroy, #finished?, #name, #uri_escape

Constructor Details

#initialize(params) ⇒ Compound

Initialize with :uri => uri, :smiles => smiles or :name => name (name can be also an InChI/InChiKey, CAS number, etc)



42
43
44
45
46
47
48
49
50
# File 'lib/opentox-ruby-api-wrapper.rb', line 42

def initialize(params)
  if params[:uri]
    @uri = params[:uri].to_s
  elsif params[:smiles]
    @uri = RestClient.post ENV['OPENTOX_COMPOUND'] ,:smiles => uri_escape(params[:smiles])
  elsif params[:name]
    @uri = RestClient.post ENV['OPENTOX_COMPOUND'] ,:name => uri_escape(params[:name])
  end
end

Instance Method Details

#match(smarts_features) ⇒ Object

Match an array of smarts features, returns matching features



67
68
69
# File 'lib/opentox-ruby-api-wrapper.rb', line 67

def match(smarts_features)
  smarts_features.collect{ |smarts| smarts if self.match?(smarts.name) }.compact
end

#match?(smarts) ⇒ Boolean

Matchs a smarts string

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/opentox-ruby-api-wrapper.rb', line 58

def match?(smarts)
  if RestClient.get(@uri + '/match/' + uri_escape(smarts)) == 'true'
    true
  else
    false
  end
end

#smilesObject

Get the (canonical) smiles



53
54
55
# File 'lib/opentox-ruby-api-wrapper.rb', line 53

def smiles
  RestClient.get @uri
end