Class: BioChEMBL::Compound

Inherits:
Object
  • Object
show all
Extended by:
DataModel
Defined in:
lib/bio-chembl/compound.rb

Overview

ChEMBL Compound Data Container and Parser

XML Data

<compound>
  <chemblId>CHEMBL1</chemblId>
  <knownDrug>No</knownDrug>
  <medChemFriendly>Yes</medChemFriendly>
  <passesRuleOfThree>No</passesRuleOfThree>
  <molecularFormula>C32H32O8</molecularFormula>
  <smiles>COc1ccc2[C@@H]3[C@H](COc2c1)C(C)(C)OC4=C3C(=O)C(=O)C5=C4OC(C)(C)[C@@H]6COc7cc(OC)ccc7[C@H]56</smiles>
  <stdInChiKey>GHBOEFUAGSHXPO-XZOTUCIWSA-N</stdInChiKey>
  <numRo5Violations>1</numRo5Violations>
  <rotatableBonds>2</rotatableBonds>
  <molecularWeight>544.59167</molecularWeight>
  <alogp>3.627</alogp>
  <acdLogp>7.669</acdLogp>
  <acdLogd>7.669</acdLogd>
</compound>

Usage

compound = BioChEMBL::Compound.find("CHEMBL1")
compound.chemblId #=> "CHEMLB1"
compound.smiles

compounds = BioChEMBL::Compound.find_all_by_smiles(compound.smiles)

xml = BioChEMBL::REST.new.compounds("CHEMBL1")
compound = BioChEMBL::Compound.parse_xml(xml)

Constant Summary collapse

ATTRIBUTES =
[ 
  :chemblId, 
  :knownDrug,
  :medChemFriendly,
  :passesRuleOfThree,
  :molecularFormula,
  :smiles,
  :stdInChiKey,
  :species,
  :numRo5Violations,
  :rotatableBonds,
  :molecularWeight,
  :alogp,
  :acdAcidicPka,
  :acdLogp,
  :acdLogd 
]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DataModel

set_attr_accessors, set_attr_values

Constructor Details

#initialize(chemblId = nil) ⇒ Compound

Returns a new instance of Compound.



139
140
141
# File 'lib/bio-chembl/compound.rb', line 139

def initialize(chemblId = nil)
  @chemblId = chemblId
end

Class Method Details

.find(chemblId) ⇒ Object

Find the Compound data by the ChEMBL ID



108
109
110
# File 'lib/bio-chembl/compound.rb', line 108

def self.find(chemblId)
  self.parse_xml(REST.new.compounds(chemblId))
end

.find_all_by_similarity(smiles_with_similarity) ⇒ Object

Find the Compounds by the SMILES with similarity 70% similarity: smiles + “/70”



134
135
136
# File 'lib/bio-chembl/compound.rb', line 134

def self.find_all_by_similarity(smiles_with_similarity)
  self.parse_list_xml(REST.new.compounds_similarity(smiles_with_similarity))
end

.find_all_by_smiles(smiles) ⇒ Object

Find the Compounds by the SMILES.



118
119
120
# File 'lib/bio-chembl/compound.rb', line 118

def self.find_all_by_smiles(smiles)
  self.parse_list_xml(REST.new.compounds_smiles(smiles))
end

.find_all_by_substructure(smiles) ⇒ Object

Find the Compounds with Substructure Search by the SMILES



128
129
130
# File 'lib/bio-chembl/compound.rb', line 128

def self.find_all_by_substructure(smiles)
  self.parse_list_xml(REST.new.compounds_substructure(smiles))
end

.find_by_smiles(smiles) ⇒ Object

Find the Compound data (first one) by the SMILES



113
114
115
# File 'lib/bio-chembl/compound.rb', line 113

def self.find_by_smiles(smiles)
  self.find_all_by_smiles(smiles).first
end

.find_by_stdinchikey(stdinchikey) ⇒ Object

Find the Compound data by the StdInChiKey



123
124
125
# File 'lib/bio-chembl/compound.rb', line 123

def self.find_by_stdinchikey(stdinchikey)
  self.parse_xml(REST.new.compounds_stdinchikey(stdinchikey))
end

.parse(str) ⇒ Object

Parse the Compound data



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bio-chembl/compound.rb', line 63

def self.parse(str)
  case str
  when /^</
    format = 'xml'
  when /^\{/
    format = 'json'
  else
    raise ArgumentError, "Unexpected file format: #{str.inspect}" 
  end
  begin
    eval "self.parse_#{format}(str)"
  rescue 
    raise NoMethodError
  end    
end

.parse_json(str) ⇒ Object

Parse the Compound data in JSON format.

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/bio-chembl/compound.rb', line 97

def self.parse_json(str)
  raise NotImplementedError
end

.parse_list_xml(str) ⇒ Object

Parse the Compound data list in XML format. data list: <list><compound/></list>



89
90
91
92
93
94
# File 'lib/bio-chembl/compound.rb', line 89

def self.parse_list_xml(str)
  xmls = Nokogiri::XML(str)
  xmls.xpath("/list/compound").map do |cpd|
    self.parse_xml(cpd.to_s)
  end
end

.parse_rdf(str) ⇒ Object

Parse the Compound data in RDF format.

Raises:

  • (NotImplementedError)


102
103
104
# File 'lib/bio-chembl/compound.rb', line 102

def self.parse_rdf(str)
  raise NotImplementedError
end

.parse_xml(str) ⇒ Object

Parse the Compound data in XML format.



80
81
82
83
84
85
# File 'lib/bio-chembl/compound.rb', line 80

def self.parse_xml(str)
  xml = Nokogiri::XML(str)
  this = new  
  eval set_attr_values(ATTRIBUTES)
  this
end

Instance Method Details

#resolveObject

Resolve the Compound data by the ChEMBL ID



144
145
146
147
148
149
# File 'lib/bio-chembl/compound.rb', line 144

def resolve
  resolved = self.class.find(@chemblId)
  ATTRIBUTES.each do |attr|
    eval "@#{attr} = resolved.#{attr}"
  end
end