Skip to content
Browse files

Update documentation

  • Loading branch information...
1 parent 3ecd8e8 commit f609ba08168442378eb4c22a038f4bed5bc46eb1 @nakao committed Jul 22, 2012
View
12 README.md
@@ -18,17 +18,22 @@ REST API address
```
Get data in XML
+
```ruby
api = BioChEMBL::REST.new
compound = api.compounds("CHEMBL1")
targst = api.targets("CHEMBL2477")
assay = api.assays("CHEMBL1217643")
```
+
Check the server status
+
```ruby
BioChEMBL::REST.up? #=> true/false
```
+
REST API client, parser and container: BioChEMBL::Compound
+
```ruby
cpd = BioChEMBL::Compound.find("CHEMBL1")
cpd.chemblId #=> "CHEMBL1"
@@ -44,7 +49,9 @@ REST API client, parser and container: BioChEMBL::Compound
xml = BioChEMBL::REST.new.compounds("CHEMBL1")
cpd = BioChEMBL::Compound.parse_xml(xml)
```
+
REST API client, parser and container: BioChEMBL::Target
+
```ruby
target = BioChEMBL::Target.find("CHEMBL1785")
target.chemblId #=> "CHEMBL1785"
@@ -62,7 +69,9 @@ REST API client, parser and container: BioChEMBL::Target
xml = BioChEMBL::REST.new.targets("CHEMBL1785")
target = BioChEMBL::Target.parse_xml(xml)
```
+
REST API client, parser and container: BioChEMBL::Assay
+
```ruby
assay = BioChEMBL::Assay.find("CHEMBL1217643")
assay.chemblId #=> "CHEMBL1217643"
@@ -76,6 +85,7 @@ REST API client, parser and container: BioChEMBL::Assay
```
Parser and container: BioChEMBL::Bioactivity
+
```ruby
cpd.bioactivities[0].parent_compound.chemblId
target.bioactivities[0].target.chemblId
@@ -85,6 +95,7 @@ Parser and container: BioChEMBL::Bioactivity
```
Getting Started with Ruby
+
```ruby
require 'bio-chembl'
# 1. Use UniProt accession to get target details
@@ -140,6 +151,7 @@ Getting Started with Ruby
puts " #{assay.assayDescription}"
end
```
+
Note: this software is under active development!
## Installation
View
51 lib/bio-chembl/assay.rb
@@ -5,21 +5,34 @@
module BioChEMBL
-
-
- # ChEMBL Assay
- #
+ # ChEMBL Assay Data parser and container.
+ #
# Data XML
- # <assay>
- # <chemblId>CHEMBL1217643</chemblId>
- # <assayType>B</assayType>
- # <journal>Bioorg. Med. Chem. Lett.</journal>
- # <assayOrganism>Homo sapiens</assayOrganism>
- # <assayStrain>Unspecified</assayStrain>
- # <assayDescription>Inhibition of human hERG</assayDescription>
- # <numBioactivities>1</numBioactivities>
- # </assay>
#
+ # <assay>
+ # <chemblId>CHEMBL1217643</chemblId>
+ # <assayType>B</assayType>
+ # <journal>Bioorg. Med. Chem. Lett.</journal>
+ # <assayOrganism>Homo sapiens</assayOrganism>
+ # <assayStrain>Unspecified</assayStrain>
+ # <assayDescription>Inhibition of human hERG</assayDescription>
+ # <numBioactivities>1</numBioactivities>
+ # </assay>
+ #
+ # Usage
+ #
+ # assay = BioChEMBL::Assay.find("CHEMBL1217643")
+ # assay.assayType
+ # assay.assayOrganism
+ # ba = assay.bioactivities
+ #
+ # assay = BioChEMBL::Assay.new("CHEMBL1217643")
+ # assay.assayType #=> nil
+ # assay.resolve
+ # assay.assayType #=> "B"
+ #
+ # xml = BioChEMBL::REST.new.assays("CHEMBL1217643")
+ # assay = BioChEMBL::Assay.parse_xml(xml)
#
class Assay
extend BioChEMBL::DataModel
@@ -36,7 +49,7 @@ class Assay
set_attr_accessors(ATTRIBUTES)
-
+ # Parse the assay data.
def self.parse(str)
case str
when /^</
@@ -53,40 +66,44 @@ def self.parse(str)
end
end
+ # Parse the assay data in XML format.
def self.parse_xml(str)
xml = Nokogiri::XML(str)
this = new
eval set_attr_values(ATTRIBUTES)
this
end
+ # Parse the assay data in JSON format.
def self.parse_json(str)
raise NotImplementedError
end
+ # Parse the assay data in RDF format.
def self.parse_rdf(str)
raise NotImplementedError
end
+ # Find the assay data by ChEMBL ID via the web service.
def self.find(chemblId)
self.parse_xml(REST.new.assays(chemblId))
end
- # new
+ # Create a blank Assay instance.
def initialize(chemblId = nil)
@chemblId = chemblId
end
- # Resolve the compound data by given ChEMBL ID
+ # Resolve the assay data by given ChEMBL ID
def resolve
resolved = self.class.find(@chemblId)
ATTRIBUTES.each do |attr|
eval "@#{attr} = resolved.#{attr}"
end
end
- # ChEMBL Bioactivity
+ # Find the Bioactivity data by the assay.
def bioactivities
BioChEMBL::Bioactivity.parse_list_xml(REST.new.assays(@chemblId, 'bioactivities'))
end
View
76 lib/bio-chembl/bioactivity.rb
@@ -4,32 +4,48 @@
module BioChEMBL
- # BioChEMBL::Bioactivity
+ # ChEMBL Bioactivity data parser and container.
#
# Data XML
- # <list>
- # <bioactivity>
- # <parent__cmpd__chemblid>CHEMBL1214402</parent__cmpd__chemblid>
- # <ingredient__cmpd__chemblid>CHEMBL1214402</ingredient__cmpd__chemblid>
- # <target__chemblid>CHEMBL240</target__chemblid>
- # <target__confidence>9</target__confidence>
- # <target__name>HERG</target__name>
- # <reference>Bioorg. Med. Chem. Lett., (2010) 20:15:4359</reference>
- # <name__in__reference>26</name__in__reference>
- # <organism>Homo sapiens</organism>
- # <bioactivity__type>IC50</bioactivity__type>
- # <activity__comment>Unspecified</activity__comment>
- # <operator>=</operator>
- # <units>nM</units>
- # <assay__chemblid>CHEMBL1217643</assay__chemblid>
- # <assay__type>B</assay__type>
- # <assay__description>Inhibition of human hERG</assay__description>
+ #
+ # <list>
+ # <bioactivity>
+ # <parent__cmpd__chemblid>CHEMBL1214402</parent__cmpd__chemblid>
+ # <ingredient__cmpd__chemblid>CHEMBL1214402</ingredient__cmpd__chemblid>
+ # <target__chemblid>CHEMBL240</target__chemblid>
+ # <target__confidence>9</target__confidence>
+ # <target__name>HERG</target__name>
+ # <reference>Bioorg. Med. Chem. Lett., (2010) 20:15:4359</reference>
+ # <name__in__reference>26</name__in__reference>
+ # <organism>Homo sapiens</organism>
+ # <bioactivity__type>IC50</bioactivity__type>
+ # <activity__comment>Unspecified</activity__comment>
+ # <operator>=</operator>
+ # <units>nM</units>
+ # <assay__chemblid>CHEMBL1217643</assay__chemblid>
+ # <assay__type>B</assay__type>
+ # <assay__description>Inhibition of human hERG</assay__description>
# <value>5900</value>
- # </bioactivity>
- # </list>
+ # </bioactivity>
+ # </list>
#
# Usage
- #
+ #
+ # bioactivties = BioChEMBL::Compound(chemlbId).bioactivities
+ # bioactivties = BioChEMBL::Target(chemlbId).bioactivities
+ # bioactivties = BioChEMBL::Assay(chemlbId).bioactivities
+ #
+ # bioactivities.find_all {|x| x.bioactivity__type =~ /IC50/ and x.value.to_i < 100 }.each do |ba|
+ # assay = ba.assay
+ # puts "Assay CHEMBLID: #{assay.chemblId}, #{assay.assayDescription}"
+ # end
+ #
+ # bioactivity = bioactivities[0]
+ # compound = bioactivity.parent_compound
+ # compound = bioactivity.compound
+ # assay = bioactivity.assay
+ # target = bioactivity.target
+ #
class Bioactivity
extend BioChEMBL::DataModel
@@ -54,6 +70,7 @@ class Bioactivity
set_attr_accessors(ATTRIBUTES)
+ # Parse the Bioactivity data.
def self.parse(str)
case str
when /^</
@@ -70,44 +87,57 @@ def self.parse(str)
end
end
+ # Parse the Bioactivity data in XML format.
def self.parse_xml(str)
xml = Nokogiri::XML(str)
this = new
eval set_attr_values(ATTRIBUTES)
this
end
- # XML
- # <list><bioactivity> ...
+ # Parse the Bioactivity data list in XML format.
+ # data list: <list><bioactivity/></list>
def self.parse_list_xml(str)
xmls = Nokogiri::XML(str)
xmls.xpath("/list/bioactivity").map do |cpd|
self.parse_xml(cpd.to_s)
end
end
+ # Parse the Bioactivity data in JSON format.
def self.parse_json(str)
raise NotImplementedError
end
+ # Parse the Bioactivity data in RDF format.
def self.parse_rdf(str)
raise NotImplementedError
end
+ # Link to the parent Compound
def parent_compound
require 'bio-chembl/compound.rb'
BioChEMBL::Compound.find(@parent__cmpd__chemblid)
end
+
+ # Link to the Compound
+ def compound
+ require 'bio-chembl/compound.rb'
+ BioChEMBL::Compound.find(@ingredient__cmpd__chemblid)
+ end
+ # Link to the Target
def target
require 'bio-chembl/target.rb'
BioChEMBL::Target.find(@target__chemblid)
end
+ # Link to the Assay
def assay
require 'bio-chembl/assay.rb'
BioChEMBL::Assay.find(@assay__chemblid)
end
+
end
end
View
6 lib/bio-chembl/chembl.rb
@@ -7,11 +7,15 @@
#
module BioChEMBL
+ # ChEMBL Website
def self.website
"https://www.ebi.ac.uk/chembl/"
end
- # BioChEMBL.to_array(aTarget.synonyms) #=> []
+ # Multi value utility
+ #
+ # BioChEMBL.to_array(aTarget.synonyms) #=> []
+ #
def self.to_array(str)
str.to_s.split('; ')
end
View
47 lib/bio-chembl/chemblid.rb
@@ -9,31 +9,42 @@
module BioChEMBL
- # ChEMBL ID
+ # ChEMBL ID Utility
#
- # CHEMBL1
+ # Format
#
- # cid = BioChEMBL::ChEMBLID.new("CHEMBL1")
- # cid.is_compound? #=> true
- # cid.resolve #=> aBioChEMBL::Compound
+ # /^CHEMBL\d+$/
+ #
+ # Usage
+ #
+ # chemblId = BioChEMBL::ChEMBLID.new("CHEMBL1")
+ # chemblId.is_compound? #=> true
+ # chemblId.is_target? #=> false
+ # compound = chemblId.resolve
#
class ChEMBLID < String
attr_accessor :data_type
+ # ChEMBL ID Validater
def self.validate_chemblId(str)
+ validate_chemblId(ste)
+ end
+
+ # ChEMBL ID Validater
+ def validate_chemblId(str)
unless str =~ /^CHEMBL\d+$/
- raise Exception, "Invalid ChEMBL ID."
+ raise Exception, "Invalid ChEMBL ID, '#{str}'"
end
- end
-
+ end
+
def initialize(str)
@data_type = nil
- self.validate_chemblId(str)
+ validate_chemblId(str)
super(str)
end
-
+ # Get the data of the ChEMBL ID
def resolve
case @data_type
when Compound
@@ -44,20 +55,26 @@ def resolve
Assay.find(self.to_s)
else
begin
- Compound.find(self.to_s)
+ is_compound?
rescue
end
begin
- Target.find(self.to_s)
+ is_target?
rescue
end
begin
- Assay.find(self.to_s)
+ is_assay?
rescue
+ end
+ if @data_type == nil
+ raise ArgumentError, "This ChEMBL ID is not exist, #{self.to_s}"
+ else
+ resolve
end
end
end
+ # Is the ChEMBL ID of Compound ?
def is_compound?
if @data_type == Compound
return true
@@ -70,7 +87,8 @@ def is_compound?
end
end
end
-
+
+ # Is the ChEMBL ID of Target ?
def is_target?
if @data_type == Assay
return true
@@ -84,6 +102,7 @@ def is_target?
end
end
+ # Is the ChEMBL ID of Assay ?
def is_assay?
if @data_type == Assay
return true
View
84 lib/bio-chembl/compound.rb
@@ -5,32 +5,35 @@ module BioChEMBL
# 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>
+ # 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
- # ```cpd = BioChEMBL::Compound.find("CHEMBL1")
- # cpd.chemblId #=> "CHEMLB1"
- # cpd.smiles
#
- # cpd2 = BioChEMBL::Compound.find_all_by_smiles(cpd.smile)
+ # compound = BioChEMBL::Compound.find("CHEMBL1")
+ # compound.chemblId #=> "CHEMLB1"
+ # compound.smiles
+ #
+ # compounds = BioChEMBL::Compound.find_all_by_smiles(compound.smiles)
#
- # cpd3 = BioChEMBL::Compound.parse(xml)
- # ```
+ # xml = BioChEMBL::REST.new.compounds("CHEMBL1")
+ # compound = BioChEMBL::Compound.parse_xml(xml)
+ #
class Compound
extend BioChEMBL::DataModel
@@ -56,8 +59,7 @@ class Compound
# Values of all attributes are in String.
set_attr_accessors(ATTRIBUTES)
- #
- # BioChEMBL::Compound.parse(doc)
+ # Parse the Compound data
def self.parse(str)
case str
when /^</
@@ -74,84 +76,78 @@ def self.parse(str)
end
end
- # XML
- # <compound>
+ # Parse the Compound data in XML format.
def self.parse_xml(str)
xml = Nokogiri::XML(str)
this = new
eval set_attr_values(ATTRIBUTES)
this
end
- # XML
- # <list><compound> ...
+ # Parse the Compound data list in XML format.
+ # data list: <list><compound/></list>
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
- # JSON
+ # Parse the Compound data in JSON format.
def self.parse_json(str)
raise NotImplementedError
end
- # RDF
+ # Parse the Compound data in RDF format.
def self.parse_rdf(str)
raise NotImplementedError
end
- # Compound.find(chemblId)
- # Find a compound data by a ChEMBL ID
+ # Find the Compound data by the ChEMBL ID
def self.find(chemblId)
self.parse_xml(REST.new.compounds(chemblId))
end
- # Compound.find_by_smiles(smiles)
- # Find a compound data by a SMILES
+ # Find the Compound data (first one) by the SMILES
def self.find_by_smiles(smiles)
self.find_all_by_smiles(smiles).first
end
- # Compound.find_all_by_smiles(smiles)
- # Find compounds by a SMILES.
+ # Find the Compounds by the SMILES.
def self.find_all_by_smiles(smiles)
self.parse_list_xml(REST.new.compounds_smiles(smiles))
end
- # Compound.find_by_stdinchikey(stdinchikey)
- # Find a compound data by a StdInChiKey
+ # Find the Compound data by the StdInChiKey
def self.find_by_stdinchikey(stdinchikey)
self.parse_xml(REST.new.compounds_stdinchikey(stdinchikey))
end
- # Compound.find_all_by_substructure(smiles)
- # Substructure Search by a SMILES
+ # Find the Compounds with Substructure Search by the SMILES
def self.find_all_by_substructure(smiles)
self.parse_list_xml(REST.new.compounds_substructure(smiles))
end
- # Compound.find_similarity(smiles_with_similarity)
- # Search compounds by a SMILES with similarity
+ # Find the Compounds by the SMILES with similarity
+ # 70% similarity: smiles + "/70"
def self.find_all_by_similarity(smiles_with_similarity)
self.parse_list_xml(REST.new.compounds_similarity(smiles_with_similarity))
end
- # new
def initialize(chemblId = nil)
@chemblId = chemblId
end
- # Resolve the compound data by given ChEMBL ID
+ # Resolve the Compound data by the ChEMBL ID
def resolve
resolved = self.class.find(@chemblId)
ATTRIBUTES.each do |attr|
eval "@#{attr} = resolved.#{attr}"
end
end
+
end
end
View
5 lib/bio-chembl/datamodel.rb
@@ -3,17 +3,18 @@
module BioChEMBL
- # BioChEMBL::DataModel
+ # ChEMBL database data common utilities
#
module DataModel
+ # Set attr_accessor of ATTRIBUTES
def set_attr_accessors(attributes)
attributes.each do |attr|
eval "attr_accessor :#{attr}"
end
end
-
+ # Set the values from XML data on the instance variables.
def set_attr_values(attributes)
attributes.map do |attr|
"this.#{attr} = xml.xpath('/#{self.to_s.split('::').last.downcase}/#{attr}').text"
View
98 lib/bio-chembl/rest_client.rb
@@ -11,30 +11,55 @@
module BioChEMBL
+ # ChEMBL REST Web service API Client.
+ #
+ # Usage
+ #
+ # # URI
+ # BioChEMBL::REST::ChEMBL_URI.status
+ # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1")
+ #
+ # # Low-level client
+ # client = BioChEMBL::REST.new
+ # client.status
+ # client.compounds("CHEMBL1")
+ #
+ # # Check REST API status
+ # BioChEMBL::REST.up? #=> true/false
+ #
+ #
class REST
HOST_NAME = "www.ebi.ac.uk"
API_ROOT = "chemblws"
BASE_URI = "https://" + HOST_NAME + "/" + API_ROOT
- # BioChEMBL::REST::ChEMBL_URI module
+ # ChEMBL REST Web Service URI generator
#
+ # [ChEMBL Web Services](https://www.ebi.ac.uk/chembldb/ws)
+ #
module ChEMBL_URI
+
#
def self.address(path)
"#{BASE_URI}/#{path}"
end
- # BioChEMBL::REST::ChEMBL_URI.status
+ # Check API status
def self.status
# Example URL: http://www.ebi.ac.uk/chemblws/status/
address("status/")
end
- # BioChEMBL::REST::ChEMBL_URI.compounds()
- # compounds("CHEMBL1")
+ # Get compound by ChEMBLID
+ # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1")
+ # Get image of a ChEMBL compound by ChEMBLID
+ # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'image')
+ # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'image', {'dimensions' => 200})
+ # Get individual compound bioactivities
+ # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'bioactivities')
def self.compounds(chemblId = nil, arg = nil, params = nil)
if chemblId and arg == nil and params == nil
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/CHEMBL1
@@ -52,28 +77,41 @@ def self.compounds(chemblId = nil, arg = nil, params = nil)
raise Exception, "Undefined address. ID: #{chemblId}, arg: #{arg}, params: #{params.inspect}"
end
end
- # BioChEMBL::REST::ChEMBL_URI.compounds_stdinchikey()
+
+ # Get compound by Standard InChiKey
+ # BioChEMBL::REST::ChEMBL_URI.compounds_stdinchikey(stdinchikey)
def self.compounds_stdinchikey(stdinchikey)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/stdinchikey/QFFGVLORLPOAEC-SNVBAGLBSA-N
address("compounds/stdinchikey/#{stdinchikey}")
end
- # BioChEMBL::REST::ChEMBL_URI.compounds_smiles()
+
+ # Get list of compounds matching Canonical SMILES
+ # BioChEMBL::REST::ChEMBL_URI.compounds_smiles(smiles)
def self.compounds_smiles(smiles)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/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
address("compounds/smiles/#{smiles}")
end
- # BioChEMBL::REST::ChEMBL_URI.compounds_substructure()
+
+ # Get list of compounds containing the substructure represented by a given Canonical SMILES
+ # BioChEMBL::REST::ChEMBL_URI.compounds_substructure(smiles)
def self.compounds_substructure(smiles)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/substructure/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
address("compounds/substructure/#{smiles}")
end
- # BioChEMBL::REST::ChEMBL_URI.compounds_similarity()
+
+ # Get list of compounds similar to the one represented by a given Canonical SMILES, at a given cutoff percentage
+ # BioChEMBL::REST::ChEMBL_URI.compounds_similarity(smiles + "/" + cutoff)
def self.compounds_similarity(smiles)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/similarity/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/70
address("compounds/similarity/#{smiles}")
end
- # BioChEMBL::REST::ChEMBL_URI.targets()
+ # Get target by ChEMBLID
+ # BioChEMBL::REST::ChEMBL_URI.targets(chemblId)
+ # Get individual target bioactivities
+ # BioChEMBL::REST::ChEMBL_URI.targets(chemblId, 'bioactivities')
+ # Get all targets
+ # BioChEMBL::REST::ChEMBL_URI.targets
def self.targets(chemblId = nil, arg = nil)
if chemblId and arg == nil
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/CHEMBL2477
@@ -88,18 +126,25 @@ def self.targets(chemblId = nil, arg = nil)
raise Exception, "Undefined."
end
end
- # BioChEMBL::REST::ChEMBL_URI.targets_uniprot()
+
+ # Get target by UniProt Accession Identifier
+ # BioChEMBL::REST::ChEMBL_URI.targets_uniprot(uniprot_id)
def self.targets_uniprot(uniprot_id)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/uniprot/Q13936
address("targets/uniprot/#{uniprot_id}")
end
- # BioChEMBL::REST::ChEMBL_URI.targets_refseq()
+
+ # Get target by RefSeq Accession Identifier
+ # BioChEMBL::REST::ChEMBL_URI.targets_refseq(refseq_id)
def self.targets_refseq(refseq_id)
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/refseq/NP_001128722
address("targets/refseq/#{refseq_id}")
end
- # BioChEMBL::REST::ChEMBL_URI.assays()
+ # Get assay by ChEMBLID
+ # BioChEMBL::REST::ChEMBL_URI.assays(chemblId)
+ # Get individual assay bioactivities
+ # BioChEMBL::REST::ChEMBL_URI.assays(chemblId, 'bioactivities')
def self.assays(chemblId, arg = nil)
if chemblId and arg == nil
# Example URL (XML Output): http://www.ebi.ac.uk/chemblws/assays/CHEMBL1217643
@@ -114,12 +159,12 @@ def self.assays(chemblId, arg = nil)
end
- # BioChEMBL::REST.website
+ # The ChEMBL REST Web services website
def self.website
"https://www.ebi.ac.uk/chembldb/index.php/ws"
end
- # BioChEMBL::REST.usage
+ # Usage
def self.usage
["a = Bio::DB::ChEMBL::REST.new",
"a.status => https://www.ebi.ac.uk/chembldb/index.php/ws#serviceStatus",
@@ -128,7 +173,8 @@ def self.usage
].join("\n")
end
- # BioChEMBL::REST.up? #=> true/false
+ # Check the API status
+ # BioChEMBL::REST.up? #=> true/false
def self.up?
if new.status == "UP"
true
@@ -138,7 +184,6 @@ def self.up?
end
- # new
def initialize(uri = BASE_URI)
uri = URI.parse(uri) unless uri.kind_of?(URI)
@header = {
@@ -150,7 +195,7 @@ def initialize(uri = BASE_URI)
# If true, shows debug information to $stderr.
attr_accessor :debug
- # get HTTP GET URL
+ # get the HTTP GET URL
def get(url)
easy = Curl::Easy.new(url) do |c|
@header.each do |k,v|
@@ -161,7 +206,6 @@ def get(url)
easy
end
- #
def prepare_return_value(response)
if @debug then
$stderr.puts "ChEMBL: #{response.inspect}"
@@ -180,12 +224,12 @@ def prepare_return_value(response)
end
end
- # uri
+ # URI
def uri
ChEMBL_URI
end
- # address
+ # Address
def address(path)
"#{BASE_URI}/#{path}"
end
@@ -194,6 +238,7 @@ def address(path)
# API methods
+ # Generic request builder and evaluator
def get_body(method, args = [])
code = case args.size
when 0
@@ -213,49 +258,58 @@ def get_body(method, args = [])
end
private :get_body
- #
+ # Resolve the calling method name
def current_method_name
caller(1).first.scan(/`(.*)'/)[0][0].to_s
end
private :current_method_name
-
+ # Check API status
def status
get_body(current_method_name)
end
+ # Evaluate Compound methods
def compounds(chemblId = nil, action = nil, params = nil)
get_body(current_method_name, [chemblId, action, params])
end
+ # Evaluate Compound StdInchiKey method
def compounds_stdinchikey(stdinchikey)
get_body(current_method_name, [stdinchikey])
end
+ # Evaluate Compound SMILES method
def compounds_smiles(smiles)
get_body(current_method_name, [smiles])
end
+ # Evaluate Compound SubStructure method
def compounds_substructure(smiles)
get_body(current_method_name, [smiles])
end
+ # Evaluate Compound Similarity method
def compounds_similarity(smiles)
get_body(current_method_name, [smiles])
end
+ # Evaluate Target Methods
def targets(chemblId = nil, action = nil)
get_body(current_method_name, [chemblId, action])
end
+ # Evaluate Target UniProt method
def targets_uniprot(uniprot_id)
get_body(current_method_name, [uniprot_id])
end
+ # Evaluate Target RefSeq method
def targets_refseq(refseq_id)
get_body(current_method_name, [refseq_id])
end
+ # Evaluate Assay methods
def assays(chemblId = nil, action = nil)
get_body(current_method_name, [chemblId, action])
end
View
49 lib/bio-chembl/target.rb
@@ -4,20 +4,31 @@
module BioChEMBL
- # ChEMBL Target
+ # ChEMBL Target parser and container.
#
# Data XML
- # <target>
- # <chemblId>CHEMBL1785</chemblId>
- # <targetType>PROTEIN</targetType>
- # <preferredName>Endothelin receptor ET-B</preferredName>
- # <proteinAccession>P24530</proteinAccession>
- # <synonyms>Endothelin B receptor; Endothelin receptor non-selective type; ET-B; ET-BR</synonyms>
- # <organism>Homo sapiens</organism>
- # <description>Endothelin B receptor</description>
- # <geneNames>EDNRB; ETRB</geneNames>
- # </target>
#
+ # <target>
+ # <chemblId>CHEMBL1785</chemblId>
+ # <targetType>PROTEIN</targetType>
+ # <preferredName>Endothelin receptor ET-B</preferredName>
+ # <proteinAccession>P24530</proteinAccession>
+ # <synonyms>Endothelin B receptor; Endothelin receptor non-selective type; ET-B; ET-BR</synonyms>
+ # <organism>Homo sapiens</organism>
+ # <description>Endothelin B receptor</description>
+ # <geneNames>EDNRB; ETRB</geneNames>
+ # </target>
+ #
+ # Usage
+ #
+ # target = BioChEMBL::Target.find("CHEMBL1785")
+ # target.geneNames
+ # BioChEMBL.to_array(target.geneNames)[0] #=> "EDNRB"
+ #
+ # bioactivities = target.bioactivities
+ #
+ # target = BioChEMBL::Target.find_by_uniprot("P24530")
+ #
class Target
extend BioChEMBL::DataModel
@@ -34,6 +45,7 @@ class Target
set_attr_accessors(ATTRIBUTES)
+ # Parse the Target data.
def self.parse(str)
case str
when /^</
@@ -50,54 +62,61 @@ def self.parse(str)
end
end
+ # Parse the Target data in XML format.
def self.parse_xml(str)
xml = Nokogiri::XML(str)
this = new
eval set_attr_values(ATTRIBUTES)
this
end
- # XML
- # <list><target> ...
+ # Parse the Target data list in XML format.
+ # data lsit: <list><target/></list>
def self.parse_list_xml(str)
xmls = Nokogiri::XML(str)
xmls.xpath("/list/target").map do |cpd|
self.parse_xml(cpd.to_s)
end
end
+ # Parse the Target data in JSON format.
def self.parse_json(str)
raise NotImplementedError
end
+ # Parse the Target data in RDF format.
def self.parse_rdf(str)
raise NotImplementedError
end
+ # Find the Target data by the ChEMBL ID.
def self.find(chemblId)
self.parse_xml(REST.new.targets(chemblId))
end
+ # Find the Target data by the UniProt ID.
def self.find_by_uniprot(uniprot_id)
self.parse_xml(REST.new.targets_uniprot(uniprot_id))
end
+ # Find the Target data by the RefSeq ID.
def self.find_by_refseq(refseq_id)
self.parse_xml(REST.new.targets_refseq(refseq_id))
end
- # bioactivities => [aBioactivity, ...]
+ # Get the bioactivity data list.
def bioactivities
BioChEMBL::Bioactivity.parse_list_xml(REST.new.targets(chemblId, 'bioactivities'))
end
- # Resolve the target data by given ChEMBL ID => aTarget
+ # Resolve the Target data by the ChEMBL ID
def resolve
resolved = self.class.find(@chemblId)
ATTRIBUTES.each do |attr|
eval "@#{attr} = resolved.#{attr}"
end
end
+
end
end
View
6 test/test_bio-chembl-chemblid.rb
@@ -10,9 +10,9 @@ def setup
end
def test_chemblid
- assert_equal(@chemblid.class, BioChEMBL::ChEMBLID)
- assert_equal(@chemblid, "CHEMBL1")
- assert_equal(@chemblid.data_type, nil)
+ assert_equal(BioChEMBL::ChEMBLID, @chemblid.class)
+ assert_equal("CHEMBL1", @chemblid)
+ assert_equal(nil, @chemblid.data_type)
end
def test_invalid_chembl_id
View
3 test/test_bio-chembl-chemblid.sh
@@ -1,3 +1,2 @@
-
cd /Users/mitsuteru/Applications/biogems/bioruby-chembl/
-/opt/local/bin/ruby1.9 -I lib -I test test/test_bio-chembl-chemblid.rb
+/opt/local/bin/ruby1.9 -I lib -I test test/test_bio-chembl-chemblid.rb

0 comments on commit f609ba0

Please sign in to comment.
Something went wrong with that request. Please try again.