Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update documentation

  • Loading branch information...
commit f609ba08168442378eb4c22a038f4bed5bc46eb1 1 parent 3ecd8e8
Mitsuteru Nakao authored
12 README.md
Source Rendered
@@ -18,17 +18,22 @@ REST API address
18 18 ```
19 19
20 20 Get data in XML
  21 +
21 22 ```ruby
22 23 api = BioChEMBL::REST.new
23 24 compound = api.compounds("CHEMBL1")
24 25 targst = api.targets("CHEMBL2477")
25 26 assay = api.assays("CHEMBL1217643")
26 27 ```
  28 +
27 29 Check the server status
  30 +
28 31 ```ruby
29 32 BioChEMBL::REST.up? #=> true/false
30 33 ```
  34 +
31 35 REST API client, parser and container: BioChEMBL::Compound
  36 +
32 37 ```ruby
33 38 cpd = BioChEMBL::Compound.find("CHEMBL1")
34 39 cpd.chemblId #=> "CHEMBL1"
@@ -44,7 +49,9 @@ REST API client, parser and container: BioChEMBL::Compound
44 49 xml = BioChEMBL::REST.new.compounds("CHEMBL1")
45 50 cpd = BioChEMBL::Compound.parse_xml(xml)
46 51 ```
  52 +
47 53 REST API client, parser and container: BioChEMBL::Target
  54 +
48 55 ```ruby
49 56 target = BioChEMBL::Target.find("CHEMBL1785")
50 57 target.chemblId #=> "CHEMBL1785"
@@ -62,7 +69,9 @@ REST API client, parser and container: BioChEMBL::Target
62 69 xml = BioChEMBL::REST.new.targets("CHEMBL1785")
63 70 target = BioChEMBL::Target.parse_xml(xml)
64 71 ```
  72 +
65 73 REST API client, parser and container: BioChEMBL::Assay
  74 +
66 75 ```ruby
67 76 assay = BioChEMBL::Assay.find("CHEMBL1217643")
68 77 assay.chemblId #=> "CHEMBL1217643"
@@ -76,6 +85,7 @@ REST API client, parser and container: BioChEMBL::Assay
76 85 ```
77 86
78 87 Parser and container: BioChEMBL::Bioactivity
  88 +
79 89 ```ruby
80 90 cpd.bioactivities[0].parent_compound.chemblId
81 91 target.bioactivities[0].target.chemblId
@@ -85,6 +95,7 @@ Parser and container: BioChEMBL::Bioactivity
85 95 ```
86 96
87 97 Getting Started with Ruby
  98 +
88 99 ```ruby
89 100 require 'bio-chembl'
90 101 # 1. Use UniProt accession to get target details
@@ -140,6 +151,7 @@ Getting Started with Ruby
140 151 puts " #{assay.assayDescription}"
141 152 end
142 153 ```
  154 +
143 155 Note: this software is under active development!
144 156
145 157 ## Installation
51 lib/bio-chembl/assay.rb
@@ -5,21 +5,34 @@
5 5
6 6 module BioChEMBL
7 7
8   -
9   -
10   - # ChEMBL Assay
11   - #
  8 + # ChEMBL Assay Data parser and container.
  9 + #
12 10 # Data XML
13   - # <assay>
14   - # <chemblId>CHEMBL1217643</chemblId>
15   - # <assayType>B</assayType>
16   - # <journal>Bioorg. Med. Chem. Lett.</journal>
17   - # <assayOrganism>Homo sapiens</assayOrganism>
18   - # <assayStrain>Unspecified</assayStrain>
19   - # <assayDescription>Inhibition of human hERG</assayDescription>
20   - # <numBioactivities>1</numBioactivities>
21   - # </assay>
22 11 #
  12 + # <assay>
  13 + # <chemblId>CHEMBL1217643</chemblId>
  14 + # <assayType>B</assayType>
  15 + # <journal>Bioorg. Med. Chem. Lett.</journal>
  16 + # <assayOrganism>Homo sapiens</assayOrganism>
  17 + # <assayStrain>Unspecified</assayStrain>
  18 + # <assayDescription>Inhibition of human hERG</assayDescription>
  19 + # <numBioactivities>1</numBioactivities>
  20 + # </assay>
  21 + #
  22 + # Usage
  23 + #
  24 + # assay = BioChEMBL::Assay.find("CHEMBL1217643")
  25 + # assay.assayType
  26 + # assay.assayOrganism
  27 + # ba = assay.bioactivities
  28 + #
  29 + # assay = BioChEMBL::Assay.new("CHEMBL1217643")
  30 + # assay.assayType #=> nil
  31 + # assay.resolve
  32 + # assay.assayType #=> "B"
  33 + #
  34 + # xml = BioChEMBL::REST.new.assays("CHEMBL1217643")
  35 + # assay = BioChEMBL::Assay.parse_xml(xml)
23 36 #
24 37 class Assay
25 38 extend BioChEMBL::DataModel
@@ -36,7 +49,7 @@ class Assay
36 49
37 50 set_attr_accessors(ATTRIBUTES)
38 51
39   -
  52 + # Parse the assay data.
40 53 def self.parse(str)
41 54 case str
42 55 when /^</
@@ -53,6 +66,7 @@ def self.parse(str)
53 66 end
54 67 end
55 68
  69 + # Parse the assay data in XML format.
56 70 def self.parse_xml(str)
57 71 xml = Nokogiri::XML(str)
58 72 this = new
@@ -60,25 +74,28 @@ def self.parse_xml(str)
60 74 this
61 75 end
62 76
  77 + # Parse the assay data in JSON format.
63 78 def self.parse_json(str)
64 79 raise NotImplementedError
65 80 end
66 81
  82 + # Parse the assay data in RDF format.
67 83 def self.parse_rdf(str)
68 84 raise NotImplementedError
69 85 end
70 86
  87 + # Find the assay data by ChEMBL ID via the web service.
71 88 def self.find(chemblId)
72 89 self.parse_xml(REST.new.assays(chemblId))
73 90 end
74 91
75 92
76   - # new
  93 + # Create a blank Assay instance.
77 94 def initialize(chemblId = nil)
78 95 @chemblId = chemblId
79 96 end
80 97
81   - # Resolve the compound data by given ChEMBL ID
  98 + # Resolve the assay data by given ChEMBL ID
82 99 def resolve
83 100 resolved = self.class.find(@chemblId)
84 101 ATTRIBUTES.each do |attr|
@@ -86,7 +103,7 @@ def resolve
86 103 end
87 104 end
88 105
89   - # ChEMBL Bioactivity
  106 + # Find the Bioactivity data by the assay.
90 107 def bioactivities
91 108 BioChEMBL::Bioactivity.parse_list_xml(REST.new.assays(@chemblId, 'bioactivities'))
92 109 end
76 lib/bio-chembl/bioactivity.rb
@@ -4,32 +4,48 @@
4 4
5 5 module BioChEMBL
6 6
7   - # BioChEMBL::Bioactivity
  7 + # ChEMBL Bioactivity data parser and container.
8 8 #
9 9 # Data XML
10   - # <list>
11   - # <bioactivity>
12   - # <parent__cmpd__chemblid>CHEMBL1214402</parent__cmpd__chemblid>
13   - # <ingredient__cmpd__chemblid>CHEMBL1214402</ingredient__cmpd__chemblid>
14   - # <target__chemblid>CHEMBL240</target__chemblid>
15   - # <target__confidence>9</target__confidence>
16   - # <target__name>HERG</target__name>
17   - # <reference>Bioorg. Med. Chem. Lett., (2010) 20:15:4359</reference>
18   - # <name__in__reference>26</name__in__reference>
19   - # <organism>Homo sapiens</organism>
20   - # <bioactivity__type>IC50</bioactivity__type>
21   - # <activity__comment>Unspecified</activity__comment>
22   - # <operator>=</operator>
23   - # <units>nM</units>
24   - # <assay__chemblid>CHEMBL1217643</assay__chemblid>
25   - # <assay__type>B</assay__type>
26   - # <assay__description>Inhibition of human hERG</assay__description>
  10 + #
  11 + # <list>
  12 + # <bioactivity>
  13 + # <parent__cmpd__chemblid>CHEMBL1214402</parent__cmpd__chemblid>
  14 + # <ingredient__cmpd__chemblid>CHEMBL1214402</ingredient__cmpd__chemblid>
  15 + # <target__chemblid>CHEMBL240</target__chemblid>
  16 + # <target__confidence>9</target__confidence>
  17 + # <target__name>HERG</target__name>
  18 + # <reference>Bioorg. Med. Chem. Lett., (2010) 20:15:4359</reference>
  19 + # <name__in__reference>26</name__in__reference>
  20 + # <organism>Homo sapiens</organism>
  21 + # <bioactivity__type>IC50</bioactivity__type>
  22 + # <activity__comment>Unspecified</activity__comment>
  23 + # <operator>=</operator>
  24 + # <units>nM</units>
  25 + # <assay__chemblid>CHEMBL1217643</assay__chemblid>
  26 + # <assay__type>B</assay__type>
  27 + # <assay__description>Inhibition of human hERG</assay__description>
27 28 # <value>5900</value>
28   - # </bioactivity>
29   - # </list>
  29 + # </bioactivity>
  30 + # </list>
30 31 #
31 32 # Usage
32   - #
  33 + #
  34 + # bioactivties = BioChEMBL::Compound(chemlbId).bioactivities
  35 + # bioactivties = BioChEMBL::Target(chemlbId).bioactivities
  36 + # bioactivties = BioChEMBL::Assay(chemlbId).bioactivities
  37 + #
  38 + # bioactivities.find_all {|x| x.bioactivity__type =~ /IC50/ and x.value.to_i < 100 }.each do |ba|
  39 + # assay = ba.assay
  40 + # puts "Assay CHEMBLID: #{assay.chemblId}, #{assay.assayDescription}"
  41 + # end
  42 + #
  43 + # bioactivity = bioactivities[0]
  44 + # compound = bioactivity.parent_compound
  45 + # compound = bioactivity.compound
  46 + # assay = bioactivity.assay
  47 + # target = bioactivity.target
  48 + #
33 49 class Bioactivity
34 50 extend BioChEMBL::DataModel
35 51
@@ -54,6 +70,7 @@ class Bioactivity
54 70
55 71 set_attr_accessors(ATTRIBUTES)
56 72
  73 + # Parse the Bioactivity data.
57 74 def self.parse(str)
58 75 case str
59 76 when /^</
@@ -70,6 +87,7 @@ def self.parse(str)
70 87 end
71 88 end
72 89
  90 + # Parse the Bioactivity data in XML format.
73 91 def self.parse_xml(str)
74 92 xml = Nokogiri::XML(str)
75 93 this = new
@@ -77,8 +95,8 @@ def self.parse_xml(str)
77 95 this
78 96 end
79 97
80   - # XML
81   - # <list><bioactivity> ...
  98 + # Parse the Bioactivity data list in XML format.
  99 + # data list: <list><bioactivity/></list>
82 100 def self.parse_list_xml(str)
83 101 xmls = Nokogiri::XML(str)
84 102 xmls.xpath("/list/bioactivity").map do |cpd|
@@ -86,28 +104,40 @@ def self.parse_list_xml(str)
86 104 end
87 105 end
88 106
  107 + # Parse the Bioactivity data in JSON format.
89 108 def self.parse_json(str)
90 109 raise NotImplementedError
91 110 end
92 111
  112 + # Parse the Bioactivity data in RDF format.
93 113 def self.parse_rdf(str)
94 114 raise NotImplementedError
95 115 end
96 116
  117 + # Link to the parent Compound
97 118 def parent_compound
98 119 require 'bio-chembl/compound.rb'
99 120 BioChEMBL::Compound.find(@parent__cmpd__chemblid)
100 121 end
  122 +
  123 + # Link to the Compound
  124 + def compound
  125 + require 'bio-chembl/compound.rb'
  126 + BioChEMBL::Compound.find(@ingredient__cmpd__chemblid)
  127 + end
101 128
  129 + # Link to the Target
102 130 def target
103 131 require 'bio-chembl/target.rb'
104 132 BioChEMBL::Target.find(@target__chemblid)
105 133 end
106 134
  135 + # Link to the Assay
107 136 def assay
108 137 require 'bio-chembl/assay.rb'
109 138 BioChEMBL::Assay.find(@assay__chemblid)
110 139 end
  140 +
111 141 end
112 142
113 143 end
6 lib/bio-chembl/chembl.rb
@@ -7,11 +7,15 @@
7 7 #
8 8 module BioChEMBL
9 9
  10 + # ChEMBL Website
10 11 def self.website
11 12 "https://www.ebi.ac.uk/chembl/"
12 13 end
13 14
14   - # BioChEMBL.to_array(aTarget.synonyms) #=> []
  15 + # Multi value utility
  16 + #
  17 + # BioChEMBL.to_array(aTarget.synonyms) #=> []
  18 + #
15 19 def self.to_array(str)
16 20 str.to_s.split('; ')
17 21 end
47 lib/bio-chembl/chemblid.rb
@@ -9,31 +9,42 @@
9 9
10 10 module BioChEMBL
11 11
12   - # ChEMBL ID
  12 + # ChEMBL ID Utility
13 13 #
14   - # CHEMBL1
  14 + # Format
15 15 #
16   - # cid = BioChEMBL::ChEMBLID.new("CHEMBL1")
17   - # cid.is_compound? #=> true
18   - # cid.resolve #=> aBioChEMBL::Compound
  16 + # /^CHEMBL\d+$/
  17 + #
  18 + # Usage
  19 + #
  20 + # chemblId = BioChEMBL::ChEMBLID.new("CHEMBL1")
  21 + # chemblId.is_compound? #=> true
  22 + # chemblId.is_target? #=> false
  23 + # compound = chemblId.resolve
19 24 #
20 25 class ChEMBLID < String
21 26
22 27 attr_accessor :data_type
23 28
  29 + # ChEMBL ID Validater
24 30 def self.validate_chemblId(str)
  31 + validate_chemblId(ste)
  32 + end
  33 +
  34 + # ChEMBL ID Validater
  35 + def validate_chemblId(str)
25 36 unless str =~ /^CHEMBL\d+$/
26   - raise Exception, "Invalid ChEMBL ID."
  37 + raise Exception, "Invalid ChEMBL ID, '#{str}'"
27 38 end
28   - end
29   -
  39 + end
  40 +
30 41 def initialize(str)
31 42 @data_type = nil
32   - self.validate_chemblId(str)
  43 + validate_chemblId(str)
33 44 super(str)
34 45 end
35 46
36   -
  47 + # Get the data of the ChEMBL ID
37 48 def resolve
38 49 case @data_type
39 50 when Compound
@@ -44,20 +55,26 @@ def resolve
44 55 Assay.find(self.to_s)
45 56 else
46 57 begin
47   - Compound.find(self.to_s)
  58 + is_compound?
48 59 rescue
49 60 end
50 61 begin
51   - Target.find(self.to_s)
  62 + is_target?
52 63 rescue
53 64 end
54 65 begin
55   - Assay.find(self.to_s)
  66 + is_assay?
56 67 rescue
  68 + end
  69 + if @data_type == nil
  70 + raise ArgumentError, "This ChEMBL ID is not exist, #{self.to_s}"
  71 + else
  72 + resolve
57 73 end
58 74 end
59 75 end
60 76
  77 + # Is the ChEMBL ID of Compound ?
61 78 def is_compound?
62 79 if @data_type == Compound
63 80 return true
@@ -70,7 +87,8 @@ def is_compound?
70 87 end
71 88 end
72 89 end
73   -
  90 +
  91 + # Is the ChEMBL ID of Target ?
74 92 def is_target?
75 93 if @data_type == Assay
76 94 return true
@@ -84,6 +102,7 @@ def is_target?
84 102 end
85 103 end
86 104
  105 + # Is the ChEMBL ID of Assay ?
87 106 def is_assay?
88 107 if @data_type == Assay
89 108 return true
84 lib/bio-chembl/compound.rb
@@ -5,32 +5,35 @@ module BioChEMBL
5 5
6 6 # ChEMBL Compound Data Container and Parser
7 7 #
8   - # XML Data string
9   - # <compound>
10   - # <chemblId>CHEMBL1</chemblId>
11   - # <knownDrug>No</knownDrug>
12   - # <medChemFriendly>Yes</medChemFriendly>
13   - # <passesRuleOfThree>No</passesRuleOfThree>
14   - # <molecularFormula>C32H32O8</molecularFormula>
15   - # <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>
16   - # <stdInChiKey>GHBOEFUAGSHXPO-XZOTUCIWSA-N</stdInChiKey>
17   - # <numRo5Violations>1</numRo5Violations>
18   - # <rotatableBonds>2</rotatableBonds>
19   - # <molecularWeight>544.59167</molecularWeight>
20   - # <alogp>3.627</alogp>
21   - # <acdLogp>7.669</acdLogp>
22   - # <acdLogd>7.669</acdLogd>
23   - # </compound>
  8 + # XML Data
  9 + #
  10 + # <compound>
  11 + # <chemblId>CHEMBL1</chemblId>
  12 + # <knownDrug>No</knownDrug>
  13 + # <medChemFriendly>Yes</medChemFriendly>
  14 + # <passesRuleOfThree>No</passesRuleOfThree>
  15 + # <molecularFormula>C32H32O8</molecularFormula>
  16 + # <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>
  17 + # <stdInChiKey>GHBOEFUAGSHXPO-XZOTUCIWSA-N</stdInChiKey>
  18 + # <numRo5Violations>1</numRo5Violations>
  19 + # <rotatableBonds>2</rotatableBonds>
  20 + # <molecularWeight>544.59167</molecularWeight>
  21 + # <alogp>3.627</alogp>
  22 + # <acdLogp>7.669</acdLogp>
  23 + # <acdLogd>7.669</acdLogd>
  24 + # </compound>
24 25 #
25 26 # Usage
26   - # ```cpd = BioChEMBL::Compound.find("CHEMBL1")
27   - # cpd.chemblId #=> "CHEMLB1"
28   - # cpd.smiles
29 27 #
30   - # cpd2 = BioChEMBL::Compound.find_all_by_smiles(cpd.smile)
  28 + # compound = BioChEMBL::Compound.find("CHEMBL1")
  29 + # compound.chemblId #=> "CHEMLB1"
  30 + # compound.smiles
  31 + #
  32 + # compounds = BioChEMBL::Compound.find_all_by_smiles(compound.smiles)
