ngoto-bio 1.2.9.9501 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +201 -4
- data/KNOWN_ISSUES.rdoc +24 -2
- data/README.rdoc +29 -0
- data/Rakefile +44 -5
- data/bin/br_pmfetch.rb +4 -3
- data/bioruby.gemspec +11 -3
- data/bioruby.gemspec.erb +40 -5
- data/doc/Changes-0.7.rd +7 -0
- data/doc/Changes-1.3.rdoc +17 -0
- data/doc/Tutorial.rd.html +1031 -0
- data/doc/Tutorial.rd.ja +111 -45
- data/doc/Tutorial.rd.ja.html +2225 -0
- data/doc/bioruby.css +281 -0
- data/lib/bio/appl/blast/format0.rb +7 -2
- data/lib/bio/db/gff.rb +2 -2
- data/lib/bio/db/lasergene.rb +3 -3
- data/lib/bio/db/soft.rb +3 -3
- data/lib/bio/io/togows.rb +458 -0
- data/lib/bio/shell/core.rb +2 -2
- data/lib/bio/shell/plugin/entry.rb +27 -4
- data/lib/bio/shell/plugin/ncbirest.rb +27 -29
- data/lib/bio/shell/plugin/togows.rb +40 -0
- data/lib/bio/shell.rb +1 -0
- data/lib/bio/util/color_scheme.rb +2 -2
- data/lib/bio/util/contingency_table.rb +2 -2
- data/lib/bio/util/restriction_enzyme.rb +2 -2
- data/lib/bio/version.rb +25 -0
- data/lib/bio.rb +4 -1
- data/test/functional/bio/io/test_togows.rb +267 -0
- data/test/runner.rb +7 -0
- data/test/unit/bio/db/test_gff.rb +63 -0
- data/test/unit/bio/io/test_togows.rb +161 -0
- metadata +11 -3
@@ -0,0 +1,458 @@
|
|
1
|
+
#
|
2
|
+
# = bio/io/togows.rb - REST interface for TogoWS
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2009 Naohisa Goto <ng@bioruby.org>
|
5
|
+
# License:: The Ruby License
|
6
|
+
#
|
7
|
+
# $Id:$
|
8
|
+
#
|
9
|
+
# Bio::TogoWS is a set of clients for the TogoWS web services
|
10
|
+
# (http://togows.dbcls.jp/).
|
11
|
+
#
|
12
|
+
# * Bio::TogoWS::REST is a REST client for the TogoWS.
|
13
|
+
# * Bio::TogoWS::SOAP will be implemented in the future.
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'uri'
|
17
|
+
require 'cgi'
|
18
|
+
require 'bio/version'
|
19
|
+
require 'bio/command'
|
20
|
+
|
21
|
+
module Bio
|
22
|
+
|
23
|
+
# Bio::TogoWS is a namespace for the TogoWS web services.
|
24
|
+
module TogoWS
|
25
|
+
|
26
|
+
# Internal Use Only.
|
27
|
+
#
|
28
|
+
# Bio::TogoWS::AccessWait is a module to implement a
|
29
|
+
# private method for access.
|
30
|
+
module AccessWait
|
31
|
+
|
32
|
+
# common default access wait for TogoWS services
|
33
|
+
TOGOWS_ACCESS_WAIT = 1
|
34
|
+
|
35
|
+
# Maximum waiting time to avoid dead lock.
|
36
|
+
# When exceeding this value, (max/2) + rand(max) is used,
|
37
|
+
# to randomize access.
|
38
|
+
# This means real maximum waiting time is (max * 1.5).
|
39
|
+
TOGOWS_ACCESS_WAIT_MAX = 60
|
40
|
+
|
41
|
+
# Sleeping if needed.
|
42
|
+
# It sleeps about TOGOWS_ACCESS_WAIT * (number of waiting processes).
|
43
|
+
#
|
44
|
+
# ---
|
45
|
+
# *Returns*:: (Numeric) sleeped time
|
46
|
+
def togows_access_wait
|
47
|
+
w_min = TOGOWS_ACCESS_WAIT
|
48
|
+
debug = defined?(@debug) && @debug
|
49
|
+
|
50
|
+
# initializing class variable
|
51
|
+
@@togows_last_access ||= nil
|
52
|
+
|
53
|
+
# determines waiting time
|
54
|
+
wait = 0
|
55
|
+
if last = @@togows_last_access then
|
56
|
+
elapsed = Time.now - last
|
57
|
+
if elapsed < w_min then
|
58
|
+
wait = w_min - elapsed
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# If wait is too long, truncated to TOGOWS_ACCESS_WAIT_MAX.
|
63
|
+
if wait > TOGOWS_ACCESS_WAIT_MAX then
|
64
|
+
orig_wait = wait
|
65
|
+
wait = TOGOWS_ACCESS_WAIT_MAX
|
66
|
+
wait = wait / 2 + rand(wait)
|
67
|
+
if debug then
|
68
|
+
$stderr.puts "TogoWS: sleeping time #{orig_wait} is too long and set to #{wait} to avoid dead lock."
|
69
|
+
end
|
70
|
+
newlast = Time.now + TOGOWS_ACCESS_WAIT_MAX
|
71
|
+
else
|
72
|
+
newlast = Time.now + wait
|
73
|
+
end
|
74
|
+
|
75
|
+
# put expected end time of sleeping
|
76
|
+
if !@@togows_last_access or @@togows_last_access < newlast then
|
77
|
+
@@togows_last_access = newlast
|
78
|
+
end
|
79
|
+
|
80
|
+
# sleeping if needed
|
81
|
+
if wait > 0 then
|
82
|
+
$stderr.puts "TogoWS: sleeping #{wait} second" if debug
|
83
|
+
sleep(wait)
|
84
|
+
end
|
85
|
+
# returns waited time
|
86
|
+
wait
|
87
|
+
end
|
88
|
+
private :togows_access_wait
|
89
|
+
|
90
|
+
# (private) resets last access.
|
91
|
+
# Should be used only for debug purpose.
|
92
|
+
def reset_togows_access_wait
|
93
|
+
@@togows_last_access = nil
|
94
|
+
end
|
95
|
+
private :reset_togows_access_wait
|
96
|
+
|
97
|
+
end #module AccessWait
|
98
|
+
|
99
|
+
# == Description
|
100
|
+
#
|
101
|
+
# Bio::TogoWS::REST is a REST client for the TogoWS web service.
|
102
|
+
#
|
103
|
+
# Details of the service are desribed in the following URI.
|
104
|
+
#
|
105
|
+
# * http://togows.dbcls.jp/site/en/rest.html
|
106
|
+
#
|
107
|
+
# == Examples
|
108
|
+
#
|
109
|
+
# For light users, class methods can be used.
|
110
|
+
#
|
111
|
+
# print Bio::TogoWS::REST.entry('genbank', 'AF237819')
|
112
|
+
# print Bio::TogoWS::REST.search('uniprot', 'lung cancer')
|
113
|
+
#
|
114
|
+
# For heavy users, an instance of the REST class can be created, and
|
115
|
+
# using the instance is more efficient than using class methods.
|
116
|
+
#
|
117
|
+
# t = Bio::TogoWS::REST.new
|
118
|
+
# print t.entry('genbank', 'AF237819')
|
119
|
+
# print t.search('uniprot', 'lung cancer')
|
120
|
+
#
|
121
|
+
# == References
|
122
|
+
#
|
123
|
+
# * http://togows.dbcls.jp/site/en/rest.html
|
124
|
+
#
|
125
|
+
class REST
|
126
|
+
|
127
|
+
include AccessWait
|
128
|
+
|
129
|
+
# URI of the TogoWS REST service
|
130
|
+
BASE_URI = 'http://togows.dbcls.jp/'.freeze
|
131
|
+
|
132
|
+
# preset default databases used by the retrieve method.
|
133
|
+
#
|
134
|
+
DEFAULT_RETRIEVAL_DATABASES =
|
135
|
+
%w( genbank uniprot embl ddbj dad )
|
136
|
+
|
137
|
+
# Creates a new object.
|
138
|
+
# ---
|
139
|
+
# *Arguments*:
|
140
|
+
# * (optional) _uri_: String or URI object
|
141
|
+
# *Returns*:: new object
|
142
|
+
def initialize(uri = BASE_URI)
|
143
|
+
uri = URI.parse(uri) unless uri.kind_of?(URI)
|
144
|
+
@pathbase = uri.path
|
145
|
+
@pathbase = '/' + @pathbase unless /\A\// =~ @pathbase
|
146
|
+
@pathbase = @pathbase + '/' unless /\/\z/ =~ @pathbase
|
147
|
+
@http = Bio::Command.new_http(uri.host, uri.port)
|
148
|
+
@header = {
|
149
|
+
'User-Agent' => "BioRuby/#{Bio::BIORUBY_VERSION_ID}"
|
150
|
+
}
|
151
|
+
@debug = false
|
152
|
+
end
|
153
|
+
|
154
|
+
# If true, shows debug information to $stderr.
|
155
|
+
attr_accessor :debug
|
156
|
+
|
157
|
+
# Debug purpose only.
|
158
|
+
# Returns Net::HTTP object used inside the object.
|
159
|
+
# The method will be changed in the future if the implementation
|
160
|
+
# of this class is changed.
|
161
|
+
def internal_http
|
162
|
+
@http
|
163
|
+
end
|
164
|
+
|
165
|
+
# Intelligent version of the entry method.
|
166
|
+
# If two or more databases are specified, sequentially tries
|
167
|
+
# them until valid entry is obtained.
|
168
|
+
#
|
169
|
+
# If database is not specified, preset default databases are used.
|
170
|
+
# See DEFAULT_RETRIEVAL_DATABASES for details.
|
171
|
+
#
|
172
|
+
# When multiple IDs and multiple databases are specified, sequentially
|
173
|
+
# tries each IDs. Note that results with no hits found or with server
|
174
|
+
# errors are regarded as void strings. Also note that data format of
|
175
|
+
# the result entries can be different from entries to entries.
|
176
|
+
#
|
177
|
+
# ---
|
178
|
+
# *Arguments*:
|
179
|
+
# * (required) _ids_: (String) an entry ID, or
|
180
|
+
# (Array containing String) IDs. Note that strings containing ","
|
181
|
+
# * (optional) _hash_: (Hash) options below can be passed as a hash.
|
182
|
+
# * (optional) <I>:database</I>: (String) database name, or
|
183
|
+
# (Array containing String) database names.
|
184
|
+
# * (optional) <I>:format</I>: (String) format
|
185
|
+
# * (optional) <I>:field</I>: (String) gets only the specified field
|
186
|
+
# *Returns*:: String or nil
|
187
|
+
def retrieve(ids, hash = {})
|
188
|
+
begin
|
189
|
+
a = ids.to_ary
|
190
|
+
rescue NoMethodError
|
191
|
+
ids = ids.to_s
|
192
|
+
end
|
193
|
+
ids = a.join(',') if a
|
194
|
+
ids = ids.split(',')
|
195
|
+
|
196
|
+
dbs = hash[:database] || DEFAULT_RETRIEVAL_DATABASES
|
197
|
+
begin
|
198
|
+
dbs.to_ary
|
199
|
+
rescue NoMethodError
|
200
|
+
dbs = dbs.to_s.empty? ? [] : [ dbs.to_s ]
|
201
|
+
end
|
202
|
+
return nil if dbs.empty? or ids.empty?
|
203
|
+
|
204
|
+
if dbs.size == 1 then
|
205
|
+
return entry(dbs[0], ids, hash[:format], hash[:field])
|
206
|
+
end
|
207
|
+
|
208
|
+
results = []
|
209
|
+
ids.each do |idstr|
|
210
|
+
dbs.each do |dbstr|
|
211
|
+
r = entry(dbstr, idstr, hash[:format], hash[:field])
|
212
|
+
if r and !r.strip.empty? then
|
213
|
+
results.push r
|
214
|
+
break
|
215
|
+
end
|
216
|
+
end #dbs.each
|
217
|
+
end #ids.each
|
218
|
+
|
219
|
+
results.join('')
|
220
|
+
end #def retrieve
|
221
|
+
|
222
|
+
# Retrieves entries corresponding to the specified IDs.
|
223
|
+
#
|
224
|
+
# Example:
|
225
|
+
# t = Bio::TogoWS::REST.new
|
226
|
+
# kuma = t.entry('genbank', 'AF237819')
|
227
|
+
# # multiple IDs at a time
|
228
|
+
# misc = t.entry('genbank', [ 'AF237819', 'AF237820' ])
|
229
|
+
# # with format change
|
230
|
+
# p53 = t.entry('uniprot', 'P53_HUMAN', 'fasta')
|
231
|
+
#
|
232
|
+
# ---
|
233
|
+
# *Arguments*:
|
234
|
+
# * (required) _database_: (String) database name
|
235
|
+
# * (required) _ids_: (String) an entry ID, or
|
236
|
+
# (Array containing String) IDs. Note that strings containing ","
|
237
|
+
# are regarded as multiple IDs.
|
238
|
+
# * (optional) _format_: (String) format. nil means the default format
|
239
|
+
# (differs depending on the database).
|
240
|
+
# * (optional) _field_: (String) gets only the specified field if not nil
|
241
|
+
# *Returns*:: String or nil
|
242
|
+
def entry(database, ids, format = nil, field = nil)
|
243
|
+
begin
|
244
|
+
a = ids.to_ary
|
245
|
+
rescue NoMethodError
|
246
|
+
ids = ids.to_s
|
247
|
+
end
|
248
|
+
ids = a.join(',') if a
|
249
|
+
|
250
|
+
arg = [ 'entry', database, ids ]
|
251
|
+
arg.push field if field
|
252
|
+
arg[-1] = "#{arg[-1]}.#{format}" if format
|
253
|
+
response = get(*arg)
|
254
|
+
|
255
|
+
prepare_return_value(response)
|
256
|
+
end
|
257
|
+
|
258
|
+
# Database search.
|
259
|
+
# Format of the search term string follows the Common Query Language.
|
260
|
+
# * http://en.wikipedia.org/wiki/Common_Query_Language
|
261
|
+
#
|
262
|
+
# Example:
|
263
|
+
# t = Bio::TogoWS::REST.new
|
264
|
+
# print t.search('uniprot', 'lung cancer')
|
265
|
+
# # only get the 10th and 11th hit ID
|
266
|
+
# print t.search('uniprot', 'lung cancer', 10, 2)
|
267
|
+
# # with json format
|
268
|
+
# print t.search('uniprot', 'lung cancer', 10, 2, 'json')
|
269
|
+
#
|
270
|
+
# ---
|
271
|
+
# *Arguments*:
|
272
|
+
# * (required) _database_: (String) database name
|
273
|
+
# * (required) _query_: (String) query string
|
274
|
+
# * (optional) _offset_: (Integer) offset in search results.
|
275
|
+
# * (optional) _limit_: (Integer) max. number of returned results.
|
276
|
+
# If offset is not nil and the limit is nil, it is set to 1.
|
277
|
+
# * (optional) _format_: (String) format. nil means the default format.
|
278
|
+
# *Returns*:: String or nil
|
279
|
+
def search(database, query, offset = nil, limit = nil, format = nil)
|
280
|
+
arg = [ 'search', database, query ]
|
281
|
+
if offset then
|
282
|
+
limit ||= 1
|
283
|
+
arg.push "#{offset},#{limit}"
|
284
|
+
end
|
285
|
+
arg[-1] = "#{arg[-1]}.#{format}" if format
|
286
|
+
response = get(*arg)
|
287
|
+
|
288
|
+
prepare_return_value(response)
|
289
|
+
end
|
290
|
+
|
291
|
+
# Data format conversion.
|
292
|
+
#
|
293
|
+
# Example:
|
294
|
+
# t = Bio::TogoWS::REST.new
|
295
|
+
# blast_string = File.read('test.blastn')
|
296
|
+
# t.convert(blast_string, 'blast', 'gff')
|
297
|
+
#
|
298
|
+
# ---
|
299
|
+
# *Arguments*:
|
300
|
+
# * (required) _text_: (String) input data
|
301
|
+
# * (required) _inputformat_: (String) data source format
|
302
|
+
# * (required) _format_: (String) output format
|
303
|
+
# *Returns*:: String or nil
|
304
|
+
def convert(data, inputformat, format)
|
305
|
+
response = post_data(data, 'convert', "#{inputformat}.#{format}")
|
306
|
+
|
307
|
+
prepare_return_value(response)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Returns list of available databases in the entry service.
|
311
|
+
# ---
|
312
|
+
# *Returns*:: Array containing String
|
313
|
+
def entry_database_list
|
314
|
+
database_list('entry')
|
315
|
+
end
|
316
|
+
|
317
|
+
# Returns list of available databases in the search service.
|
318
|
+
# ---
|
319
|
+
# *Returns*:: Array containing String
|
320
|
+
def search_database_list
|
321
|
+
database_list('search')
|
322
|
+
end
|
323
|
+
|
324
|
+
#--
|
325
|
+
# class methods
|
326
|
+
#++
|
327
|
+
|
328
|
+
# The same as Bio::TogoWS::REST#entry.
|
329
|
+
def self.entry(*arg)
|
330
|
+
self.new.entry(*arg)
|
331
|
+
end
|
332
|
+
|
333
|
+
# The same as Bio::TogoWS::REST#search.
|
334
|
+
def self.search(*arg)
|
335
|
+
self.new.search(*arg)
|
336
|
+
end
|
337
|
+
|
338
|
+
# The same as Bio::TogoWS::REST#convert.
|
339
|
+
def self.convert(*arg)
|
340
|
+
self.new.convert(*arg)
|
341
|
+
end
|
342
|
+
|
343
|
+
# The same as Bio::TogoWS::REST#retrieve.
|
344
|
+
def self.retrieve(*arg)
|
345
|
+
self.new.retrieve(*arg)
|
346
|
+
end
|
347
|
+
|
348
|
+
# The same as Bio::TogoWS::REST#entry_database_list
|
349
|
+
def self.entry_database_list(*arg)
|
350
|
+
self.new.entry_database_list(*arg)
|
351
|
+
end
|
352
|
+
|
353
|
+
# The same as Bio::TogoWS::REST#search_database_list
|
354
|
+
def self.search_database_list(*arg)
|
355
|
+
self.new.search_database_list(*arg)
|
356
|
+
end
|
357
|
+
|
358
|
+
private
|
359
|
+
|
360
|
+
# Access to the TogoWS by using GET method.
|
361
|
+
#
|
362
|
+
# Example 1:
|
363
|
+
# get('entry', 'genbank', AF209156')
|
364
|
+
# Example 2:
|
365
|
+
# get('search', 'uniprot', 'lung cancer')
|
366
|
+
#
|
367
|
+
# ---
|
368
|
+
# *Arguments*:
|
369
|
+
# * (optional) _path_: String
|
370
|
+
# *Returns*:: Net::HTTPResponse object
|
371
|
+
def get(*paths)
|
372
|
+
path = make_path(paths)
|
373
|
+
if @debug then
|
374
|
+
$stderr.puts "TogoWS: HTTP#get(#{path.inspect}, #{@header.inspect})"
|
375
|
+
end
|
376
|
+
togows_access_wait
|
377
|
+
@http.get(path, @header)
|
378
|
+
end
|
379
|
+
|
380
|
+
# Access to the TogoWS by using GET method.
|
381
|
+
# Always adds '/' at the end of the path.
|
382
|
+
#
|
383
|
+
# Example 1:
|
384
|
+
# get_dir('entry')
|
385
|
+
#
|
386
|
+
# ---
|
387
|
+
# *Arguments*:
|
388
|
+
# * (optional) _path_: String
|
389
|
+
# *Returns*:: Net::HTTPResponse object
|
390
|
+
def get_dir(*paths)
|
391
|
+
path = make_path(paths)
|
392
|
+
path += '/' unless /\/\z/ =~ path
|
393
|
+
if @debug then
|
394
|
+
$stderr.puts "TogoWS: HTTP#get(#{path.inspect}, #{@header.inspect})"
|
395
|
+
end
|
396
|
+
togows_access_wait
|
397
|
+
@http.get(path, @header)
|
398
|
+
end
|
399
|
+
|
400
|
+
# Access to the TogoWS by using POST method.
|
401
|
+
# The data is stored to the form key 'data'.
|
402
|
+
# Mime type is 'application/x-www-form-urlencoded'.
|
403
|
+
# ---
|
404
|
+
# *Arguments*:
|
405
|
+
# * (required) _data_: String
|
406
|
+
# * (optional) _path_: String
|
407
|
+
# *Returns*:: Net::HTTPResponse object
|
408
|
+
def post_data(data, *paths)
|
409
|
+
path = make_path(paths)
|
410
|
+
if @debug then
|
411
|
+
$stderr.puts "TogoWS: Bio::Command.http_post_form(#{path.inspect}, { \"data\" => (#{data.size} bytes) }, #{@header.inspect})"
|
412
|
+
end
|
413
|
+
togows_access_wait
|
414
|
+
Bio::Command.http_post_form(@http, path, { 'data' => data }, @header)
|
415
|
+
end
|
416
|
+
|
417
|
+
# Generates path string from the given paths.
|
418
|
+
# ---
|
419
|
+
# *Arguments*:
|
420
|
+
# * (required) _paths_: Array containing String objects
|
421
|
+
# *Returns*:: String
|
422
|
+
def make_path(paths)
|
423
|
+
@pathbase + paths.collect { |x| CGI.escape(x.to_s) }.join('/')
|
424
|
+
end
|
425
|
+
|
426
|
+
# If response.code == "200", returns body as a String.
|
427
|
+
# Otherwise, returns nil.
|
428
|
+
def prepare_return_value(response)
|
429
|
+
if @debug then
|
430
|
+
$stderr.puts "TogoWS: #{response.inspect}"
|
431
|
+
end
|
432
|
+
if response.code == "200" then
|
433
|
+
response.body
|
434
|
+
else
|
435
|
+
nil
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
# Returns list of available databases
|
440
|
+
# ---
|
441
|
+
# *Arguments*:
|
442
|
+
# * (required) _service_: String
|
443
|
+
# *Returns*:: Array containing String
|
444
|
+
def database_list(service)
|
445
|
+
response = get_dir(service)
|
446
|
+
str = prepare_return_value(response)
|
447
|
+
if str then
|
448
|
+
str.chomp.split(/\r?\n/)
|
449
|
+
else
|
450
|
+
raise 'Unexpected server response'
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
end #class REST
|
455
|
+
|
456
|
+
end #module TogoWS
|
457
|
+
|
458
|
+
end #module Bio
|
data/lib/bio/shell/core.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Toshiaki Katayama <k@bioruby.org>
|
6
6
|
# License:: The Ruby License
|
7
7
|
#
|
8
|
-
# $Id
|
8
|
+
# $Id:$
|
9
9
|
#
|
10
10
|
|
11
11
|
module Bio::Shell::Core
|
@@ -556,7 +556,7 @@ module Bio::Shell::Ghost
|
|
556
556
|
end
|
557
557
|
STDERR.puts
|
558
558
|
STDERR.puts
|
559
|
-
STDERR.print " Version : BioRuby #{Bio::
|
559
|
+
STDERR.print " Version : BioRuby #{Bio::BIORUBY_VERSION_ID}"
|
560
560
|
STDERR.print " / Ruby #{RUBY_VERSION}"
|
561
561
|
STDERR.puts
|
562
562
|
STDERR.puts
|
@@ -86,15 +86,38 @@ module Bio::Shell
|
|
86
86
|
puts "Retrieving entry from EMBOSS (#{arg})"
|
87
87
|
entry = str
|
88
88
|
|
89
|
-
#
|
89
|
+
# via Internet
|
90
90
|
else
|
91
91
|
case db.to_s.downcase
|
92
|
-
when 'genbank', 'gb', '
|
92
|
+
when 'genbank', 'gb', 'nuccore', 'indsc'
|
93
|
+
# NCBI
|
93
94
|
puts "Retrieving entry from NCBI eUtils"
|
94
95
|
entry = efetch(entry_id)
|
96
|
+
|
97
|
+
when 'embl', 'emb', /\Aembl/, /\Auni/, 'sp', /\Aensembl/
|
98
|
+
# EBI
|
99
|
+
puts "Retrieving entry from EBI Dbfetch"
|
100
|
+
db = 'embl' if db == 'emb'
|
101
|
+
db = 'uniprotkb' if db == 'uniprot' or db == 'sp'
|
102
|
+
entry = biofetch(db, entry_id)
|
103
|
+
|
104
|
+
when 'ddbj', 'dbj', 'dad'
|
105
|
+
# TogoWS REST
|
106
|
+
puts "Retrieving entry from TogoWS"
|
107
|
+
db = 'ddbj' if db == 'dbj'
|
108
|
+
entry = togowsentry(db, entry_id)
|
109
|
+
|
95
110
|
else
|
96
|
-
|
97
|
-
|
111
|
+
togodblist = Bio::TogoWS::REST.entry_database_list rescue []
|
112
|
+
if togodblist.include?(db) then
|
113
|
+
# TogoWS REST
|
114
|
+
puts "Retrieving entry from TogoWS"
|
115
|
+
entry = togowsentry(db, entry_id)
|
116
|
+
else
|
117
|
+
# KEGG API at http://www.genome.jp/kegg/soap/
|
118
|
+
puts "Retrieving entry from KEGG API (#{arg})"
|
119
|
+
entry = bget(arg)
|
120
|
+
end
|
98
121
|
end
|
99
122
|
end
|
100
123
|
end
|
@@ -13,38 +13,36 @@ module Bio::Shell
|
|
13
13
|
private
|
14
14
|
|
15
15
|
# NCBI eUtils EFetch service.
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# automatically
|
16
|
+
#
|
17
|
+
# With 1 argument, it gets sequence(s) by using
|
18
|
+
# Bio::NCBI::REST::EFetch.sequence.
|
19
|
+
# Nucleotide or protein database is automatically selected for each id.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
# efetch('AF237819')
|
23
|
+
#
|
24
|
+
# With two or more arguments, and when the 2nd argument is Symbol,
|
25
|
+
# it calls the corresponding Bio::NCBI::REST::EFetch class method.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
# efetch('13054692', :pubmed)
|
29
|
+
# # the same as Bio::NCBI::REST::EFetch.pubmed('13054692')
|
30
|
+
#
|
31
|
+
# Otherwise, it acts the same as Bio::NCBI::REST.efetch.
|
20
32
|
def efetch(ids, *arg)
|
21
|
-
if
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
/\A[OPQ][A-Z0-9]+(\.[0-9]+)?\z/i
|
32
|
-
# protein accession
|
33
|
-
dbs = prot_dbs
|
34
|
-
when /\A[0-9]+\z/, /\A[A-Z0-9]+\_[A-Z0-9]+\z/i
|
35
|
-
# NCBI GI or UniProt accession (with fail-safe)
|
36
|
-
dbs = prot_dbs + nucl_dbs
|
33
|
+
if arg.empty? then
|
34
|
+
Bio::NCBI::REST::EFetch.sequence(ids)
|
35
|
+
elsif arg[0].kind_of?(Symbol)
|
36
|
+
meth = arg[0]
|
37
|
+
case meth.to_s
|
38
|
+
when /\A(journal|omim|pmc|pubmed|sequence|taxonomy)\z/
|
39
|
+
Bio::NCBI::REST::EFetch.__send__(meth, ids, *(arg[1..-1]))
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
37
43
|
else
|
38
|
-
|
39
|
-
dbs = nucl_dbs
|
40
|
-
end
|
41
|
-
result = nil
|
42
|
-
dbs.each do |db|
|
43
|
-
hash = { 'db' => db, 'rettype' => 'gb' }
|
44
|
-
result = Bio::NCBI::REST.efetch(ids, hash)
|
45
|
-
break if result and !result.empty?
|
44
|
+
Bio::NCBI::REST.efetch(ids, *arg)
|
46
45
|
end
|
47
|
-
result
|
48
46
|
end
|
49
47
|
|
50
48
|
# NCBI eUtils EInfo
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# = bio/shell/plugin/togows.rb - plugin for TogoWS REST service
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2009
|
5
|
+
# Naohisa Goto <ng@bioruby.org>
|
6
|
+
# License:: The Ruby License
|
7
|
+
#
|
8
|
+
# $Id:$
|
9
|
+
#
|
10
|
+
|
11
|
+
module Bio::Shell
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# Shortcut method to fetch entry(entries) by using TogoWS REST "entry"
|
16
|
+
# service. Multiple databases may be used.
|
17
|
+
#
|
18
|
+
def togows(ids, *arg)
|
19
|
+
Bio::TogoWS::REST.retrieve(ids, *arg)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Fetches entry(entries) by using TogoWS REST "entry" service.
|
23
|
+
# Same as Bio::TogoWS::REST.entry(database, ids, *arg).
|
24
|
+
def togowsentry(database, ids, *arg)
|
25
|
+
Bio::TogoWS::REST.entry(database, ids, *arg)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Database search by using TogoWS REST "search" service.
|
29
|
+
# Same as Bio::TogoWS::REST.search(database, term, *arg).
|
30
|
+
def togowssearch(database, term, *arg)
|
31
|
+
Bio::TogoWS::REST.search(database, term, *arg)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Data format conversion by using TogoWS REST "convert" service.
|
35
|
+
# Same as Bio::TogoWS::REST.convert(data, format_from, format_to).
|
36
|
+
def togowsconvert(data, format_from, format_to)
|
37
|
+
Bio::TogoWS::REST.convert(data, format_from, format_to)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/bio/shell.rb
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
# Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com)
|
6
6
|
# License:: The Ruby License
|
7
7
|
#
|
8
|
-
# $Id
|
8
|
+
# $Id:$
|
9
9
|
#
|
10
10
|
|
11
|
-
module Bio
|
11
|
+
module Bio
|
12
12
|
|
13
13
|
#
|
14
14
|
# bio/util/color_scheme.rb - Popular color codings for nucleic and amino acids
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com)
|
6
6
|
# License:: The Ruby License
|
7
7
|
#
|
8
|
-
# $Id
|
8
|
+
# $Id:$
|
9
9
|
#
|
10
10
|
|
11
|
-
module Bio
|
11
|
+
module Bio
|
12
12
|
|
13
13
|
#
|
14
14
|
# bio/util/contingency_table.rb - Statistical contingency table analysis for aligned sequences
|
@@ -5,10 +5,10 @@
|
|
5
5
|
# Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com)
|
6
6
|
# License:: The Ruby License
|
7
7
|
#
|
8
|
-
# $Id
|
8
|
+
# $Id:$
|
9
9
|
#
|
10
10
|
|
11
|
-
module Bio
|
11
|
+
module Bio
|
12
12
|
|
13
13
|
autoload :REBASE, 'bio/db/rebase'
|
14
14
|
|