2 # POD documentation - main docs before the code
6 Bio::DB::Failover - A Bio::DB::RandomAccessI compliant class which
7 wraps a prioritized list of DBs
11 $failover = Bio::DB::Failover->new();
13 $failover->add_database($db);
15 # fail over Bio::DB::RandomAccessI.pm
17 # this will check each database in priority, returning when
18 # the first one succeeds
20 $seq = $failover->get_Seq_by_id($id);
24 This module provides fail over access to a set of Bio::DB::RandomAccessI
29 Ewan Birney E<lt>birney@ebi.ac.ukE<gt> originally wrote this class.
33 Please direct usage questions or support issues to the mailing list:
35 I<bioperl-l@bioperl.org>
37 rather than to the module maintainer directly. Many experienced and
38 reponsive experts will be able look at the problem and quickly
39 address it. Please include a thorough description of the problem
40 with code and data examples if at all possible.
44 Report bugs to the Bioperl bug tracking system to help us keep track
45 the bugs and their resolution. Bug reports can be submitted via the
48 https://github.com/bioperl/bioperl-live/issues
52 The rest of the documentation details each of the object
53 methods. Internal methods are usually preceded with a _
57 # Let the code begin...
59 package Bio
::DB
::Failover
;
63 use base
qw(Bio::Root::Root Bio::DB::RandomAccessI);
66 my ($class,@args) = @_;
68 my $self = $class->SUPER::new
(@args);
70 $self->{'_database'} = [];
77 Usage : add_database(%db)
78 Function: Adds a database to the Failover object
79 Returns : Count of number of databases
80 Args : Array of db resources
81 Throws : Not a RandomAccessI exception
88 if ( !ref $db || !$db->isa('Bio::DB::RandomAccessI') ) {
89 $self->throw("Database object $db is a not a Bio::DB::RandomAccessI");
93 push(@
{$self->{'_database'}},$db);
95 scalar @
{$self->{'_database'}};
101 Title : get_Seq_by_id
102 Usage : $seq = $db->get_Seq_by_id('ROA1_HUMAN')
103 Function: Gets a Bio::Seq object by its name
104 Returns : a Bio::Seq object
105 Args : the id (as a string) of a sequence
106 Throws : "no id" exception
114 $self->throw("no id is given!");
117 foreach my $db ( @
{$self->{'_database'}} ) {
121 $seq = $db->get_Seq_by_id($id);
123 $self->warn($@
) if $@
;
124 if ( defined $seq ) {
127 $self->warn("No sequence retrieved by database " . ref($db));
134 =head2 get_Seq_by_acc
136 Title : get_Seq_by_acc
137 Usage : $seq = $db->get_Seq_by_acc('X77802');
138 Function: Gets a Bio::Seq object by accession number
139 Returns : A Bio::Seq object
140 Args : accession number (as a string)
141 Throws : "no id" exception
149 $self->throw("no id is given!");
152 foreach my $db ( @
{$self->{'_database'}} ) {
155 $seq = $db->get_Seq_by_acc($id);
157 $self->warn($@
) if $@
;
158 if ( defined $seq ) {
161 $self->warn("No sequence retrieved by database " . ref($db));
167 =head2 get_Seq_by_version
169 Title : get_Seq_by_version
170 Usage : $seq = $db->get_Seq_by_acc('X77802.2');
171 Function: Gets a Bio::Seq object by versioned accession number
172 Returns : A Bio::Seq object
173 Args : accession number (as a string)
174 Throws : "acc does not exist" exception
178 sub get_Seq_by_version
{
182 $self->throw("no acc is given!");
185 foreach my $db ( @
{$self->{'_database'}} ) {
188 $seq = $db->get_Seq_by_version($id);
190 $self->warn($@
) if $@
;
191 if ( defined $seq ) {
194 $self->warn("No sequence retrieved by database " . ref($db));