31 33 #
32   - # cpd3 = BioChEMBL::Compound.parse(xml)
33   - # ```
  34 + # xml = BioChEMBL::REST.new.compounds("CHEMBL1")
  35 + # compound = BioChEMBL::Compound.parse_xml(xml)
  36 + #
34 37 class Compound
35 38 extend BioChEMBL::DataModel
36 39
@@ -56,8 +59,7 @@ class Compound
56 59 # Values of all attributes are in String.
57 60 set_attr_accessors(ATTRIBUTES)
58 61
59   - #
60   - # BioChEMBL::Compound.parse(doc)
  62 + # Parse the Compound data
61 63 def self.parse(str)
62 64 case str
63 65 when /^</
@@ -74,8 +76,7 @@ def self.parse(str)
74 76 end
75 77 end
76 78
77   - # XML
78   - # <compound>
  79 + # Parse the Compound data in XML format.
79 80 def self.parse_xml(str)
80 81 xml = Nokogiri::XML(str)
81 82 this = new
@@ -83,8 +84,8 @@ def self.parse_xml(str)
83 84 this
84 85 end
85 86
86   - # XML
87   - # <list><compound> ...
  87 + # Parse the Compound data list in XML format.
  88 + # data list: <list><compound/></list>
88 89 def self.parse_list_xml(str)
89 90 xmls = Nokogiri::XML(str)
90 91 xmls.xpath("/list/compound").map do |cpd|
@@ -92,66 +93,61 @@ def self.parse_list_xml(str)
92 93 end
93 94 end
94 95
95   - # JSON
  96 + # Parse the Compound data in JSON format.
