Class: OpenTox::Compound

Inherits:
Object show all
Defined in:
lib/compound.rb

Overview

Ruby wrapper for OpenTox Compound Webservices (opentox.org/dev/apis/api-1.2/structure).

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_inchi(inchi) ⇒ OpenTox::Compound

Create a compound from inchi string

Parameters:

  • inchi (String)

    smiles InChI string

Returns:


24
25
26
# File 'lib/compound.rb', line 24

def self.from_inchi inchi
  Compound.new RestClientWrapper.post(service_uri, inchi, {:content_type => 'chemical/x-inchi'})
end

.from_name(name) ⇒ OpenTox::Compound

Create a compound from name. Relies on an external service for name lookups.

Examples:

compound = OpenTox::Compound.from_name("Benzene")

Parameters:

  • name (String)

    can be also an InChI/InChiKey, CAS number, etc

Returns:


40
41
42
43
# File 'lib/compound.rb', line 40

def self.from_name name
  @inchi = RestClientWrapper.get File.join(CACTUS_URI,URI.escape(name),"stdinchi")
  Compound.new RestClientWrapper.post(service_uri, @inchi, {:content_type => 'chemical/x-inchi'})
end

.from_sdf(sdf) ⇒ OpenTox::Compound

Create a compound from sdf string

Parameters:

  • sdf (String)

    smiles SDF string

Returns:


31
32
33
# File 'lib/compound.rb', line 31

def self.from_sdf sdf
  Compound.new RestClientWrapper.post(service_uri, sdf, {:content_type => 'chemical/x-mdl-sdfile'})
end

.from_smiles(smiles) ⇒ OpenTox::Compound

Create a compound from smiles string

Examples:

compound = OpenTox::Compound.from_smiles("c1ccccc1")

Parameters:

  • smiles (String)

    Smiles string

Returns:


17
18
19
# File 'lib/compound.rb', line 17

def self.from_smiles smiles
  Compound.new RestClientWrapper.post(service_uri, smiles, {:content_type => 'chemical/x-daylight-smiles'})
end

Instance Method Details

#==(c) ⇒ Object


8
9
10
# File 'lib/compound.rb', line 8

def ==(c)
  @uri == c.uri
end

#chebiObject

TODO:

104
105
106
# File 'lib/compound.rb', line 104

def chebi
  internal_server_error "not yet implemented"
end

#chemblidString

Returns ChEMBL database compound id, derieved via restcall to chembl

Returns:

  • (String)

    ChEMBL database compound id, derieved via restcall to chembl


109
110
111
112
113
# File 'lib/compound.rb', line 109

def chemblid
  # https://www.ebi.ac.uk/chembldb/ws#individualCompoundByInChiKey
  uri = "http://www.ebi.ac.uk/chemblws/compounds/smiles/#{smiles}.json"
  @chemblid = JSON.parse(RestClientWrapper.get(uri))["compounds"].first["chemblId"]
end

#cidString

Returns PubChem Compound Identifier (CID), derieved via restcall to pubchem

Returns:

  • (String)

    PubChem Compound Identifier (CID), derieved via restcall to pubchem


98
99
100
101
# File 'lib/compound.rb', line 98

def cid
  pug_uri = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/"
  @cid ||= RestClientWrapper.post(File.join(pug_uri, "compound", "inchi", "cids", "TXT"),{:inchi => inchi}).strip
end

#gifimage/gif

Get gif image

Returns:

  • (image/gif)

    Image data


71
72
73
# File 'lib/compound.rb', line 71

def gif
  RestClientWrapper.get File.join(CACTUS_URI,inchi,"image")
end

#image_uriString

Get URI of compound image

Returns:

  • (String)

    Compound image URI


85
86
87
# File 'lib/compound.rb', line 85

def image_uri
  File.join @uri, "image"
end

#inchiString

Get InChI

Returns:


47
48
49
# File 'lib/compound.rb', line 47

def inchi
  @inchi ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchi'}).chomp
end

#inchikeyString

Get InChIKey

Returns:


53
54
55
# File 'lib/compound.rb', line 53

def inchikey
  @inchikey ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-inchikey'}).chomp
end

#namesString

Get all known compound names. Relies on an external service for name lookups.

Examples:

names = compound.names

Returns:


93
94
95
# File 'lib/compound.rb', line 93

def names
  RestClientWrapper.get("#{CACTUS_URI}#{inchi}/names").split("\n")
end

#pngimage/png

Get png image

Examples:

image = compound.png

Returns:

  • (image/png)

    Image data


79
80
81
# File 'lib/compound.rb', line 79

def png
  RestClientWrapper.get(File.join @uri, "image")
end

#sdfString

Get sdf

Returns:


65
66
67
# File 'lib/compound.rb', line 65

def sdf
  RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-mdl-sdfile'}).chomp
end

#smilesString

Get (canonical) smiles

Returns:


59
60
61
# File 'lib/compound.rb', line 59

def smiles
  @smiles ||= RestClientWrapper.get(@uri,{},{:accept => 'chemical/x-daylight-smiles'}).chomp
end