class Bio::TogoWS::REST

Description

Bio::TogoWS::REST is a REST client for the TogoWS web service.

Details of the service are desribed in the following URI.

Examples

For light users, class methods can be used.

print Bio::TogoWS::REST.entry('ncbi-nucleotide', 'AF237819')
print Bio::TogoWS::REST.search('uniprot', 'lung cancer')

For heavy users, an instance of the REST class can be created, and using the instance is more efficient than using class methods.

t = Bio::TogoWS::REST.new
print t.entry('ncbi-nucleotide', 'AF237819')
print t.search('uniprot', 'lung cancer')

References

Constants

BASE_URI

URI of the TogoWS REST service

DEFAULT_RETRIEVAL_DATABASES

preset default databases used by the retrieve method.

Attributes

debug[RW]

If true, shows debug information to $stderr.

Public Class Methods

convert(*arg) click to toggle source

The same as Bio::TogoWS::REST#convert.

    # File lib/bio/io/togows.rb
345 def self.convert(*arg)
346   self.new.convert(*arg)
347 end
entry(*arg) click to toggle source

The same as Bio::TogoWS::REST#entry.

    # File lib/bio/io/togows.rb
335 def self.entry(*arg)
336   self.new.entry(*arg)
337 end
entry_database_list(*arg) click to toggle source

The same as Bio::TogoWS::REST#entry_database_list

    # File lib/bio/io/togows.rb
355 def self.entry_database_list(*arg)
356   self.new.entry_database_list(*arg)
357 end
new(uri = BASE_URI) click to toggle source

Creates a new object.


Arguments:

  • (optional) uri: String or URI object

Returns

new object

    # File lib/bio/io/togows.rb
141 def initialize(uri = BASE_URI)
142   uri = URI.parse(uri) unless uri.kind_of?(URI)
143   @pathbase = uri.path
144   @pathbase = '/' + @pathbase unless /\A\// =~ @pathbase
145   @pathbase = @pathbase + '/' unless /\/\z/ =~ @pathbase
146   @http = Bio::Command.new_http(uri.host, uri.port)
147   @header = {
148     'User-Agent' => "BioRuby/#{Bio::BIORUBY_VERSION_ID}"
149   }
150   @debug = false
151 end
retrieve(*arg) click to toggle source

The same as Bio::TogoWS::REST#retrieve.

    # File lib/bio/io/togows.rb
350 def self.retrieve(*arg)
351   self.new.retrieve(*arg)
352 end
search_database_list(*arg) click to toggle source

The same as Bio::TogoWS::REST#search_database_list

    # File lib/bio/io/togows.rb
360 def self.search_database_list(*arg)
361   self.new.search_database_list(*arg)
362 end

Public Instance Methods

convert(data, inputformat, format) click to toggle source

Data format conversion.

Example:

t = Bio::TogoWS::REST.new
blast_string = File.read('test.blastn')
t.convert(blast_string, 'blast', 'gff')

Arguments:

  • (required) text: (String) input data

  • (required) inputformat: (String) data source format

  • (required) format: (String) output format

Returns

String or nil

    # File lib/bio/io/togows.rb
310 def convert(data, inputformat, format)
311   response = post_data(data, 'convert', "#{inputformat}.#{format}")
312 
313   prepare_return_value(response)
314 end
entry(database, ids, format = nil, field = nil) click to toggle source

Retrieves entries corresponding to the specified IDs.

Example:

t = Bio::TogoWS::REST.new
kuma = t.entry('ncbi-nucleotide', 'AF237819')
# multiple IDs at a time
misc = t.entry('ncbi-nucleotide', [ 'AF237819', 'AF237820' ])
# with format change
p53 = t.entry('uniprot', 'P53_HUMAN', 'fasta')

Arguments:

  • (required) database: (String) database name

  • (required) ids: (String) an entry ID, or (Array containing String) IDs. Note that strings containing “,” are regarded as multiple IDs.

  • (optional) format: (String) format. nil means the default format (differs depending on the database).

  • (optional) field: (String) gets only the specified field if not nil

Returns

String or nil

    # File lib/bio/io/togows.rb
241 def entry(database, ids, format = nil, field = nil)
242   begin
243     a = ids.to_ary
244   rescue NoMethodError
245     ids = ids.to_s
246   end
247 
248   arg = [ 'entry', database ]
249   if a then
250     b = a.dup
251     (a.size - 1).downto(1) { |i| b.insert(i, :",") }
252     arg.concat b
253   else
254     arg.push ids
255   end
256 
257   arg.push field if field
258   arg[-1] = "#{arg[-1]}.#{format}" if format
259   response = get(*arg)
260 
261   prepare_return_value(response)
262 end
entry_database_list() click to toggle source

Returns list of available databases in the entry service.


Returns

Array containing String

    # File lib/bio/io/togows.rb
319 def entry_database_list
320   database_list('entry')
321 end
internal_http() click to toggle source

Debug purpose only. Returns Net::HTTP object used inside the object. The method will be changed in the future if the implementation of this class is changed.

    # File lib/bio/io/togows.rb
160 def internal_http
161   @http
162 end
retrieve(ids, hash = {}) click to toggle source

Intelligent version of the entry method. If two or more databases are specified, sequentially tries them until valid entry is obtained.

If database is not specified, preset default databases are used. See DEFAULT_RETRIEVAL_DATABASES for details.

When multiple IDs and multiple databases are specified, sequentially tries each IDs. Note that results with no hits found or with server errors are regarded as void strings. Also note that data format of the result entries can be different from entries to entries.


Arguments:

  • (required) ids: (String) an entry ID, or (Array containing String) IDs. Note that strings containing “,”

  • (optional) hash: (Hash) options below can be passed as a hash.

    • (optional) :database: (String) database name, or (Array containing String) database names.

    • (optional) :format: (String) format

    • (optional) :field: (String) gets only the specified field

Returns

String or nil

    # File lib/bio/io/togows.rb
186 def retrieve(ids, hash = {})
187   begin
188     a = ids.to_ary
189   rescue NoMethodError
190     ids = ids.to_s
191   end
192   ids = a.join(',') if a
193   ids = ids.split(',')
194 
195   dbs = hash[:database] || DEFAULT_RETRIEVAL_DATABASES
196   begin
197     dbs.to_ary
198   rescue NoMethodError
199     dbs = dbs.to_s.empty? ? [] : [ dbs.to_s ]
200   end
201   return nil if dbs.empty? or ids.empty?
202 
203   if dbs.size == 1 then
204     return entry(dbs[0], ids, hash[:format], hash[:field])
205   end
206 
207   results = []
208   ids.each do |idstr|
209     dbs.each do |dbstr|
210       r = entry(dbstr, idstr, hash[:format], hash[:field])
211       if r and !r.strip.empty? then
212         results.push r
213         break
214       end
215     end #dbs.each
216   end #ids.each
217   
218   results.join('')
219 end
search_database_list() click to toggle source

Returns list of available databases in the search service.


Returns

Array containing String

    # File lib/bio/io/togows.rb
326 def search_database_list
327   database_list('search')
328 end