96 97 def self.parse_json(str)
97 98 raise NotImplementedError
98 99 end
99 100
100   - # RDF
  101 + # Parse the Compound data in RDF format.
101 102 def self.parse_rdf(str)
102 103 raise NotImplementedError
103 104 end
104 105
105 106
106   - # Compound.find(chemblId)
107   - # Find a compound data by a ChEMBL ID
  107 + # Find the Compound data by the ChEMBL ID
108 108 def self.find(chemblId)
109 109 self.parse_xml(REST.new.compounds(chemblId))
110 110 end
111 111
112   - # Compound.find_by_smiles(smiles)
113   - # Find a compound data by a SMILES
  112 + # Find the Compound data (first one) by the SMILES
114 113 def self.find_by_smiles(smiles)
115 114 self.find_all_by_smiles(smiles).first
116 115 end
117 116
118   - # Compound.find_all_by_smiles(smiles)
119   - # Find compounds by a SMILES.
  117 + # Find the Compounds by the SMILES.
120 118 def self.find_all_by_smiles(smiles)
121 119 self.parse_list_xml(REST.new.compounds_smiles(smiles))
122 120 end
123 121
124   - # Compound.find_by_stdinchikey(stdinchikey)
125   - # Find a compound data by a StdInChiKey
  122 + # Find the Compound data by the StdInChiKey
