0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 =head1 NAME
|
|
22
|
|
23 Bio::EnsEMBL::DBSQL::DBAdaptor
|
|
24
|
|
25 =head1 SYNOPSIS
|
|
26
|
|
27 $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
|
|
28 -user => 'root',
|
|
29 -dbname => 'pog',
|
|
30 -host => 'caldy',
|
|
31 -driver => 'mysql'
|
|
32 );
|
|
33
|
|
34 $gene_adaptor = $db->get_GeneAdaptor();
|
|
35
|
|
36 $gene = $gene_adaptor->fetch_by_stable_id($stable_id);
|
|
37
|
|
38 $slice =
|
|
39 $db->get_SliceAdaptor()->fetch_by_chr_start_end( 'X', 1, 10000 );
|
|
40
|
|
41 =head1 DESCRIPTION
|
|
42
|
|
43 Formerly this class provided database connectivity and a means
|
|
44 to retrieve object adaptors. This class is now provided for
|
|
45 convenience and backwards compatibility, and delegates its connection
|
|
46 responsibilities to the DBConnection class (no longer inherited from)
|
|
47 and its object adaptor retrieval to the static Bio::EnsEMBL::Registry.
|
|
48
|
|
49 Please use Bio::EnsEMBL::Registry to retrieve object adaptors.
|
|
50
|
|
51 =head1 METHODS
|
|
52
|
|
53 =cut
|
|
54
|
|
55 package Bio::EnsEMBL::DBSQL::DBAdaptor;
|
|
56
|
|
57 use strict;
|
|
58
|
|
59 use Bio::EnsEMBL::DBSQL::DBConnection;
|
|
60 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
|
|
61 use Bio::EnsEMBL::Utils::SeqRegionCache;
|
|
62 use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
|
|
63 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
|
|
64 use Bio::EnsEMBL::Registry;
|
|
65 use Bio::EnsEMBL::Utils::ConfigRegistry;
|
|
66
|
|
67 my $reg = "Bio::EnsEMBL::Registry";
|
|
68
|
|
69 =head2 new
|
|
70
|
|
71 Arg [-DNADB]: (optional) Bio::EnsEMBL::DBSQL::DBAdaptor DNADB
|
|
72 All sequence, assembly, contig information etc, will
|
|
73 be retrieved from this database instead.
|
|
74
|
|
75 Arg [-NO_CACHE]: (optional) int 1
|
|
76 This option will turn off caching for slice features,
|
|
77 so, every time a set of features is retrieved,
|
|
78 they will come from the database instead of the
|
|
79 cache. This option is only recommended for advanced
|
|
80 users, specially if you need to store and retrieve
|
|
81 features. It might reduce performance when querying
|
|
82 the database if not used properly. If in doubt, do
|
|
83 not use it or ask in the developer mailing list.
|
|
84
|
|
85 Arg [..] : Other args are passed to superclass
|
|
86 Bio::EnsEMBL::DBSQL::DBConnection
|
|
87
|
|
88 Example : $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
|
|
89 -user => 'root',
|
|
90 -dbname => 'pog',
|
|
91 -host => 'caldy',
|
|
92 -driver => 'mysql'
|
|
93 );
|
|
94
|
|
95 $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
|
|
96 -species => 'Homo_sapiens',
|
|
97 -group => 'core',
|
|
98 -user => 'root',
|
|
99 -dbname => 'pog',
|
|
100 -host => 'caldy',
|
|
101 -driver => 'mysql'
|
|
102 );
|
|
103
|
|
104 $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
|
|
105 -species => 'staphylococcus_aureus',
|
|
106 -group => 'core',
|
|
107 -user => 'root',
|
|
108 -dbname => 'staphylococcus_collection_1_52_1a',
|
|
109 -multispecies_db => 1,
|
|
110 -host => 'caldy',
|
|
111 -driver => 'mysql'
|
|
112 );
|
|
113
|
|
114 Description: Constructor for DBAdaptor.
|
|
115 Returntype : Bio::EnsEMBL::DBSQL::DBAdaptor
|
|
116 Exceptions : none
|
|
117 Caller : general
|
|
118 Status : Stable
|
|
119
|
|
120 =cut
|
|
121
|
|
122 sub new {
|
|
123 my ( $class, @args ) = @_;
|
|
124
|
|
125 my $self = bless {}, $class;
|
|
126
|
|
127 my ( $is_multispecies, $species, $species_id, $group, $con, $dnadb,
|
|
128 $no_cache, $dbname )
|
|
129 = rearrange( [
|
|
130 'MULTISPECIES_DB', 'SPECIES', 'SPECIES_ID', 'GROUP',
|
|
131 'DBCONN', 'DNADB', 'NO_CACHE', 'DBNAME'
|
|
132 ],
|
|
133 @args
|
|
134 );
|
|
135
|
|
136 if ( defined($con) ) { $self->dbc($con) }
|
|
137 else {
|
|
138 if(! defined $dbname) {
|
|
139 throw "-DBNAME is a required parameter when creating a DBAdaptor";
|
|
140 }
|
|
141 $self->dbc( new Bio::EnsEMBL::DBSQL::DBConnection(@args) );
|
|
142 }
|
|
143
|
|
144 if ( defined($species) ) { $self->species($species) }
|
|
145 if ( defined($group) ) { $self->group($group) }
|
|
146
|
|
147
|
|
148 $self = Bio::EnsEMBL::Utils::ConfigRegistry::gen_load($self);
|
|
149
|
|
150 # if(!defined($species) ){
|
|
151 # $reg->find_and_add_aliases($self);
|
|
152 # }
|
|
153
|
|
154 $self->species_id( $species_id || 1 );
|
|
155
|
|
156 $self->is_multispecies( defined($is_multispecies)
|
|
157 && $is_multispecies == 1 );
|
|
158
|
|
159 if ( defined($dnadb) ) { $self->dnadb($dnadb) }
|
|
160 if ( defined($no_cache) ) { $self->no_cache($no_cache) }
|
|
161
|
|
162 return $self;
|
|
163 } ## end sub new
|
|
164
|
|
165 =head2 clear_caches
|
|
166
|
|
167 Example : $dba->clear_caches();
|
|
168 Description : Loops through all linked adaptors and clears their
|
|
169 caches if C<clear_cache()> is implemented. Not all caches
|
|
170 are cleared & the DBAdaptor instance should be removed from
|
|
171 the registry to clear these remaining essential caches.
|
|
172 Returntype : None
|
|
173 Exceptions : None
|
|
174
|
|
175 =cut
|
|
176
|
|
177 sub clear_caches {
|
|
178 my ($self) = @_;
|
|
179 my $adaptors = Bio::EnsEMBL::Registry->get_all_adaptors(
|
|
180 $self->species(), $self->group());
|
|
181 while (my $adaptor = shift @{$adaptors}) {
|
|
182 if($adaptor->can('clear_cache')) {
|
|
183 $adaptor->clear_cache();
|
|
184 }
|
|
185 }
|
|
186 return;
|
|
187 }
|
|
188
|
|
189 =head2 dbc
|
|
190
|
|
191 Arg[1] : (optional) Bio::EnsEMBL::DBSQL::DBConnection
|
|
192
|
|
193 Example : $dbc = $dba->dbc();
|
|
194 Description: Getter/Setter for DBConnection.
|
|
195 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
|
|
196 Exceptions : throws if argument not a Bio::EnsEMBL::DBSQL::DBConnection
|
|
197 Caller : general
|
|
198 Status : Stable
|
|
199
|
|
200 =cut
|
|
201
|
|
202 sub dbc{
|
|
203 my $self = shift;
|
|
204
|
|
205 if(@_){
|
|
206 my $arg = shift;
|
|
207 if(defined($arg)){
|
|
208 if(!$arg->isa('Bio::EnsEMBL::DBSQL::DBConnection')){
|
|
209 throw("$arg is no a DBConnection\n");
|
|
210 }
|
|
211 }
|
|
212 $self->{_dbc} = $arg;
|
|
213 }
|
|
214 return $self->{_dbc};
|
|
215 }
|
|
216
|
|
217
|
|
218
|
|
219 =head2 add_db_adaptor
|
|
220
|
|
221 Arg [1] : string $name
|
|
222 the name of the database to attach to this database
|
|
223 Arg [2] : Bio::EnsEMBL::DBSQL::DBConnection
|
|
224 the db adaptor to attach to this database
|
|
225 Example : $db->add_db_adaptor('lite', $lite_db_adaptor);
|
|
226 Description: Attaches another database instance to this database so
|
|
227 that it can be used in instances where it is required.
|
|
228 Returntype : none
|
|
229 Exceptions : none
|
|
230 Caller : EnsWeb
|
|
231 Status : At Risk
|
|
232 : may get deprecated, please use add_db from the registry instead
|
|
233
|
|
234 =cut
|
|
235
|
|
236 sub add_db_adaptor {
|
|
237 my ($self, $name, $adaptor) = @_;
|
|
238
|
|
239 unless($name && $adaptor && ref $adaptor) {
|
|
240 throw('adaptor and name arguments are required');
|
|
241 }
|
|
242
|
|
243 Bio::EnsEMBL::Registry->add_db($self, $name, $adaptor);
|
|
244
|
|
245 }
|
|
246
|
|
247
|
|
248 =head2 remove_db_adaptor
|
|
249
|
|
250 Arg [1] : string $name
|
|
251 the name of the database to detach from this database.
|
|
252 Example : $lite_db = $db->remove_db_adaptor('lite');
|
|
253 Description: Detaches a database instance from this database and returns
|
|
254 it.
|
|
255 Returntype : none
|
|
256 Exceptions : none
|
|
257 Caller : ?
|
|
258 Status : At Risk
|
|
259 : mey get deprecated, use remove_db instead from the Registry
|
|
260
|
|
261 =cut
|
|
262
|
|
263 sub remove_db_adaptor {
|
|
264 my ($self, $name) = @_;
|
|
265
|
|
266 return Bio::EnsEMBL::Registry->remove_db($self, $name);
|
|
267 }
|
|
268
|
|
269
|
|
270 =head2 get_all_db_adaptors
|
|
271
|
|
272 Arg [1] : none
|
|
273 Example : @attached_dbs = values %{$db->get_all_db_adaptors()};
|
|
274 Description: returns all of the attached databases as
|
|
275 a hash reference of key/value pairs where the keys are
|
|
276 database names and the values are the attached databases
|
|
277 Returntype : hash reference with Bio::EnsEMBL::DBSQL::DBConnection values
|
|
278 Exceptions : none
|
|
279 Caller : Bio::EnsEMBL::DBSQL::ProxyAdaptor
|
|
280 Status : At Risk
|
|
281 : may get deprecated soon
|
|
282 : please use Bio::EnsEMBL::Registry->get_all_db_adaptors
|
|
283
|
|
284 =cut
|
|
285
|
|
286 sub get_all_db_adaptors {
|
|
287 my ($self) = @_;
|
|
288 return Bio::EnsEMBL::Registry->get_all_db_adaptors($self);
|
|
289 }
|
|
290
|
|
291
|
|
292
|
|
293 =head2 get_db_adaptor
|
|
294
|
|
295 Arg [1] : string $name
|
|
296 the name of the attached database to retrieve
|
|
297 Example : $lite_db = $db->get_db_adaptor('lite');
|
|
298 Description: returns an attached db adaptor of name $name or undef if
|
|
299 no such attached database exists
|
|
300 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
|
|
301 Exceptions : none
|
|
302 Caller : ?
|
|
303 Status : At Risk
|
|
304 : may get deprecated soon
|
|
305 : please use Bio::EnsEMBL::Registry->get_db_adaptors
|
|
306
|
|
307 =cut
|
|
308
|
|
309 sub get_db_adaptor {
|
|
310 my ($self, $name) = @_;
|
|
311
|
|
312 return Bio::EnsEMBL::Registry->get_db($self, $name);
|
|
313 }
|
|
314
|
|
315 =head2 get_available_adaptors
|
|
316
|
|
317 Example : my %pairs = %{$dba->get_available_adaptors()};
|
|
318 Description: gets a hash of the available adaptors
|
|
319 ReturnType : reference to a hash
|
|
320 Exceptions : none
|
|
321 Caller : Bio::EnsEMBL::Utils::ConfigRegistry
|
|
322 Status : Stable
|
|
323
|
|
324 =cut
|
|
325
|
|
326 sub get_available_adaptors {
|
|
327 my %pairs = (
|
|
328 # Firstly those that just have an adaptor named after there object
|
|
329 # in the main DBSQL directory.
|
|
330 map( { $_ => "Bio::EnsEMBL::DBSQL::${_}Adaptor" } qw(
|
|
331 Analysis ArchiveStableId Attribute
|
|
332 AssemblyExceptionFeature AssemblyMapper CoordSystem
|
|
333 CompressedSequence DBEntry DnaAlignFeature
|
|
334 DensityFeature DensityType Exon
|
|
335 Gene KaryotypeBand MiscSet
|
|
336 MiscFeature PredictionTranscript PredictionExon
|
|
337 ProteinFeature ProteinAlignFeature RepeatConsensus
|
|
338 RepeatFeature Sequence SeqRegionSynonym SimpleFeature
|
|
339 Slice SupportingFeature Transcript
|
|
340 TranscriptSupportingFeature Translation UnmappedObject
|
|
341 UnconventionalTranscriptAssociation AssemblySlice
|
|
342 SplicingEvent SplicingEventFeature SplicingTranscriptPair
|
|
343 Operon OperonTranscript
|
|
344 DataFile Assembly
|
|
345 IntronSupportingEvidence
|
|
346 ) ),
|
|
347 # Those whose adaptors are in Map::DBSQL
|
|
348 map( { $_ => "Bio::EnsEMBL::Map::DBSQL::${_}Adaptor" } qw(
|
|
349 Marker MarkerFeature QtlFeature Qtl Ditag DitagFeature
|
|
350 ) ),
|
|
351 # Finally the exceptions... those that have non-standard mapping
|
|
352 # between object / adaptor ....
|
|
353 # 'Blast' => 'Bio::EnsEMBL::External::BlastAdaptor',
|
|
354 'MetaCoordContainer' => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
|
|
355 'MetaContainer' => 'Bio::EnsEMBL::DBSQL::MetaContainer',
|
|
356 'SNP' => 'Bio::EnsEMBL::DBSQL::ProxySNPAdaptor',
|
|
357 );
|
|
358
|
|
359 return ( \%pairs );
|
|
360 } ## end sub get_available_adaptors
|
|
361
|
|
362 ###########################################################
|
|
363 #
|
|
364 # Support for DAS
|
|
365 #
|
|
366 ###########################################################
|
|
367
|
|
368 =head2 add_DASFeatureFactory
|
|
369
|
|
370 Arg [1] : Bio::EnsEMBL::ExternalFeatureFactory $value
|
|
371 Example : none
|
|
372 Description: Attaches a DAS Feature Factory to this method.
|
|
373 ExternalFeatureFactory objects are not really used right now.
|
|
374 They may be reintroduced or taken out completely. The fate
|
|
375 of this function is unknown (although it is presently needed).
|
|
376 Returntype : none
|
|
377 Exceptions : none
|
|
378 Caller : EnsWeb
|
|
379 Status : At Risk
|
|
380 : with the new web code this may not be needed/supported
|
|
381
|
|
382 =cut
|
|
383
|
|
384 sub add_DASFeatureFactory{
|
|
385
|
|
386 my ($self,$value) = @_;
|
|
387
|
|
388 push(@{$self->{'_das_ff'}},$value);
|
|
389 }
|
|
390
|
|
391
|
|
392 sub remove_all_DASFeatureFactories {
|
|
393 $_[0]->{'_das_ff'} = [];
|
|
394 }
|
|
395 =head2 _each_DASFeatureFactory
|
|
396
|
|
397 Args : none
|
|
398 Example : none
|
|
399 Description: Not sure if this is used, or if it should be removed. It
|
|
400 does not seem to be used at the moment
|
|
401 Returntype : Bio::EnsEMBL::ExternalFeatureFactory
|
|
402 Exceptions : none
|
|
403 Caller : ??
|
|
404 Status : At Risk
|
|
405 : with the new web code this may not be needed/supported
|
|
406
|
|
407 =cut
|
|
408
|
|
409 sub _each_DASFeatureFactory{
|
|
410 my ($self) = @_;
|
|
411
|
|
412 return @{$self->{'_das_ff'}||[]}
|
|
413 }
|
|
414
|
|
415
|
|
416 ##################################################################
|
|
417 #
|
|
418 # SUPPORT FOR EXTERNAL FEATURE FACTORIES
|
|
419 #
|
|
420 ##################################################################
|
|
421
|
|
422
|
|
423
|
|
424 =head2 add_ExternalFeatureAdaptor
|
|
425
|
|
426 Arg [1] : Bio::EnsEMBL::External::ExternalFeatureAdaptor
|
|
427 Example : $db_adaptor->add_ExternalFeatureAdaptor($xfa);
|
|
428 Description: Adds an external feature adaptor to this database adaptor.
|
|
429 Adding the external adaptor in this way allows external
|
|
430 features to be obtained from Slices and from RawContigs.
|
|
431
|
|
432 The external feature adaptor which is passed to this method
|
|
433 will have its db attribuite set to this DBAdaptor object via
|
|
434 the db accessor method.
|
|
435
|
|
436 ExternalFeatureAdaptors passed to this method are stored
|
|
437 internally in a hash keyed on the string returned by the
|
|
438 ExternalFeatureAdaptors track_name method.
|
|
439
|
|
440 If the track name method is not implemented then the
|
|
441 a default key named 'External features' is assigned. In the
|
|
442 event of duplicate key names, a number is appended to the
|
|
443 key name, and incremented for each subsequent adaptor with the
|
|
444 same track name. For example, if no track_names are specified
|
|
445 then the the external feature adaptors will be stored under the
|
|
446 keys 'External features', 'External features2'
|
|
447 'External features3' etc.
|
|
448 Returntype : none
|
|
449 Exceptions : none
|
|
450 Caller : general
|
|
451
|
|
452 =cut
|
|
453
|
|
454 sub add_ExternalFeatureAdaptor {
|
|
455 my ($self, $adaptor) = @_;
|
|
456
|
|
457 unless($adaptor && ref $adaptor &&
|
|
458 $adaptor->isa('Bio::EnsEMBL::External::ExternalFeatureAdaptor')) {
|
|
459 throw("[$adaptor] is not a " .
|
|
460 "Bio::EnsEMBL::External::ExternalFeatureAdaptor");
|
|
461 }
|
|
462
|
|
463 unless(exists $self->{'_xf_adaptors'}) {
|
|
464 $self->{'_xf_adaptors'} = {};
|
|
465 }
|
|
466
|
|
467 my $track_name = $adaptor->{'_track_name'};
|
|
468 if(!$track_name) {
|
|
469 $track_name = $adaptor->track_name();
|
|
470 }
|
|
471
|
|
472 #use a generic track name if one hasn't been defined
|
|
473 unless(defined $track_name) {
|
|
474 $track_name = "External features";
|
|
475 }
|
|
476
|
|
477 #if the track name exists add numbers to the end until a free name is found
|
|
478 if(exists $self->{'_xf_adaptors'}->{"$track_name"}) {
|
|
479 my $num = 2;
|
|
480 $num++ while(exists $self->{'_xf_adaptors'}->{"$track_name$num"});
|
|
481 $self->{'_xf_adaptors'}->{"$track_name$num"} = $adaptor;
|
|
482 } else {
|
|
483 $self->{'_xf_adaptors'}->{"$track_name"} = $adaptor;
|
|
484 }
|
|
485
|
|
486 $adaptor->ensembl_db($self);
|
|
487 }
|
|
488
|
|
489
|
|
490
|
|
491 =head2 get_ExternalFeatureAdaptors
|
|
492
|
|
493 Arg [1] : none
|
|
494 Example : @xfas = values %{$db_adaptor->get_ExternalFeatureAdaptors};
|
|
495 Description: Retrieves all of the ExternalFeatureAdaptors which have been
|
|
496 added to this DBAdaptor. The ExternalFeatureAdaptors are
|
|
497 returned in a reference to a hash keyed on the track names
|
|
498 of the external adaptors
|
|
499 Returntype : Reference to a hash of ExternalFeatureAdaptors keyed on
|
|
500 their track names.
|
|
501 Exceptions : none
|
|
502 Caller : general
|
|
503
|
|
504 =cut
|
|
505
|
|
506 sub get_ExternalFeatureAdaptors {
|
|
507 my $self = shift;
|
|
508
|
|
509 return $self->{'_xf_adaptors'};
|
|
510 }
|
|
511
|
|
512
|
|
513 =head2 add_ExternalFeatureFactory
|
|
514
|
|
515 Arg [1] : Bio::EnsEMBL::DB::ExternalFeatureFactoryI $value
|
|
516 Example : $db_adaptor->add_ExternalFeatureFactory
|
|
517 Description: It is recommended that add_ExternalFeatureAdaptor be used
|
|
518 instead. See documentation for
|
|
519 Bio::EnsEMBL::External::ExternalFeatureAdaptor
|
|
520
|
|
521 Adds an external feature factory to the core database
|
|
522 so that features from external sources can be displayed in
|
|
523 ensembl. This method is still available mainly for legacy
|
|
524 support for external EnsEMBL installations.
|
|
525 Returntype : none
|
|
526 Exceptions : none
|
|
527 Caller : external
|
|
528
|
|
529 =cut
|
|
530
|
|
531 sub add_ExternalFeatureFactory{
|
|
532 my ($self,$value) = @_;
|
|
533
|
|
534 $self->add_ExternalFeatureAdaptor($value);
|
|
535 }
|
|
536
|
|
537 #
|
|
538 # OVERWRITABLE STANDARD ADAPTORS
|
|
539 #
|
|
540
|
|
541 =head2 get_adaptor
|
|
542
|
|
543 Arg [1] : Canonical data type for which an adaptor is required.
|
|
544 Example : $db_adaptor->get_adaptor("Protein")
|
|
545 Description: Gets an adaptor object for a standard data type.
|
|
546 Returntype : Adaptor Object of arbitrary type or undef
|
|
547 Exceptions : none
|
|
548 Caller : external
|
|
549 Status : Medium Risk
|
|
550 : please use the Registry method, as at some time this
|
|
551 : may no longer be supprted.
|
|
552
|
|
553 =cut
|
|
554
|
|
555 sub get_adaptor {
|
|
556 my ($self, $canonical_name, @other_args) = @_;
|
|
557
|
|
558 return $reg->get_adaptor($self->species(),$self->group(),$canonical_name);
|
|
559 }
|
|
560
|
|
561
|
|
562
|
|
563 =head2 set_adaptor
|
|
564
|
|
565 Arg [1] : Canonical data type for new adaptor.
|
|
566 Arg [2] : Object defining the adaptor for arg1.
|
|
567 Example : $aa = Bio::EnsEMBL::DBSQL::GeneAdaptor->new($db_adaptor);
|
|
568 : $db_adaptor->set_adaptor("Gene", $ga)
|
|
569 Description: Stores the object which represents the adaptor for the
|
|
570 arg1 data type.
|
|
571 Returntype : none
|
|
572 Exceptions : none
|
|
573 Caller : external
|
|
574 Status : Medium Risk
|
|
575 : please use the Registry method, as at some time this
|
|
576 : may no longer be supprted.
|
|
577
|
|
578 =cut
|
|
579
|
|
580 sub set_adaptor {
|
|
581 my ($self, $canonical_name, $module) = @_;
|
|
582
|
|
583 $reg->add_adaptor($self->species(),$self->group(),$canonical_name,$module);
|
|
584
|
|
585 return $module;
|
|
586 }
|
|
587
|
|
588
|
|
589 #
|
|
590 # GENERIC FEATURE ADAPTORS
|
|
591 #
|
|
592
|
|
593 =head2 get_GenericFeatureAdaptors
|
|
594
|
|
595 Arg [1] : List of names of feature adaptors to get. If no
|
|
596 adaptor names are given, all the defined adaptors are returned.
|
|
597 Example : $db->get_GenericFeature("SomeFeature", "SomeOtherFeature")
|
|
598 Description: Returns a hash containing the named feature adaptors (or
|
|
599 all feature adaptors).
|
|
600 Returntype : reference to a Hash containing the named
|
|
601 feature adaptors (or all feature adaptors).
|
|
602 Exceptions : If any of the the named generic feature adaptors do not exist.
|
|
603 Caller : external
|
|
604
|
|
605 =cut
|
|
606
|
|
607 sub get_GenericFeatureAdaptors {
|
|
608
|
|
609 my ($self, @names) = @_;
|
|
610
|
|
611 my %adaptors = ();
|
|
612
|
|
613 if (!@names) {
|
|
614 %adaptors = %{$self->{'generic_feature_adaptors'}};
|
|
615 } else {
|
|
616 foreach my $name (@names) {
|
|
617 if (!exists($self->{'generic_feature_adaptors'}->{$name})) {
|
|
618 throw("No generic feature adaptor has been defined for $name" );
|
|
619 }
|
|
620
|
|
621
|
|
622 $adaptors{$name} = $self->{'generic_feature_adaptors'}->{$name};
|
|
623 }
|
|
624 }
|
|
625
|
|
626 return \%adaptors;
|
|
627 }
|
|
628
|
|
629
|
|
630 =head2 add_GenericFeatureAdaptor
|
|
631
|
|
632 Arg [1] : The name of the feature.
|
|
633 Arg [2] : Adaptor object for a generic feature.
|
|
634 Example : $db->add_GenericFeatureAdaptor("SomeFeature",
|
|
635 "Bio::EnsEMBL::DBSQL::SomeFeatureAdaptor")
|
|
636 Description: Stores the object which represents the adaptor for the
|
|
637 named feature type.
|
|
638 Returntype : none
|
|
639 Exceptions :
|
|
640 Caller : external
|
|
641
|
|
642 =cut
|
|
643
|
|
644 sub add_GenericFeatureAdaptor {
|
|
645 my ($self, $name, $adaptor_obj) = @_;
|
|
646
|
|
647 # check that $adaptor is an object that subclasses BaseFeatureAdaptor
|
|
648 if (!$adaptor_obj->isa("Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor")) {
|
|
649 throw("$name is a " . ref($adaptor_obj) . "which is not a " .
|
|
650 "subclass of Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor" );
|
|
651 }
|
|
652
|
|
653 $self->{'generic_feature_adaptors'}->{$name} = $adaptor_obj;
|
|
654 }
|
|
655
|
|
656 =head2 species
|
|
657
|
|
658 Arg [1] : (optional) string $arg
|
|
659 The new value of the species used by this DBAdaptor.
|
|
660 Example : $species = $dba->species()
|
|
661 Description: Getter/Setter for the species of to use for
|
|
662 this connection. There is currently no point in setting
|
|
663 this value after the connection has already been established
|
|
664 by the constructor.
|
|
665 Returntype : string
|
|
666 Exceptions : none
|
|
667 Caller : new
|
|
668 Status : Stable
|
|
669
|
|
670 =cut
|
|
671
|
|
672 sub species {
|
|
673 my ( $self, $arg ) = @_;
|
|
674
|
|
675 if ( defined($arg) ) {
|
|
676 $self->{_species} = $arg;
|
|
677 }
|
|
678
|
|
679 $self->{_species};
|
|
680 }
|
|
681
|
|
682 =head2 all_species
|
|
683
|
|
684 Args : NONE
|
|
685 Example : @all_species = @{$dba->all_species()};
|
|
686 Description: Returns the names of all species contained in the
|
|
687 database to which this DBAdaptor is connected.
|
|
688 Returntype : array reference
|
|
689 Exceptions : none
|
|
690 Caller : general
|
|
691 Status : Stable
|
|
692
|
|
693 =cut
|
|
694
|
|
695 sub all_species {
|
|
696 my ($self) = @_;
|
|
697
|
|
698 if ( !$self->is_multispecies() ) { return [ $self->species() ] }
|
|
699
|
|
700 if ( exists( $self->{'_all_species'} ) ) {
|
|
701 return $self->{'_all_species'};
|
|
702 }
|
|
703
|
|
704 my $statement =
|
|
705 "SELECT meta_value "
|
|
706 . "FROM meta "
|
|
707 . "WHERE meta_key = 'species.db_name'";
|
|
708
|
|
709 my $sth = $self->dbc()->db_handle()->prepare($statement);
|
|
710
|
|
711 $sth->execute();
|
|
712
|
|
713 my $species;
|
|
714 $sth->bind_columns( \$species );
|
|
715
|
|
716 my @all_species;
|
|
717 while ( $sth->fetch() ) { push( @all_species, $species ) }
|
|
718
|
|
719 $self->{'_all_species'} = \@all_species;
|
|
720
|
|
721 return $self->{'_all_species'};
|
|
722 } ## end sub all_species
|
|
723
|
|
724
|
|
725 =head2 is_multispecies
|
|
726
|
|
727 Arg [1] : (optional) boolean $arg
|
|
728 Example : if ($dba->is_multispecies()) { }
|
|
729 Description: Getter/Setter for the is_multispecies boolean of
|
|
730 to use for this connection. There is currently no
|
|
731 point in setting this value after the connection has
|
|
732 already been established by the constructor.
|
|
733 Returntype : boolean
|
|
734 Exceptions : none
|
|
735 Caller : new
|
|
736 Status : Stable
|
|
737
|
|
738 =cut
|
|
739
|
|
740 sub is_multispecies {
|
|
741 my ( $self, $arg ) = @_;
|
|
742
|
|
743 if ( defined($arg) ) {
|
|
744 $self->{_is_multispecies} = $arg;
|
|
745 }
|
|
746
|
|
747 return $self->{_is_multispecies};
|
|
748 }
|
|
749
|
|
750
|
|
751 =head2 species_id
|
|
752
|
|
753 Arg [1] : (optional) string $arg
|
|
754 The new value of the species_id used by this DBAdaptor
|
|
755 when dealing with multi-species databases.
|
|
756 Example : $species_id = $dba->species_id()
|
|
757 Description: Getter/Setter for the species_id of to use for this
|
|
758 connection. There is currently no point in setting
|
|
759 this value after the connection has already been
|
|
760 established by the constructor.
|
|
761 Returntype : string
|
|
762 Exceptions : none
|
|
763 Caller : new
|
|
764 Status : Stable
|
|
765
|
|
766 =cut
|
|
767
|
|
768 sub species_id {
|
|
769 my ( $self, $arg ) = @_;
|
|
770
|
|
771 if ( defined($arg) ) {
|
|
772 $self->{_species_id} = $arg;
|
|
773 }
|
|
774
|
|
775 return $self->{_species_id};
|
|
776 }
|
|
777
|
|
778
|
|
779 =head2 no_cache
|
|
780
|
|
781 Arg [1] : (optional) int $arg
|
|
782 The new value of the no cache attribute used by this DBAdaptor.
|
|
783 Example : $no_cache = $dba->no_cache();
|
|
784 Description: Getter/Setter for the no_cache to use for
|
|
785 this connection. There is currently no point in setting
|
|
786 this value after the connection has already been established
|
|
787 by the constructor.
|
|
788 Returntype : int
|
|
789 Exceptions : none
|
|
790 Caller : new
|
|
791 Status : Stable
|
|
792
|
|
793 =cut
|
|
794
|
|
795 sub no_cache {
|
|
796 my ($self, $arg ) = @_;
|
|
797
|
|
798 if ( defined $arg ){
|
|
799 if ($arg != 1 && $arg != 0){
|
|
800 throw("$arg is not allowed for this attribute. Only value 1|0 is allowed");
|
|
801 }
|
|
802 $self->{_no_cache} = $arg;
|
|
803 }
|
|
804 $self->{_no_cache};
|
|
805 }
|
|
806
|
|
807
|
|
808 =head2 group
|
|
809
|
|
810 Arg [1] : (optional) string $arg
|
|
811 The new value of the group used by this DBAdaptor.
|
|
812 Example : $group = $dba->group()
|
|
813 Description: Getter/Setter for the group of to use for
|
|
814 this connection. There is currently no point in setting
|
|
815 this value after the connection has already been established
|
|
816 by the constructor.
|
|
817 Returntype : string
|
|
818 Exceptions : none
|
|
819 Caller : new
|
|
820 Status : Stable
|
|
821
|
|
822 =cut
|
|
823
|
|
824 sub group {
|
|
825 my ($self, $arg ) = @_;
|
|
826 ( defined $arg ) &&
|
|
827 ( $self->{_group} = $arg );
|
|
828 $self->{_group};
|
|
829 }
|
|
830
|
|
831 =head2 get_SeqRegionCache
|
|
832
|
|
833 Arg [1] : none
|
|
834 Example : my $srcache = $dba->get_SeqRegionCache();
|
|
835 Description: Retrieves a seq_region cache for this database
|
|
836 Returntype : Bio::EnsEMBL::Utils::SeqRegionCache
|
|
837 Exceptions : none
|
|
838 Caller : SliceAdaptor, AssemblyMapperAdaptor
|
|
839 Status : Stable
|
|
840
|
|
841 =cut
|
|
842
|
|
843 sub get_SeqRegionCache {
|
|
844 my $self = shift;
|
|
845
|
|
846 # use the cache from the database where seq_regions are stored
|
|
847 if($self != $self->dnadb()) {
|
|
848 return $self->dnadb()->get_SeqRegionCache();
|
|
849 }
|
|
850
|
|
851 if(!$self->{'seq_region_cache'}) {
|
|
852 $self->{'seq_region_cache'} = Bio::EnsEMBL::Utils::SeqRegionCache->new();
|
|
853 }
|
|
854
|
|
855 return $self->{'seq_region_cache'};
|
|
856 }
|
|
857
|
|
858
|
|
859
|
|
860 #convenient method to retrieve the schema_build version for the database being used
|
|
861
|
|
862 sub _get_schema_build{
|
|
863 my ($self) = @_;
|
|
864
|
|
865 #avoided using dnadb by default to avoid obfuscation of behaviour
|
|
866
|
|
867 my @dbname = split/_/, $self->dbc->dbname();
|
|
868
|
|
869 #warn "dbname is $schema_build";
|
|
870
|
|
871 my $schema_build = pop @dbname;
|
|
872 $schema_build = pop(@dbname).'_'.$schema_build;
|
|
873
|
|
874
|
|
875 return $schema_build;
|
|
876 }
|
|
877
|
|
878
|
|
879 =head2 dnadb
|
|
880
|
|
881 Title : dnadb
|
|
882 Usage : my $dnadb = $db->dnadb();
|
|
883 Function: returns the database adaptor where the dna lives
|
|
884 Useful if you only want to keep one copy of the dna
|
|
885 on disk but have other databases with genes and features in
|
|
886 Returns : dna database adaptor
|
|
887 Args : Bio::EnsEMBL::DBSQL::BaseAdaptor
|
|
888 Status : Medium Risk.
|
|
889 : Use the Registry method add_DNAAdaptor/get_DNAAdaptor instead
|
|
890
|
|
891 =cut
|
|
892
|
|
893 sub dnadb {
|
|
894 my $self = shift;
|
|
895
|
|
896 if(@_) {
|
|
897 my $arg = shift;
|
|
898 $reg->add_DNAAdaptor($self->species(),$self->group(),$arg->species(),$arg->group());
|
|
899 }
|
|
900
|
|
901 # return $self->{'dnadb'} || $self;
|
|
902 return $reg->get_DNAAdaptor($self->species(),$self->group()) || $self;
|
|
903 }
|
|
904
|
|
905
|
|
906 use vars '$AUTOLOAD';
|
|
907
|
|
908 sub AUTOLOAD {
|
|
909 my ( $self, @args ) = @_;
|
|
910
|
|
911 my $type;
|
|
912 if ( $AUTOLOAD =~ /^.*::get_(\w+)Adaptor$/ ) {
|
|
913 $type = $1;
|
|
914 } elsif ( $AUTOLOAD =~ /^.*::get_(\w+)$/ ) {
|
|
915 $type = $1;
|
|
916 } else {
|
|
917 throw( sprintf( "Could not work out type for %s\n", $AUTOLOAD ) );
|
|
918 }
|
|
919
|
|
920 my $ret = $reg->get_adaptor( $self->species(), $self->group(), $type );
|
|
921
|
|
922 return $ret if $ret;
|
|
923
|
|
924 warning( sprintf(
|
|
925 "Could not find %s adaptor in the registry for %s %s\n",
|
|
926 $type, $self->species(), $self->group() ) );
|
|
927
|
|
928 throw( sprintf(
|
|
929 "Could not get adaptor %s for %s %s\n",
|
|
930 $type, $self->species(), $self->group() ) );
|
|
931
|
|
932 } ## end sub AUTOLOAD
|
|
933
|
|
934 sub DESTROY { } # required due to AUTOLOAD
|
|
935
|
|
936
|
|
937 #########################
|
|
938 # sub DEPRECATED METHODS
|
|
939 #########################
|
|
940 =head2 db
|
|
941
|
|
942 Description: DEPRECATED
|
|
943
|
|
944 =cut
|
|
945
|
|
946 sub db{
|
|
947 my ($self, $arg ) = @_;
|
|
948 deprecate("db Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
949 return $self->dbc($arg);
|
|
950 }
|
|
951
|
|
952
|
|
953 sub source { deprecate('Do not use - this method does nothing'); }
|
|
954
|
|
955
|
|
956 =head2 assembly_type
|
|
957
|
|
958 Description: DEPRECATED - Use CoordSystemAdaptor to obtain default coordinate
|
|
959 system instead.
|
|
960
|
|
961 =cut
|
|
962
|
|
963 sub assembly_type{
|
|
964 my $self = shift;
|
|
965
|
|
966 deprecate('Use CoordSystemAdaptor $csa->fetch_all->[0]->version() instead');
|
|
967
|
|
968 my $csa = $self->get_CoordSystemAdaptor();
|
|
969 my ($cs) = @{$csa->fetch_all()};
|
|
970 return ($cs) ? $cs->version() : undef;
|
|
971 }
|
|
972
|
|
973
|
|
974
|
|
975 =head2 list_supported_assemblies
|
|
976
|
|
977 Description: DEPRECATED - Use CoordSystemAdaptor to obtain list of top-level
|
|
978 coordinate systems instead
|
|
979
|
|
980 =cut
|
|
981
|
|
982 sub list_supported_assemblies {
|
|
983 my($self) = @_;
|
|
984 deprecate('Use CoordSystemAdaptor::fetch_all instead');
|
|
985
|
|
986 my $csa = $self->get_CoordSystemAdaptor();
|
|
987 my %versions;
|
|
988 foreach my $cs (@{$csa->fetch_all()}) {
|
|
989 $versions{$cs->version()} = 1;
|
|
990 }
|
|
991
|
|
992 return keys %versions;
|
|
993 }
|
|
994
|
|
995
|
|
996 sub prepare{
|
|
997 my ($self, @args) = @_;
|
|
998
|
|
999 deprecate("prepare Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1000 $self->dbc->prepare(@args);
|
|
1001 }
|
|
1002
|
|
1003 sub dbname{
|
|
1004 my ($self, @args) = @_;
|
|
1005
|
|
1006 deprecate("dbname Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1007 $self->dbc->dbname(@args);
|
|
1008 }
|
|
1009
|
|
1010 sub disconnect_when_inactive{
|
|
1011 my ($self, @args) = @_;
|
|
1012
|
|
1013 deprecate("disconnect_when_inactive Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1014 $self->dbc->disconnect_when_inactive(@args);
|
|
1015 }
|
|
1016
|
|
1017 sub reconnect_when_lost{
|
|
1018 my ($self, @args) = @_;
|
|
1019
|
|
1020 deprecate("reconnect_when_lost Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1021 $self->dbc->reconnect_when_lost(@args);
|
|
1022 }
|
|
1023
|
|
1024
|
|
1025 sub host{
|
|
1026 my ($self, @args) = @_;
|
|
1027
|
|
1028 deprecate("host Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1029 $self->dbc->host(@args);
|
|
1030 }
|
|
1031 sub username{
|
|
1032 my ($self, @args) = @_;
|
|
1033
|
|
1034 deprecate("username Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1035 $self->dbc->username(@args);
|
|
1036 }
|
|
1037 sub password{
|
|
1038 my ($self, @args) = @_;
|
|
1039
|
|
1040 deprecate("password Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1041 $self->dbc->password(@args);
|
|
1042 }
|
|
1043 sub driver{
|
|
1044 my ($self, @args) = @_;
|
|
1045
|
|
1046 deprecate("driver Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1047 $self->dbc->driver(@args);
|
|
1048 }
|
|
1049 sub port{
|
|
1050 my ($self, @args) = @_;
|
|
1051
|
|
1052 deprecate("port Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1053 $self->dbc->port(@args);
|
|
1054 }
|
|
1055
|
|
1056 sub db_handle{
|
|
1057 my ($self, @args) = @_;
|
|
1058
|
|
1059
|
|
1060 deprecate("db_handle Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
|
|
1061 $self->dbc->db_handle(@args);
|
|
1062 }
|
|
1063
|
|
1064
|
|
1065 1;
|