3 # POD documentation - main docs before the code
7 Bio::DB::Failover - A Bio::DB::RandomAccessI compliant class which
8 wraps a prioritized list of DBs
12 $failover = Bio::DB::Failover->new();
14 $failover->add_database($db);
16 # fail over Bio::DB::RandomAccessI.pm
18 # this will check each database in priority, returning when
19 # the first one succeeds
21 $seq = $failover->get_Seq_by_id($id);
25 This module provides fail over access to a set of Bio::DB::RandomAccessI
30 Ewan Birney E<lt>birney@ebi.ac.ukE<gt> originally wrote this class.
34 Report bugs to the Bioperl bug tracking system to help us keep track
35 the bugs and their resolution. Bug reports can be submitted via the
38 http://bugzilla.open-bio.org/
42 The rest of the documentation details each of the object
43 methods. Internal methods are usually preceded with a _
47 # Let the code begin...
49 package Bio
::DB
::Failover
;
53 use base
qw(Bio::Root::Root Bio::DB::RandomAccessI);
56 my ($class,@args) = @_;
58 my $self = $class->SUPER::new
(@args);
60 $self->{'_database'} = [];
67 Usage : add_database(%db)
68 Function: Adds a database to the Failover object
69 Returns : Count of number of databases
70 Args : Array of db resources
71 Throws : Not a RandomAccessI exception
78 if ( !ref $db || !$db->isa('Bio::DB::RandomAccessI') ) {
79 $self->throw("Database object $db is a not a Bio::DB::RandomAccessI");
83 push(@
{$self->{'_database'}},$db);
85 scalar @
{$self->{'_database'}};
92 Usage : $seq = $db->get_Seq_by_id('ROA1_HUMAN')
93 Function: Gets a Bio::Seq object by its name
94 Returns : a Bio::Seq object
95 Args : the id (as a string) of a sequence
96 Throws : "no id" exception
104 $self->throw("no id is given!");
107 foreach my $db ( @
{$self->{'_database'}} ) {
111 $seq = $db->get_Seq_by_id($id);
113 $self->warn($@
) if $@
;
114 if ( defined $seq ) {
117 $self->warn("No sequence retrieved by database " . ref($db));
124 =head2 get_Seq_by_acc
126 Title : get_Seq_by_acc
127 Usage : $seq = $db->get_Seq_by_acc('X77802');
128 Function: Gets a Bio::Seq object by accession number
129 Returns : A Bio::Seq object
130 Args : accession number (as a string)
131 Throws : "no id" exception
139 $self->throw("no id is given!");
142 foreach my $db ( @
{$self->{'_database'}} ) {
145 $seq = $db->get_Seq_by_acc($id);
147 $self->warn($@
) if $@
;
148 if ( defined $seq ) {
151 $self->warn("No sequence retrieved by database " . ref($db));
157 =head2 get_Seq_by_version
159 Title : get_Seq_by_version
160 Usage : $seq = $db->get_Seq_by_acc('X77802.2');
161 Function: Gets a Bio::Seq object by versioned accession number
162 Returns : A Bio::Seq object
163 Args : accession number (as a string)
164 Throws : "acc does not exist" exception
168 sub get_Seq_by_version
{
172 $self->throw("no acc is given!");
175 foreach my $db ( @
{$self->{'_database'}} ) {
178 $seq = $db->get_Seq_by_version($id);
180 $self->warn($@
) if $@
;
181 if ( defined $seq ) {
184 $self->warn("No sequence retrieved by database " . ref($db));