bio-chembl 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -6
- data/VERSION +1 -1
- data/bio-chembl.gemspec +2 -3
- data/lib/bio-chembl/assay.rb +34 -17
- data/lib/bio-chembl/bioactivity.rb +53 -23
- data/lib/bio-chembl/chembl.rb +5 -1
- data/lib/bio-chembl/chemblid.rb +65 -38
- data/lib/bio-chembl/compound.rb +40 -44
- data/lib/bio-chembl/datamodel.rb +3 -2
- data/lib/bio-chembl/rest_client.rb +77 -22
- data/lib/bio-chembl/target.rb +34 -15
- data/test/test_bio-chembl-chemblid.rb +41 -8
- data/test/test_bio-chembl-chemblid.sh +1 -2
- metadata +4 -5
- data/lib/bio-chembl/rest_api_server.rb +0 -40
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# bio-chembl
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/nakao/
|
3
|
+
[![Build Status](https://secure.travis-ci.org/nakao/bio-chembl.png)](http://travis-ci.org/nakao/bio-chembl)
|
4
4
|
|
5
5
|
[ChEMBL REST Web Service API](https://www.ebi.ac.uk/chembldb/ws) client, parser and container classes.
|
6
6
|
|
@@ -8,27 +8,32 @@ REST API address
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
BioChEMBL::REST::ChEMBL_URI.status
|
11
|
-
#=> "
|
11
|
+
#=> "https://www.ebi.ac.uk/chemblws/status/"
|
12
12
|
BioChEMBL::REST::ChEMBL_URI.compounds("CHEMBL1")
|
13
|
-
#=> "
|
13
|
+
#=> "https://www.ebi.ac.uk/chemblws/compounds/CHEMBL1"
|
14
14
|
BioChEMBL::REST::ChEMBL_URI.targets("CHEMBL2477")
|
15
|
-
#=> "
|
15
|
+
#=> "https://www.ebi.ac.uk/chemblws/targets/CHEMBL2477"
|
16
16
|
BioChEMBL::REST::ChEMBL_URI.assays("CHEMBL1217643")
|
17
|
-
#=> "
|
17
|
+
#=> "https://www.ebi.ac.uk/chemblws/assays/CHEMBL1217643"
|
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
|
@@ -171,8 +183,9 @@ The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
|
|
171
183
|
* BioChEMBL::Compound#image method to get the image in png.
|
172
184
|
* BioChEMBL::Target.find_by_refesq method.
|
173
185
|
* JSON output support (parser and address).
|
174
|
-
* ChEMBL RDF
|
186
|
+
* ChEMBL RDF integration.
|
175
187
|
* Local REST API server with local ChEMBL database.
|
188
|
+
* Connect Bioactivity#reference to external IDs (PubMed ID/DOI/CiteXplore)
|
176
189
|
|
177
190
|
## Cite
|
178
191
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bio-chembl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bio-chembl}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mitsuteru Nakao"]
|
12
|
-
s.date = %q{2012-07-
|
12
|
+
s.date = %q{2012-07-23}
|
13
13
|
s.description = %q{BioRuby plugin for ChEMBL REST API Client, Parser and Container classes}
|
14
14
|
s.email = %q{mitsuteru.nakao@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -34,7 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/bio-chembl/chemblid.rb",
|
35
35
|
"lib/bio-chembl/compound.rb",
|
36
36
|
"lib/bio-chembl/datamodel.rb",
|
37
|
-
"lib/bio-chembl/rest_api_server.rb",
|
38
37
|
"lib/bio-chembl/rest_client.rb",
|
39
38
|
"lib/bio-chembl/target.rb",
|
40
39
|
"test/helper.rb",
|
data/lib/bio-chembl/assay.rb
CHANGED
@@ -5,21 +5,34 @@ require 'bio-chembl/bioactivity.rb'
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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
|
-
#
|
93
|
+
# Create a blank Assay instance.
|
77
94
|
def initialize(chemblId = nil)
|
78
95
|
@chemblId = chemblId
|
79
96
|
end
|
80
97
|
|
81
|
-
# Resolve the
|
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 @@ module BioChEMBL
|
|
86
103
|
end
|
87
104
|
end
|
88
105
|
|
89
|
-
#
|
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
|
@@ -4,32 +4,48 @@ require 'bio-chembl/datamodel.rb'
|
|
4
4
|
|
5
5
|
module BioChEMBL
|
6
6
|
|
7
|
-
#
|
7
|
+
# ChEMBL Bioactivity data parser and container.
|
8
8
|
#
|
9
9
|
# Data XML
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
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
|
-
#
|
29
|
-
#
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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
|
data/lib/bio-chembl/chembl.rb
CHANGED
@@ -7,11 +7,15 @@ require 'nokogiri'
|
|
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
|
-
#
|
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
|
data/lib/bio-chembl/chemblid.rb
CHANGED
@@ -9,89 +9,116 @@ require 'nokogiri'
|
|
9
9
|
|
10
10
|
module BioChEMBL
|
11
11
|
|
12
|
-
# ChEMBL ID
|
12
|
+
# ChEMBL ID utility String
|
13
13
|
#
|
14
|
-
#
|
14
|
+
# Format
|
15
15
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
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
|
24
|
+
#
|
25
|
+
# BioChEMBL::ChEMBLID.validate("CHEMBL1")
|
19
26
|
#
|
20
27
|
class ChEMBLID < String
|
21
28
|
|
22
29
|
attr_accessor :data_type
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
|
32
|
+
# Checking the format of the ChEMBL ID
|
33
|
+
def self.valid_format?(str)
|
34
|
+
begin
|
35
|
+
self.new(str)
|
36
|
+
true
|
37
|
+
rescue Exception
|
38
|
+
false
|
27
39
|
end
|
28
40
|
end
|
29
|
-
|
41
|
+
|
42
|
+
# ChEMBL ID Validater
|
43
|
+
def validate_chemblId(str)
|
44
|
+
if str =~ /^CHEMBL\d+$/
|
45
|
+
true
|
46
|
+
else
|
47
|
+
raise Exception, "Invalid ChEMBL ID, '#{str}'"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
private :validate_chemblId
|
51
|
+
|
30
52
|
def initialize(str)
|
31
53
|
@data_type = nil
|
32
|
-
|
54
|
+
validate_chemblId(str)
|
33
55
|
super(str)
|
34
56
|
end
|
35
57
|
|
36
|
-
|
58
|
+
# Get the data of the ChEMBL ID (Slow)
|
37
59
|
def resolve
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
Assay.find(self.to_s)
|
60
|
+
if @data_type == Compound
|
61
|
+
return Compound.find(self.to_s)
|
62
|
+
elsif @data_type == Target
|
63
|
+
return Target.find(self.to_s)
|
64
|
+
elsif @data_type == Assay
|
65
|
+
return Assay.find(self.to_s)
|
45
66
|
else
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
begin
|
55
|
-
Assay.find(self.to_s)
|
56
|
-
rescue
|
67
|
+
if is_compound?
|
68
|
+
elsif is_target?
|
69
|
+
elsif is_assay?
|
70
|
+
end
|
71
|
+
if @data_type == nil
|
72
|
+
raise ArgumentError, "This ChEMBL ID is not exist, #{self.to_s}"
|
73
|
+
else
|
74
|
+
resolve
|
57
75
|
end
|
58
76
|
end
|
59
77
|
end
|
60
78
|
|
79
|
+
|
80
|
+
# Is the ChEMBL ID of Compound ?
|
61
81
|
def is_compound?
|
62
82
|
if @data_type == Compound
|
63
83
|
return true
|
64
84
|
else
|
65
|
-
|
85
|
+
begin
|
86
|
+
Compound.find(self)
|
66
87
|
@data_type = Compound
|
67
88
|
return true
|
68
|
-
|
89
|
+
rescue Exception
|
69
90
|
return false
|
70
91
|
end
|
71
92
|
end
|
72
93
|
end
|
73
|
-
|
94
|
+
|
95
|
+
|
96
|
+
# Is the ChEMBL ID of Target ?
|
74
97
|
def is_target?
|
75
|
-
if @data_type ==
|
98
|
+
if @data_type == Target
|
76
99
|
return true
|
77
100
|
else
|
78
|
-
|
79
|
-
|
101
|
+
begin
|
102
|
+
Target.find(self)
|
103
|
+
@data_type = Target
|
80
104
|
return true
|
81
|
-
|
105
|
+
rescue Exception
|
82
106
|
return false
|
83
107
|
end
|
84
108
|
end
|
85
109
|
end
|
86
110
|
|
111
|
+
|
112
|
+
# Is the ChEMBL ID of Assay ?
|
87
113
|
def is_assay?
|
88
114
|
if @data_type == Assay
|
89
115
|
return true
|
90
116
|
else
|
91
|
-
|
117
|
+
begin
|
118
|
+
Assay.find(self)
|
92
119
|
@data_type = Assay
|
93
120
|
return true
|
94
|
-
|
121
|
+
rescue Exception
|
95
122
|
return false
|
96
123
|
end
|
97
124
|
end
|
data/lib/bio-chembl/compound.rb
CHANGED
@@ -5,32 +5,35 @@ module BioChEMBL
|
|
5
5
|
|
6
6
|
# ChEMBL Compound Data Container and Parser
|
7
7
|
#
|
8
|
-
# XML Data
|
9
|
-
#
|
10
|
-
# <
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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
|
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
|
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
|
-
#
|
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
|
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
|
-
#
|
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
|
-
#
|
137
|
-
#
|
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
|
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
|
data/lib/bio-chembl/datamodel.rb
CHANGED
@@ -3,17 +3,18 @@ require 'nokogiri'
|
|
3
3
|
|
4
4
|
module BioChEMBL
|
5
5
|
|
6
|
-
#
|
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"
|
@@ -11,6 +11,23 @@ require 'bio-chembl/bioactivity.rb'
|
|
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 @@ module BioChEMBL
|
|
18
35
|
BASE_URI = "https://" + HOST_NAME + "/" + API_ROOT
|
19
36
|
|
20
37
|
|
21
|
-
#
|
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
|
-
#
|
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
|
-
#
|
37
|
-
#
|
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 @@ module BioChEMBL
|
|
52
77
|
raise Exception, "Undefined address. ID: #{chemblId}, arg: #{arg}, params: #{params.inspect}"
|
53
78
|
end
|
54
79
|
end
|
55
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
#
|
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 @@ module BioChEMBL
|
|
88
126
|
raise Exception, "Undefined."
|
89
127
|
end
|
90
128
|
end
|
91
|
-
|
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
|
-
|
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
|
-
#
|
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 @@ module BioChEMBL
|
|
114
159
|
end
|
115
160
|
|
116
161
|
|
117
|
-
#
|
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
|
-
#
|
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 @@ module BioChEMBL
|
|
128
173
|
].join("\n")
|
129
174
|
end
|
130
175
|
|
131
|
-
#
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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,7 @@ module BioChEMBL
|
|
161
206
|
easy
|
162
207
|
end
|
163
208
|
|
164
|
-
#
|
209
|
+
# HTTP responce handling
|
165
210
|
def prepare_return_value(response)
|
166
211
|
if @debug then
|
167
212
|
$stderr.puts "ChEMBL: #{response.inspect}"
|
@@ -180,12 +225,12 @@ module BioChEMBL
|
|
180
225
|
end
|
181
226
|
end
|
182
227
|
|
183
|
-
#
|
228
|
+
# URI
|
184
229
|
def uri
|
185
230
|
ChEMBL_URI
|
186
231
|
end
|
187
232
|
|
188
|
-
#
|
233
|
+
# Address
|
189
234
|
def address(path)
|
190
235
|
"#{BASE_URI}/#{path}"
|
191
236
|
end
|
@@ -194,6 +239,7 @@ module BioChEMBL
|
|
194
239
|
|
195
240
|
# API methods
|
196
241
|
|
242
|
+
# Generic request builder and evaluator
|
197
243
|
def get_body(method, args = [])
|
198
244
|
code = case args.size
|
199
245
|
when 0
|
@@ -213,49 +259,58 @@ module BioChEMBL
|
|
213
259
|
end
|
214
260
|
private :get_body
|
215
261
|
|
216
|
-
#
|
262
|
+
# Resolve the calling method name
|
217
263
|
def current_method_name
|
218
264
|
caller(1).first.scan(/`(.*)'/)[0][0].to_s
|
219
265
|
end
|
220
266
|
private :current_method_name
|
221
267
|
|
222
|
-
|
268
|
+
# Check API status
|
223
269
|
def status
|
224
270
|
get_body(current_method_name)
|
225
271
|
end
|
226
272
|
|
273
|
+
# Evaluate Compound methods
|
227
274
|
def compounds(chemblId = nil, action = nil, params = nil)
|
228
275
|
get_body(current_method_name, [chemblId, action, params])
|
229
276
|
end
|
230
277
|
|
278
|
+
# Evaluate Compound StdInchiKey method
|
231
279
|
def compounds_stdinchikey(stdinchikey)
|
232
280
|
get_body(current_method_name, [stdinchikey])
|
233
281
|
end
|
234
282
|
|
283
|
+
# Evaluate Compound SMILES method
|
235
284
|
def compounds_smiles(smiles)
|
236
285
|
get_body(current_method_name, [smiles])
|
237
286
|
end
|
238
287
|
|
288
|
+
# Evaluate Compound SubStructure method
|
239
289
|
def compounds_substructure(smiles)
|
240
290
|
get_body(current_method_name, [smiles])
|
241
291
|
end
|
242
292
|
|
293
|
+
# Evaluate Compound Similarity method
|
243
294
|
def compounds_similarity(smiles)
|
244
295
|
get_body(current_method_name, [smiles])
|
245
296
|
end
|
246
297
|
|
298
|
+
# Evaluate Target Methods
|
247
299
|
def targets(chemblId = nil, action = nil)
|
248
300
|
get_body(current_method_name, [chemblId, action])
|
249
301
|
end
|
250
302
|
|
303
|
+
# Evaluate Target UniProt method
|
251
304
|
def targets_uniprot(uniprot_id)
|
252
305
|
get_body(current_method_name, [uniprot_id])
|
253
306
|
end
|
254
307
|
|
308
|
+
# Evaluate Target RefSeq method
|
255
309
|
def targets_refseq(refseq_id)
|
256
310
|
get_body(current_method_name, [refseq_id])
|
257
311
|
end
|
258
312
|
|
313
|
+
# Evaluate Assay methods
|
259
314
|
def assays(chemblId = nil, action = nil)
|
260
315
|
get_body(current_method_name, [chemblId, action])
|
261
316
|
end
|
data/lib/bio-chembl/target.rb
CHANGED
@@ -4,20 +4,31 @@ require 'bio-chembl/bioactivity.rb'
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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 @@ module BioChEMBL
|
|
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
|
-
#
|
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
|
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
|
@@ -10,27 +10,60 @@ class TestBioChemblChembId < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_chemblid
|
13
|
-
assert_equal(@chemblid.class
|
14
|
-
assert_equal(
|
15
|
-
assert_equal(@chemblid.data_type
|
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
|
19
19
|
assert_raise(Exception) {
|
20
|
-
BioChEMBL::
|
20
|
+
BioChEMBL::ChEMBLID.new("CHEMBLCHEMBL1")
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_chemblid_validate
|
25
|
+
assert_equal(true, BioChEMBL::ChEMBLID.valid_format?(@str))
|
26
|
+
assert_equal(false, BioChEMBL::ChEMBLID.valid_format?("CHEMBLCHEMBL1"))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_resolve
|
30
|
+
compound = @chemblid.resolve
|
31
|
+
assert_equal(BioChEMBL::Compound, @chemblid.data_type)
|
32
|
+
assert_equal(@chemblid, compound.chemblId)
|
33
|
+
assert_equal("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", compound.smiles)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_resolve_target
|
37
|
+
target = BioChEMBL::ChEMBLID.new("CHEMBL1785").resolve
|
38
|
+
assert_equal(BioChEMBL::Target, target.class)
|
39
|
+
assert_equal("CHEMBL1785", target.chemblId)
|
40
|
+
assert_equal("PROTEIN", target.targetType)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_resolve_assay
|
44
|
+
assay = BioChEMBL::ChEMBLID.new("CHEMBL1217643").resolve
|
45
|
+
assert_equal(BioChEMBL::Assay, assay.class)
|
46
|
+
assert_equal("CHEMBL1217643", assay.chemblId)
|
47
|
+
assert_equal("B", assay.assayType)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_resolve_invalid
|
51
|
+
assert_raise(ArgumentError) {
|
52
|
+
dummy = BioChEMBL::ChEMBLID.new("CHEMBL11111111111111217643").resolve
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
|
24
57
|
def test_chemblid_is_compound?
|
25
|
-
assert_equal(@chemblid.is_compound
|
26
|
-
assert_equal(@chemblid.data_type
|
58
|
+
assert_equal(true, @chemblid.is_compound?)
|
59
|
+
assert_equal(BioChEMBL::Compound, @chemblid.data_type)
|
27
60
|
end
|
28
61
|
|
29
62
|
def test_chemblid_is_target?
|
30
|
-
assert_equal(@chemblid.is_target
|
63
|
+
assert_equal(false, @chemblid.is_target?)
|
31
64
|
end
|
32
65
|
|
33
66
|
def test_chemblid_is_assay?
|
34
|
-
assert_equal(@chemblid.is_assay
|
67
|
+
assert_equal(false, @chemblid.is_assay?)
|
35
68
|
end
|
36
69
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bio-chembl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mitsuteru Nakao
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-23 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- lib/bio-chembl/chemblid.rb
|
168
168
|
- lib/bio-chembl/compound.rb
|
169
169
|
- lib/bio-chembl/datamodel.rb
|
170
|
-
- lib/bio-chembl/rest_api_server.rb
|
171
170
|
- lib/bio-chembl/rest_client.rb
|
172
171
|
- lib/bio-chembl/target.rb
|
173
172
|
- test/helper.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'cgi'
|
2
|
-
require 'uri'
|
3
|
-
require 'nokogiri'
|
4
|
-
|
5
|
-
|
6
|
-
module BioChEMBL
|
7
|
-
class REST
|
8
|
-
# serv = BioChEMBL::REST::Server.new
|
9
|
-
#
|
10
|
-
class Server
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
# serv.query(:status)
|
16
|
-
# serv.query(:compounds, 'CHEML1')
|
17
|
-
def query(action, args, options)
|
18
|
-
end
|
19
|
-
|
20
|
-
# /compounds/CHEMBL1
|
21
|
-
def compounds(chemblId)
|
22
|
-
end
|
23
|
-
# /compounds/CHEMBL1/image
|
24
|
-
def compounds_image(chemblId)
|
25
|
-
end
|
26
|
-
# /compounds/CHEMBL1/bioactivities
|
27
|
-
def comopunds_bioactivities(chemblId)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
class DB
|
35
|
-
class Query
|
36
|
-
def initialize
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|