126 123 def self.find_by_stdinchikey(stdinchikey)
127 124 self.parse_xml(REST.new.compounds_stdinchikey(stdinchikey))
128 125 end
129 126
130   - # Compound.find_all_by_substructure(smiles)
131   - # Substructure Search by a SMILES
  127 + # Find the Compounds with Substructure Search by the SMILES
132 128 def self.find_all_by_substructure(smiles)
133 129 self.parse_list_xml(REST.new.compounds_substructure(smiles))
134 130 end
135 131
136   - # Compound.find_similarity(smiles_with_similarity)
137   - # Search compounds by a SMILES with similarity
  132 + # Find the Compounds by the SMILES with similarity
  133 + # 70% similarity: smiles + "/70"
138 134 def self.find_all_by_similarity(smiles_with_similarity)
139 135 self.parse_list_xml(REST.new.compounds_similarity(smiles_with_similarity))
140 136 end
141 137
142 138
143   - # new
144 139 def initialize(chemblId = nil)
145 140 @chemblId = chemblId
146 141 end
147 142
148   - # Resolve the compound data by given ChEMBL ID
  143 + # Resolve the Compound data by the ChEMBL ID
149 144 def resolve
150 145 resolved = self.class.find(@chemblId)
151 146 ATTRIBUTES.each do |attr|
152 147 eval "@#{attr} = resolved.#{attr}"
153 148 end
154 149 end
  150 +
