Class: Bio::Fetch
Overview
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')
Instance Attribute Summary collapse
-
#database ⇒ Object
The default database to query – This will be used by the get_by_id method ++.
Class Method Summary collapse
-
.query(*args) ⇒ Object
Shortcut for using BioRuby’s BioFetch server.
Instance Method Summary collapse
-
#databases ⇒ Object
Using this method, the user can ask a dbfetch server what databases it supports.
-
#fetch(db, id, style = 'raw', format = nil) ⇒ Object
Fetch a database entry as specified by database (db), entry id (id), ‘raw’ text or ‘html’ (style), and format.
-
#formats(database = @database) ⇒ Object
Lists the formats that are available for a given database.
-
#get_by_id(id) ⇒ Object
Get raw database entry by id.
-
#initialize(url = 'http://bioruby.org/cgi-bin/biofetch.rb') ⇒ Fetch
constructor
- Create a new Bio::Fetch server object that can subsequently be queried using the Bio::Fetch#fetch method — Arguments: * url: URL of dbfetch server (default = ‘bioruby.org/cgi-bin/biofetch.rb’) Returns
-
Bio::Fetch object.
-
#maxids ⇒ Object
A dbfetch server will only return entries up to a given maximum number.
Constructor Details
#initialize(url = 'http://bioruby.org/cgi-bin/biofetch.rb') ⇒ Fetch
Create a new Bio::Fetch server object that can subsequently be queried using the Bio::Fetch#fetch method
Arguments:
-
url: URL of dbfetch server (default = ‘bioruby.org/cgi-bin/biofetch.rb’)
- Returns
-
Bio::Fetch object
74 75 76 77 |
# File 'lib/bio/io/fetch.rb', line 74 def initialize(url = 'http://bioruby.org/cgi-bin/biofetch.rb') @url = url schema, user, @host, @port, reg, @path, = URI.split(@url) end |
Instance Attribute Details
#database ⇒ Object
The default database to query – This will be used by the get_by_id method ++
83 84 85 |
# File 'lib/bio/io/fetch.rb', line 83 def database @database end |
Class Method Details
.query(*args) ⇒ Object
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:
-
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)
125 126 127 |
# File 'lib/bio/io/fetch.rb', line 125 def self.query(*args) self.new.fetch(*args) end |
Instance Method Details
#databases ⇒ Object
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
141 142 143 144 145 |
# File 'lib/bio/io/fetch.rb', line 141 def databases query = "info=dbs" Bio::Command.read_uri(@url + '?' + URI.escape(query)).strip.split(/\s+/) end |
#fetch(db, id, style = 'raw', format = nil) ⇒ Object
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:
-
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)
104 105 106 107 108 109 110 |
# File 'lib/bio/io/fetch.rb', line 104 def fetch(db, id, style = 'raw', format = nil) query = [ "db=#{db}", "id=#{id}", "style=#{style}" ] query.push("format=#{format}") if format query = query.join('&') Bio::Command.read_uri(@url + '?' + URI.escape(query)) end |
#formats(database = @database) ⇒ Object
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
157 158 159 160 161 162 163 |
# File 'lib/bio/io/fetch.rb', line 157 def formats(database = @database) if database query = "info=formats;db=#{database}" Bio::Command.read_uri(@url + '?' + URI.escape(query)).strip.split(/\s+/) end end |
#get_by_id(id) ⇒ Object
Get raw database entry by id. This method lets the Bio::Registry class use Bio::Fetch objects.
87 88 89 |
# File 'lib/bio/io/fetch.rb', line 87 def get_by_id(id) fetch(@database, id) end |
#maxids ⇒ Object
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
172 173 174 175 176 |
# File 'lib/bio/io/fetch.rb', line 172 def maxids query = "info=maxids" Bio::Command.read_uri(@url + '?' + URI.escape(query)).to_i end |