class Bio::Fetch


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:

Note that old URL still alives probably because of compatibility, but using the new URL is recommended.

Historically, there were other dbfetch servers including:

But they are unavailable now.

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


require 'bio'

# Retrieve the sequence of accession number M33388 from the EMBL
# database.
server =  #uses EBI server
puts server.fetch('ena_sequence','M33388')

# database name "embl" can also be used though it is not officially listed
puts server.fetch('embl','M33388')

# Do the same thing with explicitly giving the URL.
server =  #uses EBI server
puts server.fetch('ena_sequence','M33388')

# Do the same thing without creating a Bio::Fetch::EBI object.
puts Bio::Fetch::EBI.query('ena_sequence','M33388')

# To know what databases are available on the dbfetch server:
server =
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')



The default database to query

Public Class Methods

new(url = nil) click to toggle source

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

You must specify url of a server. The preset default server is deprecated.

If you want to use a server without explicitly specifying the URL, use that uses EBI Dbfetch server.


  • url: URL of dbfetch server. (no default value)


Bio::Fetch object

    # File lib/bio/io/fetch.rb
140 def initialize(url = nil)
141   unless url then
142     raise ArgumentError, "No server URL is given in The default server URL value have been deprecated. You must explicitly specify the url or use Bio::Fetch::EBI for using EBI Dbfetch."
143   end
144   @url = url
145 end

Public Instance Methods

databases() click to toggle source

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 =
puts server.databases # returns "aa aax bl cpd dgenes dr ec eg emb ..."

This method works for EBI Dbfetch server (and for the bioruby dbfetch server). Not all servers support this method.


array of database names

    # File lib/bio/io/fetch.rb
192 def databases
193   _get_single('info', 'dbs').strip.split(/\s+/)
194 end
fetch(db, id, style = 'raw', format = nil) click to toggle source

Fetch a database entry as specified by database (db), entry id (id), ‘raw’ text or ‘html’ (style), and format.


server ='')
puts server.fetch('embl','M33388','raw','fasta')
puts server.fetch('refseq','NM_12345','html','embl')


  • database: name of database to query (see Bio::Fetch#databases to get list of supported databases)

  • id: single ID or ID list separated by commas or white space

  • style: [raw|html] (default = ‘raw’)

  • format: name of output format (see Bio::Fetch#formats)

    # File lib/bio/io/fetch.rb
172 def fetch(db, id, style = 'raw', format = nil)
173   query = [ [ 'db',    db ],
174             [ 'id',    id ],
175             [ 'style', style ] ]
176   query.push([ 'format', format ]) if format
178   _get(query)
179 end
formats(database = @database) click to toggle source

Lists the formats that are available for a given database. Like the Bio::Fetch#databases method, not all servers support this method. This method is available on the EBI Dbfetch server (and on the bioruby dbfetch server).


server =
puts server.formats('embl') # returns [ "default", "annot", ... ]


  • database

    name of database you want the supported formats for


array of formats

    # File lib/bio/io/fetch.rb
208 def formats(database = @database)
209   if database
210     query = [ [ 'info', 'formats' ],
211               [ 'db',   database  ] ]
212     _get(query).strip.split(/\s+/)
213   end
214 end
get_by_id(id) click to toggle source

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

    # File lib/bio/io/fetch.rb
155 def get_by_id(id)
156   fetch(@database, id)
157 end
maxids() click to toggle source

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, not all servers support the maxids method. This method is available on the EBI Dbfetch server (and on the bioruby dbfetch server).


server =
puts server.maxids # currently returns 200

Arguments: none



    # File lib/bio/io/fetch.rb
228 def maxids
229   _get_single('info', 'maxids').to_i
230 end