0
|
1 # POD documentation - main docs before the code
|
|
2
|
|
3 # $Id: Failover.pm,v 1.5.2.1 2003/06/25 13:44:18 heikki Exp $
|
|
4
|
|
5
|
|
6 =head1 NAME
|
|
7
|
|
8 Bio::DB::Failover - A Bio::DB::RandomAccessI compliant class which wraps a priority list of DBs
|
|
9
|
|
10 =head1 SYNOPSIS
|
|
11
|
|
12 $failover = Bio::DB::Failover->new();
|
|
13
|
|
14 $failover->add_database($db);
|
|
15
|
|
16 # fail over Bio::DB::RandomAccessI.pm
|
|
17
|
|
18 # this will check each database in priority, returning when
|
|
19 # the first one succeeds
|
|
20
|
|
21 $seq = $failover->get_Seq_by_id($id);
|
|
22
|
|
23 =head1 DESCRIPTION
|
|
24
|
|
25 This module provides fail over access to a set of Bio::DB::RandomAccessI objects
|
|
26
|
|
27
|
|
28 =head1 CONTACT
|
|
29
|
|
30 Ewan Birney originally wrote this class.
|
|
31
|
|
32 =head2 Reporting Bugs
|
|
33
|
|
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 email
|
|
36 or the web:
|
|
37
|
|
38 bioperl-bugs@bio.perl.org
|
|
39 http://bugzilla.bioperl.org/
|
|
40
|
|
41 =head1 APPENDIX
|
|
42
|
|
43 The rest of the documentation details each of the object
|
|
44 methods. Internal methods are usually preceded with a _
|
|
45
|
|
46 =cut
|
|
47
|
|
48
|
|
49 # Let the code begin...
|
|
50
|
|
51 package Bio::DB::Failover;
|
|
52
|
|
53 use vars qw(@ISA);
|
|
54 use strict;
|
|
55
|
|
56 use Bio::Root::Root;
|
|
57 use Bio::DB::RandomAccessI;
|
|
58 @ISA = qw(Bio::Root::Root Bio::DB::RandomAccessI );
|
|
59
|
|
60 sub new {
|
|
61 my ($class,@args) = @_;
|
|
62
|
|
63 my $self = $class->SUPER::new(@args);
|
|
64
|
|
65 $self->{'_database'} = [];
|
|
66 return $self;
|
|
67 }
|
|
68
|
|
69 =head2 add_database
|
|
70
|
|
71 Title : add_database
|
|
72 Usage : add_database(%db)
|
|
73 Function: Adds a database to the
|
|
74 Returns : count of number of databases
|
|
75 Args : hash of db resource name to Bio::DB::SeqI object
|
|
76
|
|
77 =cut
|
|
78
|
|
79 sub add_database {
|
|
80 my ($self,@db) = @_;
|
|
81 foreach my $db ( @db ) {
|
|
82 if( !ref $db || !$db->isa('Bio::DB::RandomAccessI') ) {
|
|
83 $self->throw("Database objects $db is a not a Bio::DB::RandomAccessI");
|
|
84 next;
|
|
85 }
|
|
86
|
|
87 push(@{$self->{'_database'}},$db);
|
|
88 }
|
|
89 }
|
|
90
|
|
91
|
|
92 =head2 get_Seq_by_id
|
|
93
|
|
94 Title : get_Seq_by_id
|
|
95 Usage : $seq = $db->get_Seq_by_id('ROA1_HUMAN')
|
|
96 Function: Gets a Bio::Seq object by its name
|
|
97 Returns : a Bio::Seq object
|
|
98 Args : the id (as a string) of a sequence
|
|
99 Throws : "id does not exist" exception
|
|
100
|
|
101
|
|
102 =cut
|
|
103
|
|
104 sub get_Seq_by_id {
|
|
105 my ($self,$id) = @_;
|
|
106
|
|
107 if( !defined $id ) {
|
|
108 $self->throw("no id is given!");
|
|
109 }
|
|
110
|
|
111 foreach my $db ( @{$self->{'_database'}} ) {
|
|
112 my $seq;
|
|
113
|
|
114 eval {
|
|
115 $seq = $db->get_Seq_by_id($id);
|
|
116 };
|
|
117 if( defined $seq ) {
|
|
118 return $seq;
|
|
119 }
|
|
120 }
|
|
121
|
|
122 return undef;
|
|
123 }
|
|
124
|
|
125 =head2 get_Seq_by_acc
|
|
126
|
|
127 Title : get_Seq_by_acc
|
|
128 Usage : $seq = $db->get_Seq_by_acc('X77802');
|
|
129 Function: Gets a Bio::Seq object by accession number
|
|
130 Returns : A Bio::Seq object
|
|
131 Args : accession number (as a string)
|
|
132 Throws : "acc does not exist" exception
|
|
133
|
|
134
|
|
135 =cut
|
|
136
|
|
137 sub get_Seq_by_acc {
|
|
138 my ($self,$id) = @_;
|
|
139
|
|
140 if( !defined $id ) {
|
|
141 $self->throw("no id is given!");
|
|
142 }
|
|
143
|
|
144 foreach my $db ( @{$self->{'_database'}} ) {
|
|
145 my $seq;
|
|
146 eval {
|
|
147 $seq = $db->get_Seq_by_acc($id);
|
|
148 };
|
|
149 if( defined $seq ) {
|
|
150 return $seq;
|
|
151 }
|
|
152 }
|
|
153 return undef;
|
|
154 }
|
|
155
|
|
156
|
|
157 ## End of Package
|
|
158
|
|
159 1;
|
|
160
|
|
161 __END__
|
|
162
|