Class: BioChEMBL::Compound
- Inherits:
-
Object
- Object
- BioChEMBL::Compound
- Extended by:
- DataModel
- Defined in:
- lib/bio-chembl/compound.rb
Overview
ChEMBL Compound Data Container and Parser
XML Data string <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 “‘cpd = BioChEMBL::Compound.find(“CHEMBL1”)
cpd.chemblId #=> "CHEMLB1"
cpd.smiles
cpd2 = BioChEMBL::Compound.find_all_by_smiles(cpd.smile)
cpd3 = BioChEMBL::Compound.parse(xml)
“‘
Constant Summary collapse
- ATTRIBUTES =
[ :chemblId, :knownDrug, :medChemFriendly, :passesRuleOfThree, :molecularFormula, :smiles, :stdInChiKey, :species, :numRo5Violations, :rotatableBonds, :molecularWeight, :alogp, :acdAcidicPka, :acdLogp, :acdLogd ]
Class Method Summary collapse
-
.find(chemblId) ⇒ Object
Compound.find(chemblId) Find a compound data by a ChEMBL ID.
-
.find_all_by_similarity(smiles_with_similarity) ⇒ Object
Compound.find_similarity(smiles_with_similarity) Search compounds by a SMILES with similarity.
-
.find_all_by_smiles(smiles) ⇒ Object
Compound.find_all_by_smiles(smiles) Find compounds by a SMILES.
-
.find_all_by_substructure(smiles) ⇒ Object
Compound.find_all_by_substructure(smiles) Substructure Search by a SMILES.
-
.find_by_smiles(smiles) ⇒ Object
Compound.find_by_smiles(smiles) Find a compound data by a SMILES.
-
.find_by_stdinchikey(stdinchikey) ⇒ Object
Compound.find_by_stdinchikey(stdinchikey) Find a compound data by a StdInChiKey.
-
.parse(str) ⇒ Object
BioChEMBL::Compound.parse(doc).
-
.parse_json(str) ⇒ Object
JSON.
-
.parse_list_xml(str) ⇒ Object
XML <list><compound> …
-
.parse_rdf(str) ⇒ Object
RDF.
-
.parse_xml(str) ⇒ Object
XML <compound>.
Instance Method Summary collapse
-
#initialize(chemblId = nil) ⇒ Compound
constructor
new.
-
#resolve ⇒ Object
Resolve the compound data by given ChEMBL ID.
Methods included from DataModel
set_attr_accessors, set_attr_values
Constructor Details
#initialize(chemblId = nil) ⇒ Compound
new
144 145 146 |
# File 'lib/bio-chembl/compound.rb', line 144 def initialize(chemblId = nil) @chemblId = chemblId end |
Class Method Details
.find(chemblId) ⇒ Object
Compound.find(chemblId) Find a compound data by a 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
Compound.find_similarity(smiles_with_similarity) Search compounds by a SMILES with similarity
138 139 140 |
# File 'lib/bio-chembl/compound.rb', line 138 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
Compound.find_all_by_smiles(smiles) Find compounds by a SMILES.
120 121 122 |
# File 'lib/bio-chembl/compound.rb', line 120 def self.find_all_by_smiles(smiles) self.parse_list_xml(REST.new.compounds_smiles(smiles)) end |
.find_all_by_substructure(smiles) ⇒ Object
Compound.find_all_by_substructure(smiles) Substructure Search by a SMILES
132 133 134 |
# File 'lib/bio-chembl/compound.rb', line 132 def self.find_all_by_substructure(smiles) self.parse_list_xml(REST.new.compounds_substructure(smiles)) end |
.find_by_smiles(smiles) ⇒ Object
Compound.find_by_smiles(smiles) Find a compound data by a SMILES
114 115 116 |
# File 'lib/bio-chembl/compound.rb', line 114 def self.find_by_smiles(smiles) self.find_all_by_smiles(smiles).first end |
.find_by_stdinchikey(stdinchikey) ⇒ Object
Compound.find_by_stdinchikey(stdinchikey) Find a compound data by a StdInChiKey
126 127 128 |
# File 'lib/bio-chembl/compound.rb', line 126 def self.find_by_stdinchikey(stdinchikey) self.parse_xml(REST.new.compounds_stdinchikey(stdinchikey)) end |
.parse(str) ⇒ Object
BioChEMBL::Compound.parse(doc)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bio-chembl/compound.rb', line 61 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
JSON
96 97 98 |
# File 'lib/bio-chembl/compound.rb', line 96 def self.parse_json(str) raise NotImplementedError end |
.parse_list_xml(str) ⇒ Object
XML <list><compound> …
88 89 90 91 92 93 |
# File 'lib/bio-chembl/compound.rb', line 88 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
RDF
101 102 103 |
# File 'lib/bio-chembl/compound.rb', line 101 def self.parse_rdf(str) raise NotImplementedError end |
.parse_xml(str) ⇒ Object
XML <compound>
79 80 81 82 83 84 |
# File 'lib/bio-chembl/compound.rb', line 79 def self.parse_xml(str) xml = Nokogiri::XML(str) this = new eval set_attr_values(ATTRIBUTES) this end |
Instance Method Details
#resolve ⇒ Object
Resolve the compound data by given ChEMBL ID
149 150 151 152 153 154 |
# File 'lib/bio-chembl/compound.rb', line 149 def resolve resolved = self.class.find(@chemblId) ATTRIBUTES.each do |attr| eval "@#{attr} = resolved.#{attr}" end end |