155 151 end
156 152
157 153 end
5 lib/bio-chembl/datamodel.rb
@@ -3,17 +3,18 @@
3 3
4 4 module BioChEMBL
5 5
6   - # BioChEMBL::DataModel
  6 + # ChEMBL database data common utilities
7 7 #
8 8 module DataModel
9 9
  10 + # Set attr_accessor of ATTRIBUTES
10 11 def set_attr_accessors(attributes)
11 12 attributes.each do |attr|
12 13 eval "attr_accessor :#{attr}"
13 14 end
14 15 end
15 16
16   -
  17 + # Set the values from XML data on the instance variables.
17 18 def set_attr_values(attributes)
18 19 attributes.map do |attr|
19 20 "this.#{attr} = xml.xpath('/#{self.to_s.split('::').last.downcase}/#{attr}').text"
98 lib/bio-chembl/rest_client.rb
@@ -11,6 +11,23 @@
11 11
12 12 module BioChEMBL
13 13
  14 + # ChEMBL REST Web service API Client.
  15 + #
  16 + # Usage
  17 + #
  18 + # # URI
  19 + # BioChEMBL::REST::ChEMBL_URI.status
  20 + # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1")
  21 + #
  22 + # # Low-level client
  23 + # client = BioChEMBL::REST.new
  24 + # client.status
  25 + # client.compounds("CHEMBL1")
  26 + #
  27 + # # Check REST API status
  28 + # BioChEMBL::REST.up? #=> true/false
  29 + #
  30 + #
14 31 class REST
15 32
16 33 HOST_NAME = "www.ebi.ac.uk"
@@ -18,23 +35,31 @@ class REST
18 35 BASE_URI = "https://" + HOST_NAME + "/" + API_ROOT
19 36
20 37
21   - # BioChEMBL::REST::ChEMBL_URI module
  38 + # ChEMBL REST Web Service URI generator
22 39 #
  40 + # [ChEMBL Web Services](https://www.ebi.ac.uk/chembldb/ws)
  41 + #
23 42 module ChEMBL_URI
  43 +
