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 Please direct usage questions or support issues to the mailing list:
50 I<bioperl-l@bioperl.org>
52 rather than to the module maintainer directly. Many experienced and
53 reponsive experts will be able look at the problem and quickly
54 address it. Please include a thorough description of the problem
55 with code and data examples if at all possible.
59 Report bugs to the Bioperl bug tracking system to help us keep track
60 the bugs and their resolution. Bug reports can be submitted via the web:
62 http://redmine.open-bio.org/projects/bioperl
64 =head1 AUTHOR - Brian Osborne
66 Email bosborne at alum.mit.edu
70 The rest of the documentation details each of the object methods. Internal
71 methods are usually preceded with a _
75 # Let the code begin...
77 package Bio
::DB
::BioSQL
::OBDA
;
79 use Bio
::DB
::Query
::BioQuery
;
81 use base
qw(Bio::Root::Root Bio::DB::RandomAccessI);
83 =head2 new_from_registry
85 Title : new_from_registry
87 Function: Create a database object that can be used by OBDA
89 Args : Hash containing connection parameters read from an OBDA
94 sub new_from_registry
{
95 my ($class, %conf) = @_;
96 my $self = $class->SUPER::new
();
98 # prevent warning msg by allowing location to be undef for postgresql 'ident sameuser' login)
99 if (defined $conf{'location'}) {
100 ($host,$port) = split ":", $conf{'location'};
102 my $db = Bio
::DB
::BioDB
->new( -database
=> 'biosql',
105 -dbname
=> $conf{'dbname'},
106 -driver
=> $conf{'driver'},
107 -user
=> $conf{'user' },
108 -pass
=> $conf{'passwd'} );
113 =head1 Methods inherited from Bio::DB::RandomAccessI
117 Title : get_Seq_by_id
118 Usage : $seq = $db->get_Seq_by_id(12345)
121 Returns : One or more Sequence objects
130 $self->throw("No identifier given") unless $id;
132 my $query = $self->{'_byId_Query'};
134 $query = Bio
::DB
::Query
::BioQuery
->new(
135 -datacollections
=> ['Bio::SeqI seq'],
136 -where
=> ["seq.primary_id = ?"]);
137 $self->{'_byId_Query'} = $query;
139 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
140 my $result = $seq_adaptor->find_by_query($query,
141 '-name' => 'OBDA get_Seq_by_id',
144 for my $seq ($result->next_object) {
147 return wantarray ?
@seqs : $seqs[0];
150 =head2 get_Seq_by_acc
152 Title : get_Seq_by_acc
153 Usage : $seq = $db->get_Seq_by_acc('A12345')
156 Returns : One or more Sequence objects
157 Args : An accession number
162 my ($self,$acc) = @_;
165 $self->throw("No accession given") unless $acc;
167 my $query = $self->{'_byAcc_Query'};
169 $query = Bio
::DB
::Query
::BioQuery
->new(
170 -datacollections
=> ['Bio::SeqI seq'],
171 -where
=> ["seq.accession_number = ?"]);
172 $self->{'_byAcc_Query'} = $query;
174 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
175 my $result = $seq_adaptor->find_by_query($query,
176 '-name' => "OBDA get_Seq_by_acc",
177 '-values' => [$acc]);
179 for my $seq ($result->next_object) {
182 return wantarray ?
@seqs : $seqs[0];
185 =head2 get_Seq_by_version
187 Title : get_Seq_by_version
188 Usage : $seq = $db->get_Seq_by_version('A12345.3')
191 Returns : One or more Sequence objects
192 Args : A versioned accession number
196 sub get_Seq_by_version
{
197 my ($self,$vacc) = @_;
200 my @comps = split(/\./, $vacc); # split into components on period
201 $self->throw("Must supply a versioned accession: <accession>.<version>")
203 my $ver = pop(@comps); # the last one is the version
204 my $acc = join(".",@comps); # the preceding rest is the accession
206 my $query = $self->{'_byAccVersion_Query'};
208 $query = Bio
::DB
::Query
::BioQuery
->new(
209 -datacollections
=> ['Bio::SeqI seq'],
210 -where
=> ["seq.accession_number = ?",
212 $self->{'_byAccVersion_Query'} = $query;
214 my $seq_adaptor = $db->get_object_adaptor('Bio::SeqI');
215 my $result = $seq_adaptor->find_by_query($query,
216 '-name' => "OBDA get_Seq_by_version",
217 '-values' => [$acc,$ver]);
219 for my $seq ($result->next_object) {
222 return wantarray ?
@seqs : $seqs[0];
225 =head1 Private methods
231 Function: Get or set the BioDB object
240 $self->{_db
} = $db if ($db);