3 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
4 Copyright [2016-2024] EMBL-European Bioinformatics Institute
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
44 $gene_adaptor = $db->get_GeneAdaptor();
46 $gene = $gene_adaptor->fetch_by_stable_id($stable_id);
49 $db->get_SliceAdaptor()->fetch_by_chr_start_end(
'X', 1, 10000 );
53 Formerly
this class provided database connectivity and a means
54 to retrieve object adaptors. This class is now provided for
55 convenience and backwards compatibility, and delegates its connection
56 responsibilities to the
DBConnection class (no longer inherited from)
84 All sequence, assembly, contig information etc, will
85 be retrieved from this database instead.
87 Arg [-NO_CACHE]: (optional) int 1
88 This option will turn off caching for slice features,
89 so, every time a set of features is retrieved,
90 they will come from the database instead of the
91 cache. This option is only recommended for advanced
92 users, specially if you need to store and retrieve
93 features. It might reduce performance when querying
94 the database if not used properly. If in doubt, do
95 not use it or ask in the developer mailing list.
97 Arg [-ADD_ALIASES]: (optional) boolean
98 Used to automatically load aliases for this
99 species into the
Registry upon loading.
101 Arg [-ADD_SPECIES_ID]: (optional) boolean
102 Used to automatically load the species id
103 based on the species if none is defined.
105 Arg [..] : Other args are passed to superclass
116 -species => 'Homo_sapiens',
125 -species => 'staphylococcus_aureus',
128 -dbname => 'staphylococcus_collection_1_52_1a',
129 -multispecies_db => 1,
143 my ( $class, @args ) = @_;
145 my $self = bless {}, $class;
147 my ( $is_multispecies, $species, $species_id, $group, $con, $dnadb,
148 $no_cache, $dbname, $add_aliases, $add_species_id )
150 'MULTISPECIES_DB',
'SPECIES',
'SPECIES_ID',
'GROUP',
151 'DBCONN',
'DNADB',
'NO_CACHE',
'DBNAME',
152 'ADD_ALIASES',
'ADD_SPECIES_ID'
157 if ( defined($con) ) { $self->dbc($con) }
159 if(! defined $dbname) {
160 throw "-DBNAME is a required parameter when creating a DBAdaptor";
165 if ( defined($species) ) { $self->species($species); }
166 if ( defined($group) ) { $self->group($group) }
170 if (defined $species_id) {
171 $self->species_id($species_id);
172 } elsif ($add_species_id and defined $species) {
173 $self->find_and_add_species_id();
175 $self->species_id(1);
178 $self->is_multispecies( defined($is_multispecies)
179 && $is_multispecies == 1 );
181 if ( defined($dnadb) ) { $self->dnadb($dnadb) }
182 if ( $no_cache ) { $self->no_cache($no_cache) }
183 if ( $add_aliases ) { $self->find_and_add_aliases($add_aliases) }
190 Example : $dba->clear_caches();
191 Description : Loops through all linked adaptors and clears their
192 caches
if C<clear_cache()> is implemented. Not all caches
193 are cleared & the
DBAdaptor instance should be removed from
194 the registry to clear these remaining essential caches.
202 my $adaptors = $REGISTRY->get_all_adaptors(
203 $self->species(), $self->group());
204 foreach my $adaptor (@{$adaptors}) {
205 if($adaptor->can(
'clear_cache')) {
206 $adaptor->clear_cache();
212 =head2 find_and_add_aliases
215 Description : When executed we delegate to the find_and_add_aliases
217 database
's MetaContainer for species.alias entries
218 indicating alternative names for this species. This
219 is best executed on a core DBAdaptor instance.
225 sub find_and_add_aliases {
227 $REGISTRY->find_and_add_aliases(-ADAPTOR => $self);
231 =head2 find_and_add_species_id
239 sub find_and_add_species_id {
241 my $species = $self->species;
242 defined $species or throw "Undefined species";
244 my $dbc = $self->dbc;
245 my $sth = $dbc->prepare(sprintf "SELECT DISTINCT species_id FROM %s.meta " .
246 "WHERE meta_key='species.alias
' AND meta_value LIKE '%%s%
'",
247 $dbc->db_handle->quote_identifier($dbc->dbname), $species);
249 throw "Error querying for species_id: perhaps the DB doesn't have a meta table?\n
" .
250 "$DBI::err .... $DBI::errstr\n
";
253 $sth->bind_columns(\$species_id);
256 throw "Undefined species_id
" unless defined $species_id;
257 throw "Something wrong retrieving the species_id
"
258 unless $species_id >= 1;
260 $self->species_id($species_id);
266 Arg[1] : (optional) Bio::EnsEMBL::DBSQL::DBConnection
268 Example : $dbc = $dba->dbc();
269 Description: Getter/Setter for DBConnection.
270 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
271 Exceptions : throws if argument not a Bio::EnsEMBL::DBSQL::DBConnection
283 if(!$arg->isa('Bio::EnsEMBL::DBSQL::DBConnection')){
284 throw("$arg is no a DBConnection\n
");
287 $self->{_dbc} = $arg;
289 return $self->{_dbc};
292 =head2 add_db_adaptor
294 Arg [1] : string $name
295 the name of the database to attach to this database
296 Arg [2] : Bio::EnsEMBL::DBSQL::DBConnection
297 the db adaptor to attach to this database
298 Example : $db->add_db_adaptor('lite', $lite_db_adaptor);
299 Description: Attaches another database instance to this database so
300 that it can be used in instances where it is required.
309 my ($self, $name, $adaptor) = @_;
311 unless($name && $adaptor && ref $adaptor) {
312 throw('adaptor and name arguments are required');
315 $REGISTRY->add_db($self, $name, $adaptor);
320 =head2 remove_db_adaptor
322 Arg [1] : string $name
323 the name of the database to detach from this database.
324 Example : $lite_db = $db->remove_db_adaptor('lite');
325 Description: Detaches a database instance from this database and returns
334 sub remove_db_adaptor {
335 my ($self, $name) = @_;
336 return $REGISTRY->remove_db($self, $name);
340 =head2 get_all_db_adaptors
343 Example : @attached_dbs = values %{$db->get_all_db_adaptors()};
344 Description: returns all of the attached databases as
345 a hash reference of key/value pairs where the keys are
346 database names and the values are the attached databases
347 Returntype : hash reference with Bio::EnsEMBL::DBSQL::DBConnection values
349 Caller : Bio::EnsEMBL::DBSQL::ProxyAdaptor
351 : please use Bio::EnsEMBL::Registry->get_all_db_adaptors
355 sub get_all_db_adaptors {
357 return $REGISTRY->get_all_db_adaptors($self);
362 =head2 get_db_adaptor
364 Arg [1] : string $name
365 the name of the attached database to retrieve
366 Example : $lite_db = $db->get_db_adaptor('lite');
367 Description: returns an attached db adaptor of name $name or undef if
368 no such attached database exists
369 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
373 : please use Bio::EnsEMBL::Registry->get_db_adaptors
378 my ($self, $name) = @_;
380 return $REGISTRY->get_db($self, $name);
383 =head2 get_available_adaptors
385 Example : my %pairs = %{$dba->get_available_adaptors()};
386 Description: gets a hash of the available adaptors
387 ReturnType : reference to a hash
389 Caller : Bio::EnsEMBL::Utils::ConfigRegistry
394 sub get_available_adaptors {
396 # Firstly those that just have an adaptor named after there object
397 # in the main DBSQL directory.
398 AltAlleleGroup => 'Bio::EnsEMBL::DBSQL::AltAlleleGroupAdaptor',
399 Analysis => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
400 ArchiveStableId => 'Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor',
401 AssemblyExceptionFeature => 'Bio::EnsEMBL::DBSQL::AssemblyExceptionFeatureAdaptor',
402 AssemblyMapper => 'Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor',
403 AssemblySlice => 'Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor',
404 Attribute => 'Bio::EnsEMBL::DBSQL::AttributeAdaptor',
405 Biotype => 'Bio::EnsEMBL::DBSQL::BiotypeAdaptor',
406 CoordSystem => 'Bio::EnsEMBL::DBSQL::CoordSystemAdaptor',
407 DataFile => 'Bio::EnsEMBL::DBSQL::DataFileAdaptor',
408 DBEntry => 'Bio::EnsEMBL::DBSQL::DBEntryAdaptor',
409 DensityFeature => 'Bio::EnsEMBL::DBSQL::DensityFeatureAdaptor',
410 DensityType => 'Bio::EnsEMBL::DBSQL::DensityTypeAdaptor',
411 DnaAlignFeature => 'Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor',
412 Exon => 'Bio::EnsEMBL::DBSQL::ExonAdaptor',
413 Gene => 'Bio::EnsEMBL::DBSQL::GeneAdaptor',
414 IntronSupportingEvidence => 'Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor',
415 KaryotypeBand => 'Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor',
416 MiscFeature => 'Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor',
417 MiscSet => 'Bio::EnsEMBL::DBSQL::MiscSetAdaptor',
418 Operon => 'Bio::EnsEMBL::DBSQL::OperonAdaptor',
419 OperonTranscript => 'Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor',
420 PredictionExon => 'Bio::EnsEMBL::DBSQL::PredictionExonAdaptor',
421 PredictionTranscript => 'Bio::EnsEMBL::DBSQL::PredictionTranscriptAdaptor',
422 ProteinAlignFeature => 'Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor',
423 ProteinFeature => 'Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor',
424 RNAProduct => 'Bio::EnsEMBL::DBSQL::RNAProductAdaptor',
425 RepeatConsensus => 'Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor',
426 RepeatFeature => 'Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor',
427 SeqRegionSynonym => 'Bio::EnsEMBL::DBSQL::SeqRegionSynonymAdaptor',
428 Sequence => 'Bio::EnsEMBL::DBSQL::SequenceAdaptor',
429 SimpleFeature => 'Bio::EnsEMBL::DBSQL::SimpleFeatureAdaptor',
430 Slice => 'Bio::EnsEMBL::DBSQL::SliceAdaptor',
431 SupportingFeature => 'Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor',
432 Transcript => 'Bio::EnsEMBL::DBSQL::TranscriptAdaptor',
433 TranscriptSupportingFeature => 'Bio::EnsEMBL::DBSQL::TranscriptSupportingFeatureAdaptor',
434 Translation => 'Bio::EnsEMBL::DBSQL::TranslationAdaptor',
435 UnmappedObject => 'Bio::EnsEMBL::DBSQL::UnmappedObjectAdaptor',
437 # Those whose adaptors are in Map::DBSQL
438 Ditag => 'Bio::EnsEMBL::Map::DBSQL::DitagAdaptor',
439 DitagFeature => 'Bio::EnsEMBL::Map::DBSQL::DitagFeatureAdaptor',
440 Marker => 'Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor',
441 MarkerFeature => 'Bio::EnsEMBL::Map::DBSQL::MarkerFeatureAdaptor',
443 # Finally the exceptions... those that have non-standard mapping
444 # between object / adaptor ....
445 GenomeContainer => 'Bio::EnsEMBL::DBSQL::GenomeContainer',
446 MetaContainer => 'Bio::EnsEMBL::DBSQL::MetaContainer',
447 MetaCoordContainer => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
450 } ## end sub get_available_adaptors
452 ###########################################################
456 ###########################################################
458 =head2 add_DASFeatureFactory
460 Arg [1] : Bio::EnsEMBL::ExternalFeatureFactory $value
462 Description: Attaches a DAS Feature Factory to this method.
463 ExternalFeatureFactory objects are not really used right now.
464 They may be reintroduced or taken out completely. The fate
465 of this function is unknown (although it is presently needed).
470 : with the new web code this may not be needed/supported
474 sub add_DASFeatureFactory{
476 my ($self,$value) = @_;
478 push(@{$self->{'_das_ff'}},$value);
482 sub remove_all_DASFeatureFactories {
483 $_[0]->{'_das_ff'} = [];
485 =head2 _each_DASFeatureFactory
489 Description: Not sure if this is used, or if it should be removed. It
490 does not seem to be used at the moment
491 Returntype : Bio::EnsEMBL::ExternalFeatureFactory
495 : with the new web code this may not be needed/supported
499 sub _each_DASFeatureFactory{
502 return @{$self->{'_das_ff'}||[]}
506 ##################################################################
508 # SUPPORT FOR EXTERNAL FEATURE FACTORIES
510 ##################################################################
514 =head2 add_ExternalFeatureAdaptor
516 Arg [1] : Bio::EnsEMBL::External::ExternalFeatureAdaptor
517 Example : $db_adaptor->add_ExternalFeatureAdaptor($xfa);
518 Description: Adds an external feature adaptor to this database adaptor.
519 Adding the external adaptor in this way allows external
520 features to be obtained from Slices and from RawContigs.
522 The external feature adaptor which is passed to this method
523 will have its db attribute set to this DBAdaptor object via
524 the db accessor method.
526 ExternalFeatureAdaptors passed to this method are stored
527 internally in a hash keyed on the string returned by the
528 ExternalFeatureAdaptors track_name method.
530 If the track name method is not implemented then the
531 a default key named 'External features' is assigned. In the
532 event of duplicate key names, a number is appended to the
533 key name, and incremented for each subsequent adaptor with the
534 same track name. For example, if no track_names are specified
535 then the the external feature adaptors will be stored under the
536 keys 'External features', 'External features2'
537 'External features3' etc.
544 sub add_ExternalFeatureAdaptor {
545 my ($self, $adaptor) = @_;
547 unless($adaptor && ref $adaptor &&
548 $adaptor->isa('Bio::EnsEMBL::External::ExternalFeatureAdaptor')) {
549 throw("[$adaptor] is not a
" .
553 unless(exists $self->{'_xf_adaptors'}) {
554 $self->{'_xf_adaptors'} = {};
557 my $track_name = $adaptor->{'_track_name'};
559 $track_name = $adaptor->track_name();
562 #use a generic track name if one hasn't been defined
563 unless(defined $track_name) {
564 $track_name = "External features
";
567 #if the track name exists add numbers to the end until a free name is found
568 if(exists $self->{'_xf_adaptors'}->{"$track_name
"}) {
570 $num++ while(exists $self->{'_xf_adaptors'}->{"$track_name$num
"});
571 $self->{'_xf_adaptors'}->{"$track_name$num
"} = $adaptor;
573 $self->{'_xf_adaptors'}->{"$track_name
"} = $adaptor;
576 $adaptor->ensembl_db($self);
581 =head2 get_ExternalFeatureAdaptors
584 Example : @xfas = values %{$db_adaptor->get_ExternalFeatureAdaptors};
585 Description: Retrieves all of the ExternalFeatureAdaptors which have been
586 added to this DBAdaptor. The ExternalFeatureAdaptors are
587 returned in a reference to a hash keyed on the track names
588 of the external adaptors
589 Returntype : Reference to a hash of ExternalFeatureAdaptors keyed on
596 sub get_ExternalFeatureAdaptors {
599 return $self->{'_xf_adaptors'};
603 =head2 add_ExternalFeatureFactory
605 Arg [1] : Bio::EnsEMBL::DB::ExternalFeatureFactoryI $value
606 Example : $db_adaptor->add_ExternalFeatureFactory
607 Description: It is recommended that add_ExternalFeatureAdaptor be used
608 instead. See documentation for
609 Bio::EnsEMBL::External::ExternalFeatureAdaptor
611 Adds an external feature factory to the core database
612 so that features from external sources can be displayed in
613 ensembl. This method is still available mainly for legacy
614 support for external EnsEMBL installations.
621 sub add_ExternalFeatureFactory{
622 my ($self,$value) = @_;
624 $self->add_ExternalFeatureAdaptor($value);
628 # OVERWRITABLE STANDARD ADAPTORS
633 Arg [1] : Canonical data type for which an adaptor is required.
634 Example : $db_adaptor->get_adaptor("Protein
")
635 Description: Gets an adaptor object for a standard data type.
636 Returntype : Adaptor Object of arbitrary type or undef
640 : please use the Registry method, as at some time this
641 : may no longer be supported.
646 my ($self, $canonical_name, @other_args) = @_;
647 return $REGISTRY->get_adaptor($self->species(),$self->group(),$canonical_name);
654 Arg [1] : Canonical data type for new adaptor.
655 Arg [2] : Object defining the adaptor for arg1.
656 Example : $aa = Bio::EnsEMBL::DBSQL::GeneAdaptor->new($db_adaptor);
657 : $db_adaptor->set_adaptor("Gene
", $ga)
658 Description: Stores the object which represents the adaptor for the
664 : please use the Registry method, as at some time this
665 : may no longer be supported.
670 my ($self, $canonical_name, $module) = @_;
671 $REGISTRY->add_adaptor($self->species(),$self->group(),$canonical_name,$module);
677 # GENERIC FEATURE ADAPTORS
680 =head2 get_GenericFeatureAdaptors
682 Arg [1] : List of names of feature adaptors to get. If no
683 adaptor names are given, all the defined adaptors are returned.
684 Example : $db->get_GenericFeature("SomeFeature
", "SomeOtherFeature
")
685 Description: Returns a hash containing the named feature adaptors (or
686 all feature adaptors).
687 Returntype : reference to a Hash containing the named
688 feature adaptors (or all feature adaptors).
689 Exceptions : If any of the the named generic feature adaptors do not exist.
694 sub get_GenericFeatureAdaptors {
696 my ($self, @names) = @_;
701 %adaptors = %{$self->{'generic_feature_adaptors'}};
703 foreach my $name (@names) {
704 if (!exists($self->{'generic_feature_adaptors'}->{$name})) {
705 throw("No
generic feature adaptor has been defined
for $name
" );
709 $adaptors{$name} = $self->{'generic_feature_adaptors'}->{$name};
717 =head2 add_GenericFeatureAdaptor
719 Arg [1] : The name of the feature.
720 Arg [2] : Adaptor object for a generic feature.
721 Example : $db->add_GenericFeatureAdaptor("SomeFeature
",
722 "Bio::EnsEMBL::DBSQL::SomeFeatureAdaptor
")
723 Description: Stores the object which represents the adaptor for the
731 sub add_GenericFeatureAdaptor {
732 my ($self, $name, $adaptor_obj) = @_;
734 # check that $adaptor is an object that subclasses BaseFeatureAdaptor
736 throw("$name is a
" . ref($adaptor_obj) . "which is not a
" .
740 $self->{'generic_feature_adaptors'}->{$name} = $adaptor_obj;
745 Arg [1] : (optional) string $arg
746 The new value of the species used by this DBAdaptor.
747 Example : $species = $dba->species()
748 Description: Getter/Setter for the species of to use for
749 this connection. There is currently no point in setting
750 this value after the connection has already been established
760 my ( $self, $arg ) = @_;
762 if ( defined($arg) ) {
763 $self->{_species} = $arg;
772 Example : @all_species = @{$dba->all_species()};
773 Description: Returns the names of all species contained in the
774 database to which this DBAdaptor is connected.
775 Returntype : array reference
784 if ( !$self->is_multispecies() ) { return [ $self->species() ] }
785 return $self->{'_all_species'} if exists $self->{_all_species};
786 my $sql = "SELECT meta_value FROM meta WHERE meta_key =
'species.db_name'";
787 $self->{_all_species} = $self->dbc->sql_helper()->execute_simple(-SQL => $sql);
788 return $self->{'_all_species'};
789 } ## end sub all_species
792 =head2 is_multispecies
794 Arg [1] : (optional) boolean $arg
795 Example : if ($dba->is_multispecies()) { }
796 Description: Getter/Setter for the is_multispecies boolean of
797 to use for this connection. There is currently no
798 point in setting this value after the connection has
799 already been established by the constructor.
807 sub is_multispecies {
808 my ( $self, $arg ) = @_;
810 if ( defined($arg) ) {
811 $self->{_is_multispecies} = $arg;
814 return $self->{_is_multispecies};
820 Arg [1] : (optional) string $arg
821 The new value of the species_id used by this DBAdaptor
822 when dealing with multi-species databases.
823 Example : $species_id = $dba->species_id()
824 Description: Getter/Setter for the species_id of to use for this
825 connection. There is currently no point in setting
826 this value after the connection has already been
827 established by the constructor.
836 my ( $self, $arg ) = @_;
838 if ( defined($arg) ) {
839 $self->{_species_id} = $arg;
842 return $self->{_species_id};
848 Arg [1] : (optional) int $arg
849 The new value of the no cache attribute used by this DBAdaptor.
850 Example : $no_cache = $dba->no_cache();
851 Description: Getter/Setter for the no_cache to use for
852 this connection. There is currently no point in setting
853 this value after the connection has already been established
863 my ($self, $arg ) = @_;
866 if ($arg != 1 && $arg != 0){
867 throw("$arg is not allowed
for this attribute. Only value 1|0 is allowed
");
869 $self->{_no_cache} = $arg;
877 Arg [1] : (optional) string $arg
878 The new value of the group used by this DBAdaptor.
879 Example : $group = $dba->group()
880 Description: Getter/Setter for the group of to use for
881 this connection. There is currently no point in setting
882 this value after the connection has already been established
892 my ($self, $arg ) = @_;
894 ( $self->{_group} = $arg );
898 =head2 get_SeqRegionCache
901 Example : my $srcache = $dba->get_SeqRegionCache();
902 Description: Retrieves a seq_region cache for this database
903 Returntype : Bio::EnsEMBL::Utils::SeqRegionCache
905 Caller : SliceAdaptor, AssemblyMapperAdaptor
910 sub get_SeqRegionCache {
913 # use the cache from the database where seq_regions are stored
914 if($self != $self->dnadb()) {
915 return $self->dnadb()->get_SeqRegionCache();
918 if(!$self->{'seq_region_cache'}) {
919 $self->{'seq_region_cache'} = Bio::EnsEMBL::Utils::SeqRegionCache->new();
922 return $self->{'seq_region_cache'};
927 #convenient method to retrieve the schema_build version for the database being used
929 sub _get_schema_build{
932 #avoided using dnadb by default to avoid obfuscation of behaviour
934 my @dbname = split/_/, $self->dbc->dbname();
936 #warn "dbname is $schema_build
";
938 my $schema_build = pop @dbname;
939 $schema_build = pop(@dbname).'_'.$schema_build;
942 return $schema_build;
949 Usage : my $dnadb = $db->dnadb();
950 Function: returns the database adaptor where the dna lives
951 Useful if you only want to keep one copy of the dna
952 on disk but have other databases with genes and features in
953 Returns : dna database adaptor
954 Args : Bio::EnsEMBL::DBSQL::BaseAdaptor
955 Status : Medium Risk.
956 : Use the Registry method add_DNAAdaptor/get_DNAAdaptor instead
965 $REGISTRY->add_DNAAdaptor($self->species(),$self->group(),$arg->species(),$arg->group());
968 # return $self->{'dnadb'} || $self;
969 return $REGISTRY->get_DNAAdaptor($self->species(),$self->group()) || $self;
973 use vars '$AUTOLOAD';
976 my ( $self, @args ) = @_;
979 if ( $AUTOLOAD =~ /^.*::get_(\w+)Adaptor$/ ) {
981 } elsif ( $AUTOLOAD =~ /^.*::get_(\w+)$/ ) {
984 throw( sprintf( "Could not work out type
for %s\n
", $AUTOLOAD ) );
987 my $ret = $REGISTRY->get_adaptor( $self->species(), $self->group(), $type );
991 "Could not find %s adaptor in the registry
for %s %s\n
",
992 $type, $self->species(), $self->group() ) );
995 "Could not get adaptor %s
for %s %s\n
",
996 $type, $self->species(), $self->group() ) );
998 } ## end sub AUTOLOAD
1000 sub DESTROY { } # required due to AUTOLOAD
1004 Example : my $hash = $dba->to_hash();
1005 my $new_dba = $dba->new(%{$hash});
1006 Description: Provides a hash which is compatible with the
1007 parameters for DBAdaptor's new() method. This can be
1008 useful during serialisation but be aware that Registry
1018 my $hash = $self->dbc()->to_hash();
1019 $hash->{-SPECIES} = $self->species();
1020 $hash->{-GROUP} = $self->group();
1021 $hash->{-SPECIES_ID} = $self->species_id();
1022 $hash->{-MULTISPECIES_DB} = $self->is_multispecies();
1026 #########################
1027 # Switchable adaptor methods
1028 #########################
1030 =head2 switch_adaptor
1032 Arg [1] : String name of the adaptor type to switch out
1033 Arg [2] : Reference The switchable adaptor implementation
1034 Arg [3] : (optional) CodeRef Provide a subroutine reference as a callback. The
1035 adaptor will be switched before your codeblock is executed and
1036 the adaptor switched back to the original once your code has finished running
1037 Arg [4] : (optional) Boolean override any existing switchable adaptor
1038 Example : $dba->switch_adaptor("sequence
", $my_replacement_sequence_adaptor);
1039 $dba->switch_adaptor("sequence
", $my_other_replacement_sequence_adaptor, 1);
1040 $dba->switch_adaptor("sequence
", $my_replacement_sequence_adaptor, sub {
1041 #Make calls as normal without having to do manual cleanup
1044 Description : Provides a wrapper around the Registry add_switchable_adaptor() method
1045 defaulting both species and group to the current DBAdaptor. Callbacks are
1046 also available providing automatic resource cleanup.
1048 The method also remembers the last switch you did. It will not remember
1049 multiple switches though.
1050 Exceptions : Thrown if no switchable adaptor instance was given
1054 sub switch_adaptor {
1055 my ($self, $adaptor_name, $instance, $callback, $force) = @_;
1056 my ($species, $group) = ($self->species(), $self->group());
1057 $REGISTRY->add_switchable_adaptor($species, $group, $adaptor_name, $instance, $force);
1058 $self->{_last_switchable_adaptor} = $adaptor_name;
1059 if(check_ref($callback, 'CODE')) {
1060 #Scope guard will reset the adaptor once it falls out of scope. They
1061 #are implemented as callback DESTROYS so are neigh on impossible
1063 my $guard = scope_guard(sub { $REGISTRY->remove_switchable_adaptor($species, $group, $adaptor_name); } );
1069 =head2 has_switched_adaptor
1071 Arg [1] : String name of the adaptor type to switch back in
1072 Example : $dba->has_switchable_adaptor("sequence
"); #explicit switching back
1073 Returntype : Boolean indicating if the given adaptor is being actively switched
1074 Description : Provides a wrapper around the Registry has_switchable_adaptor() method
1075 defaulting both species and group to the current DBAdaptor. This will
1076 inform if the specified adaptor is being switched out
1081 sub has_switched_adaptor {
1082 my ($self, $adaptor_name) = @_;
1083 return $REGISTRY->has_switchable_adaptor($self->species, $self->group, $adaptor_name);
1086 =head2 revert_adaptor
1088 Arg [1] : (optional) String name of the adaptor type to switch back in
1089 Example : $dba->revert_adaptor(); #implicit switching back whatever was the last switch_adaptor() call
1090 $dba->revert_adaptor("sequence
"); #explicit switching back
1091 Returntype : The removed adaptor
1092 Description : Provides a wrapper around the Registry remove_switchable_adaptor() method
1093 defaulting both species and group to the current DBAdaptor. This will remove
1094 a switchable adaptor. You can also remove the last adaptor you switched
1095 in without having to specify any parameter.
1096 Exceptions : Thrown if no switchable adaptor name was given or could be found in the internal
1097 last adaptor variable
1101 sub revert_adaptor {
1102 my ($self, $adaptor_name) = @_;
1103 $adaptor_name ||= $self->{_last_switchable_adaptor};
1104 throw "Not given an adaptor name to remove and cannot find the name of the last switched adaptor
" if ! $adaptor_name;
1105 my $deleted_adaptor = $REGISTRY->remove_switchable_adaptor($self->species, $self->group, $adaptor_name);
1106 delete $self->{last_switch};
1107 return $deleted_adaptor;