24 44 #
25 45 def self.address(path)
26 46 "#{BASE_URI}/#{path}"
27 47 end
28 48
29 49
30   - # BioChEMBL::REST::ChEMBL_URI.status
  50 + # Check API status
31 51 def self.status
32 52 # Example URL: http://www.ebi.ac.uk/chemblws/status/
33 53 address("status/")
34 54 end
35 55
36   - # BioChEMBL::REST::ChEMBL_URI.compounds()
37   - # compounds("CHEMBL1")
  56 + # Get compound by ChEMBLID
  57 + # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1")
  58 + # Get image of a ChEMBL compound by ChEMBLID
  59 + # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'image')
  60 + # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'image', {'dimensions' => 200})
  61 + # Get individual compound bioactivities
  62 + # BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1", 'bioactivities')
38 63 def self.compounds(chemblId = nil, arg = nil, params = nil)
39 64 if chemblId and arg == nil and params == nil
40 65 # 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)
52 77 raise Exception, "Undefined address. ID: #{chemblId}, arg: #{arg}, params: #{params.inspect}"
53 78 end
54 79 end
55   - # BioChEMBL::REST::ChEMBL_URI.compounds_stdinchikey()
  80 +
  81 + # Get compound by Standard InChiKey
  82 + # BioChEMBL::REST::ChEMBL_URI.compounds_stdinchikey(stdinchikey)
56 83 def self.compounds_stdinchikey(stdinchikey)
57 84 # Example URL (XML Output): http://www.ebi.ac.uk/chemblws/compounds/stdinchikey/QFFGVLORLPOAEC-SNVBAGLBSA-N
58 85 address("compounds/stdinchikey/#{stdinchikey}")
59 86 end
60   - # BioChEMBL::REST::ChEMBL_URI.compounds_smiles()
  87 +
  88 + # Get list of compounds matching Canonical SMILES
  89 + # BioChEMBL::REST::ChEMBL_URI.compounds_smiles(smiles)
61 90 def self.compounds_smiles(smiles)
62 91 # 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
63 92 address("compounds/smiles/#{smiles}")
64 93 end
65   - # BioChEMBL::REST::ChEMBL_URI.compounds_substructure()
  94 +
  95 + # Get list of compounds containing the substructure represented by a given Canonical SMILES
  96 + # BioChEMBL::REST::ChEMBL_URI.compounds_substructure(smiles)
66 97 def self.compounds_substructure(smiles)
67 98 # 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
68 99 address("compounds/substructure/#{smiles}")
69 100 end
70   - # BioChEMBL::REST::ChEMBL_URI.compounds_similarity()
  101 +
  102 + # Get list of compounds similar to the one represented by a given Canonical SMILES, at a given cutoff percentage
  103 + # BioChEMBL::REST::ChEMBL_URI.compounds_similarity(smiles + "/" + cutoff)
71 104 def self.compounds_similarity(smiles)
72 105 # 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
73 106 address("compounds/similarity/#{smiles}")
74 107 end
75 108
76   - # BioChEMBL::REST::ChEMBL_URI.targets()
  109 + # Get target by ChEMBLID
  110 + # BioChEMBL::REST::ChEMBL_URI.targets(chemblId)
  111 + # Get individual target bioactivities
  112 + # BioChEMBL::REST::ChEMBL_URI.targets(chemblId, 'bioactivities')
  113 + # Get all targets
  114 + # BioChEMBL::REST::ChEMBL_URI.targets
77 115 def self.targets(chemblId = nil, arg = nil)
78 116 if chemblId and arg == nil
79 117 # Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/CHEMBL2477
@@ -88,18 +126,25 @@ def self.targets(chemblId = nil, arg = nil)
88 126 raise Exception, "Undefined."
89 127 end
90 128 end
91   - # BioChEMBL::REST::ChEMBL_URI.targets_uniprot()
  129 +
  130 + # Get target by UniProt Accession Identifier
  131 + # BioChEMBL::REST::ChEMBL_URI.targets_uniprot(uniprot_id)
92 132 def self.targets_uniprot(uniprot_id)
93 133 # Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/uniprot/Q13936
94 134 address("targets/uniprot/#{uniprot_id}")
95 135 end
96   - # BioChEMBL::REST::ChEMBL_URI.targets_refseq()
  136 +
  137 + # Get target by RefSeq Accession Identifier
  138 + # BioChEMBL::REST::ChEMBL_URI.targets_refseq(refseq_id)
97 139 def self.targets_refseq(refseq_id)
98 140 # Example URL (XML Output): http://www.ebi.ac.uk/chemblws/targets/refseq/NP_001128722
99 141 address("targets/refseq/#{refseq_id}")
100 142 end
101 143
102   - # BioChEMBL::REST::ChEMBL_URI.assays()
  144 + # Get assay by ChEMBLID
  145 + # BioChEMBL::REST::ChEMBL_URI.assays(chemblId)
  146 + # Get individual assay bioactivities
  147 + # BioChEMBL::REST::ChEMBL_URI.assays(chemblId, 'bioactivities')
