3 # BioPerl module for Bio::DB::BioSQL::OBDA
5 # Copyright Brian Osborne
7 # You may distribute this module under the same terms as perl itself
9 # POD documentation - main docs before the code
17 This module is meant to be used a part of the OBDA system, e.g.:
19 use Bio::DB::Registry;
21 my $registry = Bio::DB::Registry->new;
22 my $db = $registry->get_database('biosql');
23 my $seq = $db->get_Seq_by_acc('P41932');
27 This module connects code that uses OBDA to the bioperl-db package
28 and the underlying BioSQL database.
30 The Open Biological Database Access (OBDA) system was designed so that one
31 could use the same application code to access data from multiple database
32 types by simply changing a few lines in a configuration file. See
33 L<http://www.bioperl.org/wiki/HOWTO:OBDA> for more information.
39 User feedback is an integral part of the evolution of this
40 and other Bioperl modules. Send your comments and suggestions preferably
41 to one of the Bioperl mailing lists.
42 Your participation is much appreciated.
44 bioperl-l@bio.perl.org
48 Report bugs to the Bioperl bug tracking system to help us keep track
49 the bugs and their resolution. Bug reports can be submitted via the web:
51 http://bugzilla.open-bio.org
53 =head1 AUTHOR - Brian Osborne
55 Email bosborne at alum.mit.edu
59 The rest of the documentation details each of the object methods. Internal
60 methods are usually preceded with a _
64 # Let the code begin...
66 package Bio
::DB
::BioSQL
::OBDA
;
68 use Bio
::DB
::Query
::BioQuery
;
70 use base
qw(Bio::Root::Root Bio::DB::RandomAccessI);
72 =head2 new_from_registry
74 Title : new_from_registry
76 Function: Create a database object that can be used by OBDA
78 Args : Hash containing connection parameters read from an OBDA
83 sub new_from_registry
{
84 my ($class, %conf) = @_;
85 my $self = $class->SUPER::new
();
87 # prevent warning msg by allowing location to be undef for postgresql 'ident sameuser' login)
88 if (defined $conf{'location'}) {
89 ($host,$port) = split ":", $conf{'location'};
91 my $db = Bio
::DB
::BioDB
->new( -database
=> 'biosql',
94 -dbname
=> $conf{'dbname'},
95 -driver
=> $conf{'driver'},
96 -user
=> $conf{'user' },
97 -pass
=> $conf{'passwd'} );
102 =head1 Methods inherited from Bio::DB::RandomAccessI
106 Title : get_Seq_by_id
107 Usage : $seq = $db->get_Seq_by_id(12345)
110 Returns : One or more Sequence objects
119 $self->throw("No identifier given") unless $id;
121 my $query = Bio
::DB
::Query
::BioQuery
->new(
122 -datacollections
=> ['Bio::SeqI seq'],
123 -where
=> ["seq.primary_id = $id"]);
125 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
126 my $result = $seq_adaptor->find_by_query($query);
128 for my $seq ($result->next_object) {
131 return wantarray ?
@seqs : $seqs[0];
134 =head2 get_Seq_by_acc
136 Title : get_Seq_by_acc
137 Usage : $seq = $db->get_Seq_by_acc('A12345')
140 Returns : One or more Sequence objects
141 Args : An accession number
146 my ($self,$acc) = @_;
149 $self->throw("No accession given") unless $acc;
151 my $query = Bio
::DB
::Query
::BioQuery
->new(
152 -datacollections
=> ['Bio::SeqI seq'],
153 -where
=> ["seq.accession_number = '$acc'"]);
155 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
156 my $result = $seq_adaptor->find_by_query($query);
158 for my $seq ($result->next_object) {
161 return wantarray ?
@seqs : $seqs[0];
164 =head2 get_Seq_by_version
166 Title : get_Seq_by_version
167 Usage : $seq = $db->get_Seq_by_version('A12345.3')
170 Returns : One or more Sequence objects
171 Args : A versioned accession number
175 sub get_Seq_by_version
{
176 my ($self,$vacc) = @_;
179 my ($acc,$ver) = split /\./, $vacc; # split on period
180 $self->throw("Must supply a versioned accession: <accession>.<version>")
181 unless ($acc && $ver);
183 my $query = Bio
::DB
::Query
::BioQuery
->new(
184 -datacollections
=> ['Bio::SeqI seq'],
185 -where
=> ["seq.accession_number = '$acc'",
186 "seq.version = $ver"]);
188 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
189 my $result = $seq_adaptor->find_by_query($query);
191 for my $seq ($result->next_object) {
194 return wantarray ?
@seqs : $seqs[0];
197 =head1 Private methods
203 Function: Get or set the BioDB object
212 $self->{_db
} = $db if ($db);