Class Bio::Fetch
In: lib/bio/io/fetch.rb
Parent: Object

DESCRIPTION

The Bio::Fetch class provides an interface to dbfetch servers. Given a database name and an accession number, these servers return the associated record. For example, for the embl database on the EBI, that would be a nucleic or amino acid sequence.

Possible dbfetch servers include:

If you‘re behind a proxy server, be sure to set your HTTP_PROXY environment variable accordingly.

USAGE

 require 'bio'

 # Retrieve the sequence of accession number M33388 from the EMBL
 # database.
 server = Bio::Fetch.new()  #uses default server
 puts server.fetch('embl','M33388')

 # Do the same thing without creating a Bio::Fetch object. This method always
 # uses the default dbfetch server: http://bioruby.org/cgi-bin/biofetch.rb
 puts Bio::Fetch.query('embl','M33388')

 # To know what databases are available on the bioruby dbfetch server:
 server = Bio::Fetch.new()
 puts server.databases

 # Some databases provide their data in different formats (e.g. 'fasta',
 # 'genbank' or 'embl'). To check which formats are supported by a given
 # database:
 puts server.formats('embl')

Methods

databases   fetch   formats   get_by_id   maxids   new   query  

Attributes

database  [RW]  The default database to query

Public Class methods

Create a new Bio::Fetch server object that can subsequently be queried using the Bio::Fetch#fetch method


Arguments:

Returns:Bio::Fetch object

[Source]

    # File lib/bio/io/fetch.rb, line 75
75:     def initialize(url = 'http://bioruby.org/cgi-bin/biofetch.rb')
76:       @url = url
77:       schema, user, @host, @port, reg, @path, = URI.split(@url)
78:     end

Shortcut for using BioRuby‘s BioFetch server. You can fetch an entry without creating an instance of BioFetch server. This method uses the default dbfetch server, which is bioruby.org/cgi-bin/biofetch.rb

Example:

  puts Bio::Fetch.query('refseq','NM_12345')

Arguments:

[Source]

     # File lib/bio/io/fetch.rb, line 127
127:     def self.query(*args)
128:       self.new.fetch(*args)
129:     end

Public Instance methods

Using this method, the user can ask a dbfetch server what databases it supports. This would normally be the first step you‘d take when you use a dbfetch server for the first time. Example:

 server = Bio::Fetch.new()
 puts server.databases # returns "aa aax bl cpd dgenes dr ec eg emb ..."

This method only works for the bioruby dbfetch server. For a list of databases available from the EBI, see the EBI website at www.ebi.ac.uk/cgi-bin/dbfetch/


Returns:array of database names

[Source]

     # File lib/bio/io/fetch.rb, line 143
143:     def databases
144:       _get_single('info', 'dbs').strip.split(/\s+/)
145:     end

Fetch a database entry as specified by database (db), entry id (id), ‘raw’ text or ‘html’ (style), and format. When using BioRuby‘s BioFetch server, value for the format should not be set. Examples:

  server = Bio::Fetch.new('http://www.ebi.ac.uk/cgi-bin/dbfetch')
  puts server.fetch('embl','M33388','raw','fasta')
  puts server.fetch('refseq','NM_12345','html','embl')

Arguments:

[Source]

     # File lib/bio/io/fetch.rb, line 105
105:     def fetch(db, id, style = 'raw', format = nil)
106:       query = [ [ 'db',    db ],
107:                 [ 'id',    id ],
108:                 [ 'style', style ] ]
109:       query.push([ 'format', format ]) if format
110:   
111:       _get(query)
112:     end

Lists the formats that are available for a given database. Like the Bio::Fetch#databases method, this method is only available on the bioruby dbfetch server. Example:

 server = Bio::Fetch.new()
 puts server.formats('embl') # returns "default fasta"

Arguments:

  • database:: name of database you want the supported formats for
Returns:array of formats

[Source]

     # File lib/bio/io/fetch.rb, line 157
157:     def formats(database = @database)
158:       if database
159:         query = [ [ 'info', 'formats' ],
160:                   [ 'db',   database  ] ]
161:         _get(query).strip.split(/\s+/)
162:       end
163:     end

Get raw database entry by id. This method lets the Bio::Registry class use Bio::Fetch objects.

[Source]

    # File lib/bio/io/fetch.rb, line 88
88:     def get_by_id(id)
89:       fetch(@database, id)
90:     end

A dbfetch server will only return entries up to a given maximum number. This method retrieves that number from the server. As for the databases and formats methods, the maxids method only works for the bioruby dbfetch server.


Arguments: none

Returns:number

[Source]

     # File lib/bio/io/fetch.rb, line 172
172:     def maxids
173:       _get_single('info', 'maxids').to_i
174:     end

[Validate]