Class: BioChEMBL::REST

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-chembl/rest_client.rb

Overview

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

Defined Under Namespace

Modules: ChEMBL_URI

Constant Summary collapse

HOST_NAME =
"www.ebi.ac.uk"
API_ROOT =
"chemblws"
BASE_URI =
"https://" + HOST_NAME + "/" + API_ROOT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = BASE_URI) ⇒ REST

Returns a new instance of REST.



187
188
189
190
191
192
193
# File 'lib/bio-chembl/rest_client.rb', line 187

def initialize(uri = BASE_URI)
  uri = URI.parse(uri) unless uri.kind_of?(URI)
  @header = {
    'User-Agent' => "BioChEMBL, BioRuby/#{Bio::BIORUBY_VERSION_ID}"
  }
  @debug = false
end

Instance Attribute Details

#debugObject

If true, shows debug information to $stderr.



196
197
198
# File 'lib/bio-chembl/rest_client.rb', line 196

def debug
  @debug
end

Class Method Details

.up?Boolean

Check the API status

BioChEMBL::REST.up? #=> true/false

Returns:

  • (Boolean)


178
179
180
181
182
183
184
# File 'lib/bio-chembl/rest_client.rb', line 178

def self.up?
  if new.status == "UP"
    true
  else
    false
  end
end

.usageObject

Usage



168
169
170
171
172
173
174
# File 'lib/bio-chembl/rest_client.rb', line 168

def self.usage    
  ["a = Bio::DB::ChEMBL::REST.new",
   "a.status => https://www.ebi.ac.uk/chembldb/index.php/ws#serviceStatus",
   'a.compounds("CHEMBL1") => http://www.ebi.ac.uk/chemblws/compounds/CHEMBL1',
   'a.compounds.stdinchikey("QFFGVLORLPOAEC-SNVBAGLBSA-N") => http://www.ebi.ac.uk/chemblws/compounds/stdinchikey/QFFGVLORLPOAEC-SNVBAGLBSA-N'
   ].join("\n")
end

.websiteObject

The ChEMBL REST Web services website



163
164
165
# File 'lib/bio-chembl/rest_client.rb', line 163

def self.website
  "https://www.ebi.ac.uk/chembldb/index.php/ws"
end

Instance Method Details

#address(path) ⇒ Object

Address



234
235
236
# File 'lib/bio-chembl/rest_client.rb', line 234

def address(path)
  "#{BASE_URI}/#{path}"
end

#assays(chemblId = nil, action = nil) ⇒ Object

Evaluate Assay methods



314
315
316
# File 'lib/bio-chembl/rest_client.rb', line 314

def assays(chemblId = nil, action = nil)
  get_body(current_method_name, [chemblId, action])
end

#compounds(chemblId = nil, action = nil, params = nil) ⇒ Object

Evaluate Compound methods



274
275
276
# File 'lib/bio-chembl/rest_client.rb', line 274

def compounds(chemblId = nil, action = nil, params = nil)
  get_body(current_method_name, [chemblId, action, params])
end

#compounds_similarity(smiles) ⇒ Object

Evaluate Compound Similarity method



294
295
296
# File 'lib/bio-chembl/rest_client.rb', line 294

def compounds_similarity(smiles)
  get_body(current_method_name, [smiles])
end

#compounds_smiles(smiles) ⇒ Object

Evaluate Compound SMILES method



284
285
286
# File 'lib/bio-chembl/rest_client.rb', line 284

def compounds_smiles(smiles)
  get_body(current_method_name, [smiles])
end

#compounds_stdinchikey(stdinchikey) ⇒ Object

Evaluate Compound StdInchiKey method



279
280
281
# File 'lib/bio-chembl/rest_client.rb', line 279

def compounds_stdinchikey(stdinchikey)
  get_body(current_method_name, [stdinchikey])
end

#compounds_substructure(smiles) ⇒ Object

Evaluate Compound SubStructure method



289
290
291
# File 'lib/bio-chembl/rest_client.rb', line 289

def compounds_substructure(smiles)
  get_body(current_method_name, [smiles])
end

#get(url) ⇒ Object

get the HTTP GET URL



199
200
201
202
203
204
205
206
207
# File 'lib/bio-chembl/rest_client.rb', line 199

def get(url)
  easy = Curl::Easy.new(url) do |c|
    @header.each do |k,v|
      c.headers[k] = v
    end
  end 
  easy.perform
  easy
end

#prepare_return_value(response) ⇒ Object

HTTP responce handling



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/bio-chembl/rest_client.rb', line 210

def prepare_return_value(response)
  if @debug then
    $stderr.puts "ChEMBL: #{response.inspect}"
  end
  case response.response_code 
  when 200
    response.body_str
  when 400
    raise Exception, "400 Bad request  #{response.inspect}"
  when 404
    raise Exception, "404 Not found   #{response.inspect}"
  when 500
    raise Exception, "500 Service unavailable"
  else
    nil
  end
end

#statusObject

Check API status



269
270
271
# File 'lib/bio-chembl/rest_client.rb', line 269

def status
  get_body(current_method_name)
end

#targets(chemblId = nil, action = nil) ⇒ Object

Evaluate Target Methods



299
300
301
# File 'lib/bio-chembl/rest_client.rb', line 299

def targets(chemblId = nil, action = nil)
  get_body(current_method_name, [chemblId, action])
end

#targets_refseq(refseq_id) ⇒ Object

Evaluate Target RefSeq method



309
310
311
# File 'lib/bio-chembl/rest_client.rb', line 309

def targets_refseq(refseq_id)
  get_body(current_method_name, [refseq_id])
end

#targets_uniprot(uniprot_id) ⇒ Object

Evaluate Target UniProt method



304
305
306
# File 'lib/bio-chembl/rest_client.rb', line 304

def targets_uniprot(uniprot_id)
  get_body(current_method_name, [uniprot_id])
end

#uriObject

URI



229
230
231
# File 'lib/bio-chembl/rest_client.rb', line 229

def uri
  ChEMBL_URI
end