103 148 def self.assays(chemblId, arg = nil)
104 149 if chemblId and arg == nil
105 150 # Example URL (XML Output): http://www.ebi.ac.uk/chemblws/assays/CHEMBL1217643
@@ -114,12 +159,12 @@ def self.assays(chemblId, arg = nil)
114 159 end
115 160
116 161
117   - # BioChEMBL::REST.website
  162 + # The ChEMBL REST Web services website
118 163 def self.website
119 164 "https://www.ebi.ac.uk/chembldb/index.php/ws"
120 165 end
121 166
122   - # BioChEMBL::REST.usage
  167 + # Usage
123 168 def self.usage
124 169 ["a = Bio::DB::ChEMBL::REST.new",
125 170 "a.status => https://www.ebi.ac.uk/chembldb/index.php/ws#serviceStatus",
@@ -128,7 +173,8 @@ def self.usage
128 173 ].join("\n")
129 174 end
130 175
131   - # BioChEMBL::REST.up? #=> true/false
  176 + # Check the API status
  177 + # BioChEMBL::REST.up? #=> true/false
132 178 def self.up?
133 179 if new.status == "UP"
134 180 true
@@ -138,7 +184,6 @@ def self.up?
138 184 end
139 185
140 186
141   - # new
142 187 def initialize(uri = BASE_URI)
143 188 uri = URI.parse(uri) unless uri.kind_of?(URI)
144 189 @header = {
@@ -150,7 +195,7 @@ def initialize(uri = BASE_URI)
150 195 # If true, shows debug information to $stderr.
151 196 attr_accessor :debug
152 197
153   - # get HTTP GET URL
  198 + # get the HTTP GET URL
154 199 def get(url)
155 200 easy = Curl::Easy.new(url) do |c|
156 201 @header.each do |k,v|
@@ -161,7 +206,6 @@ def get(url)
161 206 easy
162 207 end
163 208
164   - #
165 209 def prepare_return_value(response)
166 210 if @debug then
167 211 $stderr.puts "ChEMBL: #{response.inspect}"
@@ -180,12 +224,12 @@ def prepare_return_value(response)
180 224 end
181 225 end
182 226
183   - # uri
  227 + # URI
184 228 def uri
185 229 ChEMBL_URI
186 230 end
187 231
188   - # address
  232 + # Address
189 233 def address(path)
190 234 "#{BASE_URI}/#{path}"
191 235 end
@@ -194,6 +238,7 @@ def address(path)
194 238
195 239 # API methods
196 240
  241 + # Generic request builder and evaluator
197 242 def get_body(method, args = [])
198 243 code = case args.size
199 244 when 0
@@ -213,49 +258,58 @@ def get_body(method, args = [])
213 258 end
214 259 private :get_body
215 260
216   - #
  261 + # Resolve the calling method name
217 262 def current_method_name
218 263 caller(1).first.scan(/`(.*)'/)[0][0].to_s
219 264 end
220 265 private :current_method_name
221 266
222   -
  267 + # Check API status
223 268 def status
224 269 get_body(current_method_name)
225 270 end
226 271
  272 + # Evaluate Compound methods
227 273 def compounds(chemblId = nil, action = nil, params = nil)
228 274 get_body(current_method_name, [chemblId, action, params])
229 275 end
230 276
  277 + # Evaluate Compound StdInchiKey method
231 278 def compounds_stdinchikey(stdinchikey)
232 279 get_body(current_method_name, [stdinchikey])
233 280 end
234 281
  282 + # Evaluate Compound SMILES method
235 283 def compounds_smiles(smiles)
236 284 get_body(current_method_name, [smiles])
237 285 end
238 286
  287 + # Evaluate Compound SubStructure method
239 288 def compounds_substructure(smiles)
240 289 get_body(current_method_name, [smiles])
241 290 end
242 291
  292 + # Evaluate Compound Similarity method
243 293 def compounds_similarity(smiles)
244 294 get_body(current_method_name, [smiles])
245 295 end
246 296
  297 + # Evaluate Target Methods
247 298 def targets(chemblId = nil, action = nil)
248 299 get_body(current_method_name, [chemblId, action])
249 300 end
250 301
  302 + # Evaluate Target UniProt method
251 303 def targets_uniprot(uniprot_id)
252 304 get_body(current_method_name, [uniprot_id])
253 305 end
254 306
  307 + # Evaluate Target RefSeq method
255 308 def targets_refseq(refseq_id)
256 309 get_body(current_method_name, [refseq_id])
257 310 end
258 311
  312 + # Evaluate Assay methods
259 313 def assays(chemblId = nil, action = nil)
260 314 get_body(current_method_name, [chemblId, action])
261 315 end
49 lib/bio-chembl/target.rb
@@ -4,20 +4,31 @@
4 4
5 5 module BioChEMBL
6 6
7   - # ChEMBL Target
  7 + # ChEMBL Target parser and container.
8 8 #
9 9 # Data XML
10   - # <target>
11   - # <chemblId>CHEMBL1785</chemblId>
12   - # <targetType>PROTEIN</targetType>
13   - # <preferredName>Endothelin receptor ET-B</preferredName>
14   - # <proteinAccession>P24530</proteinAccession>
15   - # <synonyms>Endothelin B receptor; Endothelin receptor non-selective type; ET-B; ET-BR</synonyms>
16   - # <organism>Homo sapiens</organism>
17   - # <description>Endothelin B receptor</description>
18   - # <geneNames>EDNRB; ETRB</geneNames>
19   - # </target>
20 10 #
  11 + # <target>
  12 + # <chemblId>CHEMBL1785</chemblId>
  13 + # <targetType>PROTEIN</targetType>
  14 + # <preferredName>Endothelin receptor ET-B</preferredName>
  15 + # <proteinAccession>P24530</proteinAccession>
  16 + # <synonyms>Endothelin B receptor; Endothelin receptor non-selective type; ET-B; ET-BR</synonyms>
  17 + # <organism>Homo sapiens</organism>
  18 + # <description>Endothelin B receptor</description>
  19 + # <geneNames>EDNRB; ETRB</geneNames>
  20 + # </target>
  21 + #
  22 + # Usage
  23 + #
  24 + # target = BioChEMBL::Target.find("CHEMBL1785")
  25 + # target.geneNames
  26 + # BioChEMBL.to_array(target.geneNames)[0] #=> "EDNRB"
  27 + #
  28 + # bioactivities = target.bioactivities
  29 + #
  30 + # target = BioChEMBL::Target.find_by_uniprot("P24530")
  31 + #
21 32 class Target
22 33 extend BioChEMBL::DataModel
23 34
@@ -34,6 +45,7 @@ class Target
34 45
35 46 set_attr_accessors(ATTRIBUTES)
36 47
  48 + # Parse the Target data.
37 49 def self.parse(str)
38 50 case str
39 51 when /^</
@@ -50,6 +62,7 @@ def self.parse(str)
50 62 end
51 63 end
52 64
  65 + # Parse the Target data in XML format.
53 66 def self.parse_xml(str)
54 67 xml = Nokogiri::XML(str)
55 68 this = new
@@ -57,8 +70,8 @@ def self.parse_xml(str)
57 70 this
58 71 end
59 72
60   - # XML
61   - # <list><target> ...
  73 + # Parse the Target data list in XML format.
  74 + # data lsit: <list><target/></list>
62 75 def self.parse_list_xml(str)
63 76 xmls = Nokogiri::XML(str)
64 77 xmls.xpath("/list/target").map do |cpd|
@@ -66,38 +79,44 @@ def self.parse_list_xml(str)
66 79 end
67 80 end
68 81
  82 + # Parse the Target data in JSON format.
69 83 def self.parse_json(str)
70 84 raise NotImplementedError
71 85 end
72 86
  87 + # Parse the Target data in RDF format.
73 88 def self.parse_rdf(str)
74 89 raise NotImplementedError
75 90 end
76 91
  92 + # Find the Target data by the ChEMBL ID.
77 93 def self.find(chemblId)
78 94 self.parse_xml(REST.new.targets(chemblId))
79 95 end
80 96
  97 + # Find the Target data by the UniProt ID.
81 98 def self.find_by_uniprot(uniprot_id)
82 99 self.parse_xml(REST.new.targets_uniprot(uniprot_id))
83 100 end
84 101
  102 + # Find the Target data by the RefSeq ID.
85 103 def self.find_by_refseq(refseq_id)
86 104 self.parse_xml(REST.new.targets_refseq(refseq_id))
87 105 end
88 106
89   - # bioactivities => [aBioactivity, ...]
  107 + # Get the bioactivity data list.
90 108 def bioactivities
91 109 BioChEMBL::Bioactivity.parse_list_xml(REST.new.targets(chemblId, 'bioactivities'))
92 110 end
93 111
94   - # Resolve the target data by given ChEMBL ID => aTarget
  112 + # Resolve the Target data by the ChEMBL ID
95 113 def resolve
96 114 resolved = self.class.find(@chemblId)
97 115 ATTRIBUTES.each do |attr|
98 116 eval "@#{attr} = resolved.#{attr}"
99 117 end
100 118 end
  119 +
101 120 end
102 121
103 122 end
6 test/test_bio-chembl-chemblid.rb
@@ -10,9 +10,9 @@ def setup
10 10 end
11 11
12 12 def test_chemblid
13   - assert_equal(@chemblid.class, BioChEMBL::ChEMBLID)
14   - assert_equal(@chemblid, "CHEMBL1")
15   - assert_equal(@chemblid.data_type, nil)
  13 + assert_equal(BioChEMBL::ChEMBLID, @chemblid.class)
  14 + assert_equal("CHEMBL1", @chemblid)
  15 + assert_equal(nil, @chemblid.data_type)
16 16 end
17 17
18 18 def test_invalid_chembl_id
3  test/test_bio-chembl-chemblid.sh
... ... @@ -1,3 +1,2 @@
1   -
2 1 cd /Users/mitsuteru/Applications/biogems/bioruby-chembl/
3   -/opt/local/bin/ruby1.9 -I lib -I test test/test_bio-chembl-chemblid.rb
  2 +/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.