3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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 INSTR(meta_value, ?) > 0",
247 $dbc->db_handle->quote_identifier($dbc->dbname));
248 $sth->bind_param(1, "$species");
250 throw "Error querying for species_id: perhaps the DB doesn't have a meta table?\n
" .
251 "$DBI::err .... $DBI::errstr\n
";
254 $sth->bind_columns(\$species_id);
257 throw "Undefined species_id
" unless defined $species_id;
258 throw "Something wrong retrieving the species_id
"
259 unless $species_id >= 1;
261 $self->species_id($species_id);
267 Arg[1] : (optional) Bio::EnsEMBL::DBSQL::DBConnection
269 Example : $dbc = $dba->dbc();
270 Description: Getter/Setter for DBConnection.
271 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
272 Exceptions : throws if argument not a Bio::EnsEMBL::DBSQL::DBConnection
284 if(!$arg->isa('Bio::EnsEMBL::DBSQL::DBConnection')){
285 throw("$arg is no a DBConnection\n
");
288 $self->{_dbc} = $arg;
290 return $self->{_dbc};
293 =head2 add_db_adaptor
295 Arg [1] : string $name
296 the name of the database to attach to this database
297 Arg [2] : Bio::EnsEMBL::DBSQL::DBConnection
298 the db adaptor to attach to this database
299 Example : $db->add_db_adaptor('lite', $lite_db_adaptor);
300 Description: Attaches another database instance to this database so
301 that it can be used in instances where it is required.
310 my ($self, $name, $adaptor) = @_;
312 unless($name && $adaptor && ref $adaptor) {
313 throw('adaptor and name arguments are required');
316 $REGISTRY->add_db($self, $name, $adaptor);
321 =head2 remove_db_adaptor
323 Arg [1] : string $name
324 the name of the database to detach from this database.
325 Example : $lite_db = $db->remove_db_adaptor('lite');
326 Description: Detaches a database instance from this database and returns
335 sub remove_db_adaptor {
336 my ($self, $name) = @_;
337 return $REGISTRY->remove_db($self, $name);
341 =head2 get_all_db_adaptors
344 Example : @attached_dbs = values %{$db->get_all_db_adaptors()};
345 Description: returns all of the attached databases as
346 a hash reference of key/value pairs where the keys are
347 database names and the values are the attached databases
348 Returntype : hash reference with Bio::EnsEMBL::DBSQL::DBConnection values
350 Caller : Bio::EnsEMBL::DBSQL::ProxyAdaptor
352 : please use Bio::EnsEMBL::Registry->get_all_db_adaptors
356 sub get_all_db_adaptors {
358 return $REGISTRY->get_all_db_adaptors($self);
363 =head2 get_db_adaptor
365 Arg [1] : string $name
366 the name of the attached database to retrieve
367 Example : $lite_db = $db->get_db_adaptor('lite');
368 Description: returns an attached db adaptor of name $name or undef if
369 no such attached database exists
370 Returntype : Bio::EnsEMBL::DBSQL::DBConnection
374 : please use Bio::EnsEMBL::Registry->get_db_adaptors
379 my ($self, $name) = @_;
381 return $REGISTRY->get_db($self, $name);
384 =head2 get_available_adaptors
386 Example : my %pairs = %{$dba->get_available_adaptors()};
387 Description: gets a hash of the available adaptors
388 ReturnType : reference to a hash
390 Caller : Bio::EnsEMBL::Utils::ConfigRegistry
395 sub get_available_adaptors {
397 # Firstly those that just have an adaptor named after there object
398 # in the main DBSQL directory.
399 AltAlleleGroup => 'Bio::EnsEMBL::DBSQL::AltAlleleGroupAdaptor',
400 Analysis => 'Bio::EnsEMBL::DBSQL::AnalysisAdaptor',
401 ArchiveStableId => 'Bio::EnsEMBL::DBSQL::ArchiveStableIdAdaptor',
402 AssemblyExceptionFeature => 'Bio::EnsEMBL::DBSQL::AssemblyExceptionFeatureAdaptor',
403 AssemblyMapper => 'Bio::EnsEMBL::DBSQL::AssemblyMapperAdaptor',
404 AssemblySlice => 'Bio::EnsEMBL::DBSQL::AssemblySliceAdaptor',
405 Attribute => 'Bio::EnsEMBL::DBSQL::AttributeAdaptor',
406 Biotype => 'Bio::EnsEMBL::DBSQL::BiotypeAdaptor',
407 CoordSystem => 'Bio::EnsEMBL::DBSQL::CoordSystemAdaptor',
408 DataFile => 'Bio::EnsEMBL::DBSQL::DataFileAdaptor',
409 DBEntry => 'Bio::EnsEMBL::DBSQL::DBEntryAdaptor',
410 DensityFeature => 'Bio::EnsEMBL::DBSQL::DensityFeatureAdaptor',
411 DensityType => 'Bio::EnsEMBL::DBSQL::DensityTypeAdaptor',
412 DnaAlignFeature => 'Bio::EnsEMBL::DBSQL::DnaAlignFeatureAdaptor',
413 Exon => 'Bio::EnsEMBL::DBSQL::ExonAdaptor',
414 Gene => 'Bio::EnsEMBL::DBSQL::GeneAdaptor',
415 IntronSupportingEvidence => 'Bio::EnsEMBL::DBSQL::IntronSupportingEvidenceAdaptor',
416 KaryotypeBand => 'Bio::EnsEMBL::DBSQL::KaryotypeBandAdaptor',
417 MiscFeature => 'Bio::EnsEMBL::DBSQL::MiscFeatureAdaptor',
418 MiscSet => 'Bio::EnsEMBL::DBSQL::MiscSetAdaptor',
419 Operon => 'Bio::EnsEMBL::DBSQL::OperonAdaptor',
420 OperonTranscript => 'Bio::EnsEMBL::DBSQL::OperonTranscriptAdaptor',
421 PredictionExon => 'Bio::EnsEMBL::DBSQL::PredictionExonAdaptor',
422 PredictionTranscript => 'Bio::EnsEMBL::DBSQL::PredictionTranscriptAdaptor',
423 ProteinAlignFeature => 'Bio::EnsEMBL::DBSQL::ProteinAlignFeatureAdaptor',
424 ProteinFeature => 'Bio::EnsEMBL::DBSQL::ProteinFeatureAdaptor',
425 RNAProduct => 'Bio::EnsEMBL::DBSQL::RNAProductAdaptor',
426 RepeatConsensus => 'Bio::EnsEMBL::DBSQL::RepeatConsensusAdaptor',
427 RepeatFeature => 'Bio::EnsEMBL::DBSQL::RepeatFeatureAdaptor',
428 SeqRegionSynonym => 'Bio::EnsEMBL::DBSQL::SeqRegionSynonymAdaptor',
429 Sequence => 'Bio::EnsEMBL::DBSQL::SequenceAdaptor',
430 SimpleFeature => 'Bio::EnsEMBL::DBSQL::SimpleFeatureAdaptor',
431 Slice => 'Bio::EnsEMBL::DBSQL::SliceAdaptor',
432 SupportingFeature => 'Bio::EnsEMBL::DBSQL::SupportingFeatureAdaptor',
433 Transcript => 'Bio::EnsEMBL::DBSQL::TranscriptAdaptor',
434 TranscriptSupportingFeature => 'Bio::EnsEMBL::DBSQL::TranscriptSupportingFeatureAdaptor',
435 Translation => 'Bio::EnsEMBL::DBSQL::TranslationAdaptor',
436 UnmappedObject => 'Bio::EnsEMBL::DBSQL::UnmappedObjectAdaptor',
438 # Those whose adaptors are in Map::DBSQL
439 Ditag => 'Bio::EnsEMBL::Map::DBSQL::DitagAdaptor',
440 DitagFeature => 'Bio::EnsEMBL::Map::DBSQL::DitagFeatureAdaptor',
441 Marker => 'Bio::EnsEMBL::Map::DBSQL::MarkerAdaptor',
442 MarkerFeature => 'Bio::EnsEMBL::Map::DBSQL::MarkerFeatureAdaptor',
444 # Finally the exceptions... those that have non-standard mapping
445 # between object / adaptor ....
446 GenomeContainer => 'Bio::EnsEMBL::DBSQL::GenomeContainer',
447 MetaContainer => 'Bio::EnsEMBL::DBSQL::MetaContainer',
448 MetaCoordContainer => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
451 } ## end sub get_available_adaptors
453 ###########################################################
457 ###########################################################
459 =head2 add_DASFeatureFactory
461 Arg [1] : Bio::EnsEMBL::ExternalFeatureFactory $value
463 Description: Attaches a DAS Feature Factory to this method.
464 ExternalFeatureFactory objects are not really used right now.
465 They may be reintroduced or taken out completely. The fate
466 of this function is unknown (although it is presently needed).
471 : with the new web code this may not be needed/supported
475 sub add_DASFeatureFactory{
477 my ($self,$value) = @_;
479 push(@{$self->{'_das_ff'}},$value);
483 sub remove_all_DASFeatureFactories {
484 $_[0]->{'_das_ff'} = [];
486 =head2 _each_DASFeatureFactory
490 Description: Not sure if this is used, or if it should be removed. It
491 does not seem to be used at the moment
492 Returntype : Bio::EnsEMBL::ExternalFeatureFactory
496 : with the new web code this may not be needed/supported
500 sub _each_DASFeatureFactory{
503 return @{$self->{'_das_ff'}||[]}
507 ##################################################################
509 # SUPPORT FOR EXTERNAL FEATURE FACTORIES
511 ##################################################################
515 =head2 add_ExternalFeatureAdaptor
517 Arg [1] : Bio::EnsEMBL::External::ExternalFeatureAdaptor
518 Example : $db_adaptor->add_ExternalFeatureAdaptor($xfa);
519 Description: Adds an external feature adaptor to this database adaptor.
520 Adding the external adaptor in this way allows external
521 features to be obtained from Slices and from RawContigs.
523 The external feature adaptor which is passed to this method
524 will have its db attribute set to this DBAdaptor object via
525 the db accessor method.
527 ExternalFeatureAdaptors passed to this method are stored
528 internally in a hash keyed on the string returned by the
529 ExternalFeatureAdaptors track_name method.
531 If the track name method is not implemented then the
532 a default key named 'External features' is assigned. In the
533 event of duplicate key names, a number is appended to the
534 key name, and incremented for each subsequent adaptor with the
535 same track name. For example, if no track_names are specified
536 then the the external feature adaptors will be stored under the
537 keys 'External features', 'External features2'
538 'External features3' etc.
545 sub add_ExternalFeatureAdaptor {
546 my ($self, $adaptor) = @_;
548 unless($adaptor && ref $adaptor &&
549 $adaptor->isa('Bio::EnsEMBL::External::ExternalFeatureAdaptor')) {
550 throw("[$adaptor] is not a
" .
554 unless(exists $self->{'_xf_adaptors'}) {
555 $self->{'_xf_adaptors'} = {};
558 my $track_name = $adaptor->{'_track_name'};
560 $track_name = $adaptor->track_name();
563 #use a generic track name if one hasn't been defined
564 unless(defined $track_name) {
565 $track_name = "External features
";
568 #if the track name exists add numbers to the end until a free name is found
569 if(exists $self->{'_xf_adaptors'}->{"$track_name
"}) {
571 $num++ while(exists $self->{'_xf_adaptors'}->{"$track_name$num
"});
572 $self->{'_xf_adaptors'}->{"$track_name$num
"} = $adaptor;
574 $self->{'_xf_adaptors'}->{"$track_name
"} = $adaptor;
577 $adaptor->ensembl_db($self);
582 =head2 get_ExternalFeatureAdaptors
585 Example : @xfas = values %{$db_adaptor->get_ExternalFeatureAdaptors};
586 Description: Retrieves all of the ExternalFeatureAdaptors which have been
587 added to this DBAdaptor. The ExternalFeatureAdaptors are
588 returned in a reference to a hash keyed on the track names
589 of the external adaptors
590 Returntype : Reference to a hash of ExternalFeatureAdaptors keyed on
597 sub get_ExternalFeatureAdaptors {
600 return $self->{'_xf_adaptors'};
604 =head2 add_ExternalFeatureFactory
606 Arg [1] : Bio::EnsEMBL::DB::ExternalFeatureFactoryI $value
607 Example : $db_adaptor->add_ExternalFeatureFactory
608 Description: It is recommended that add_ExternalFeatureAdaptor be used
609 instead. See documentation for
610 Bio::EnsEMBL::External::ExternalFeatureAdaptor
612 Adds an external feature factory to the core database
613 so that features from external sources can be displayed in
614 ensembl. This method is still available mainly for legacy
615 support for external EnsEMBL installations.
622 sub add_ExternalFeatureFactory{
623 my ($self,$value) = @_;
625 $self->add_ExternalFeatureAdaptor($value);
629 # OVERWRITABLE STANDARD ADAPTORS
634 Arg [1] : Canonical data type for which an adaptor is required.
635 Example : $db_adaptor->get_adaptor("Protein
")
636 Description: Gets an adaptor object for a standard data type.
637 Returntype : Adaptor Object of arbitrary type or undef
641 : please use the Registry method, as at some time this
642 : may no longer be supported.
647 my ($self, $canonical_name, @other_args) = @_;
648 return $REGISTRY->get_adaptor($self->species(),$self->group(),$canonical_name);
655 Arg [1] : Canonical data type for new adaptor.
656 Arg [2] : Object defining the adaptor for arg1.
657 Example : $aa = Bio::EnsEMBL::DBSQL::GeneAdaptor->new($db_adaptor);
658 : $db_adaptor->set_adaptor("Gene
", $ga)
659 Description: Stores the object which represents the adaptor for the
665 : please use the Registry method, as at some time this
666 : may no longer be supported.
671 my ($self, $canonical_name, $module) = @_;
672 $REGISTRY->add_adaptor($self->species(),$self->group(),$canonical_name,$module);
678 # GENERIC FEATURE ADAPTORS
681 =head2 get_GenericFeatureAdaptors
683 Arg [1] : List of names of feature adaptors to get. If no
684 adaptor names are given, all the defined adaptors are returned.
685 Example : $db->get_GenericFeature("SomeFeature
", "SomeOtherFeature
")
686 Description: Returns a hash containing the named feature adaptors (or
687 all feature adaptors).
688 Returntype : reference to a Hash containing the named
689 feature adaptors (or all feature adaptors).
690 Exceptions : If any of the the named generic feature adaptors do not exist.
695 sub get_GenericFeatureAdaptors {
697 my ($self, @names) = @_;
702 %adaptors = %{$self->{'generic_feature_adaptors'}};
704 foreach my $name (@names) {
705 if (!exists($self->{'generic_feature_adaptors'}->{$name})) {
706 throw("No
generic feature adaptor has been defined
for $name
" );
710 $adaptors{$name} = $self->{'generic_feature_adaptors'}->{$name};
718 =head2 add_GenericFeatureAdaptor
720 Arg [1] : The name of the feature.
721 Arg [2] : Adaptor object for a generic feature.
722 Example : $db->add_GenericFeatureAdaptor("SomeFeature
",
723 "Bio::EnsEMBL::DBSQL::SomeFeatureAdaptor
")
724 Description: Stores the object which represents the adaptor for the
732 sub add_GenericFeatureAdaptor {
733 my ($self, $name, $adaptor_obj) = @_;
735 # check that $adaptor is an object that subclasses BaseFeatureAdaptor
737 throw("$name is a
" . ref($adaptor_obj) . "which is not a
" .
741 $self->{'generic_feature_adaptors'}->{$name} = $adaptor_obj;
746 Arg [1] : (optional) string $arg
747 The new value of the species used by this DBAdaptor.
748 Example : $species = $dba->species()
749 Description: Getter/Setter for the species of to use for
750 this connection. There is currently no point in setting
751 this value after the connection has already been established
761 my ( $self, $arg ) = @_;
763 if ( defined($arg) ) {
764 $self->{_species} = $arg;
773 Example : @all_species = @{$dba->all_species()};
774 Description: Returns the names of all species contained in the
775 database to which this DBAdaptor is connected.
776 Returntype : array reference
785 if ( !$self->is_multispecies() ) { return [ $self->species() ] }
786 return $self->{'_all_species'} if exists $self->{_all_species};
787 my $sql = "SELECT meta_value FROM meta WHERE meta_key =
'species.db_name'";
788 $self->{_all_species} = $self->dbc->sql_helper()->execute_simple(-SQL => $sql);
789 return $self->{'_all_species'};
790 } ## end sub all_species
793 =head2 is_multispecies
795 Arg [1] : (optional) boolean $arg
796 Example : if ($dba->is_multispecies()) { }
797 Description: Getter/Setter for the is_multispecies boolean of
798 to use for this connection. There is currently no
799 point in setting this value after the connection has
800 already been established by the constructor.
808 sub is_multispecies {
809 my ( $self, $arg ) = @_;
811 if ( defined($arg) ) {
812 $self->{_is_multispecies} = $arg;
815 return $self->{_is_multispecies};
821 Arg [1] : (optional) string $arg
822 The new value of the species_id used by this DBAdaptor
823 when dealing with multi-species databases.
824 Example : $species_id = $dba->species_id()
825 Description: Getter/Setter for the species_id of to use for this
826 connection. There is currently no point in setting
827 this value after the connection has already been
828 established by the constructor.
837 my ( $self, $arg ) = @_;
839 if ( defined($arg) ) {
840 $self->{_species_id} = $arg;
843 return $self->{_species_id};
849 Arg [1] : (optional) int $arg
850 The new value of the no cache attribute used by this DBAdaptor.
851 Example : $no_cache = $dba->no_cache();
852 Description: Getter/Setter for the no_cache to use for
853 this connection. There is currently no point in setting
854 this value after the connection has already been established
864 my ($self, $arg ) = @_;
867 if ($arg != 1 && $arg != 0){
868 throw("$arg is not allowed
for this attribute. Only value 1|0 is allowed
");
870 $self->{_no_cache} = $arg;
878 Arg [1] : (optional) string $arg
879 The new value of the group used by this DBAdaptor.
880 Example : $group = $dba->group()
881 Description: Getter/Setter for the group of to use for
882 this connection. There is currently no point in setting
883 this value after the connection has already been established
893 my ($self, $arg ) = @_;
895 ( $self->{_group} = $arg );
899 =head2 get_SeqRegionCache
902 Example : my $srcache = $dba->get_SeqRegionCache();
903 Description: Retrieves a seq_region cache for this database
904 Returntype : Bio::EnsEMBL::Utils::SeqRegionCache
906 Caller : SliceAdaptor, AssemblyMapperAdaptor
911 sub get_SeqRegionCache {
914 # use the cache from the database where seq_regions are stored
915 if($self != $self->dnadb()) {
916 return $self->dnadb()->get_SeqRegionCache();
919 if(!$self->{'seq_region_cache'}) {
920 $self->{'seq_region_cache'} = Bio::EnsEMBL::Utils::SeqRegionCache->new();
923 return $self->{'seq_region_cache'};
928 #convenient method to retrieve the schema_build version for the database being used
930 sub _get_schema_build{
933 #avoided using dnadb by default to avoid obfuscation of behaviour
935 my @dbname = split/_/, $self->dbc->dbname();
937 #warn "dbname is $schema_build
";
939 my $schema_build = pop @dbname;
940 $schema_build = pop(@dbname).'_'.$schema_build;
943 return $schema_build;
950 Usage : my $dnadb = $db->dnadb();
951 Function: returns the database adaptor where the dna lives
952 Useful if you only want to keep one copy of the dna
953 on disk but have other databases with genes and features in
954 Returns : dna database adaptor
955 Args : Bio::EnsEMBL::DBSQL::BaseAdaptor
956 Status : Medium Risk.
957 : Use the Registry method add_DNAAdaptor/get_DNAAdaptor instead
966 $REGISTRY->add_DNAAdaptor($self->species(),$self->group(),$arg->species(),$arg->group());
969 # return $self->{'dnadb'} || $self;
970 return $REGISTRY->get_DNAAdaptor($self->species(),$self->group()) || $self;
974 use vars '$AUTOLOAD';
977 my ( $self, @args ) = @_;
980 if ( $AUTOLOAD =~ /^.*::get_(\w+)Adaptor$/ ) {
982 } elsif ( $AUTOLOAD =~ /^.*::get_(\w+)$/ ) {
985 throw( sprintf( "Could not work out type
for %s\n
", $AUTOLOAD ) );
988 my $ret = $REGISTRY->get_adaptor( $self->species(), $self->group(), $type );
992 "Could not find %s adaptor in the registry
for %s %s\n
",
993 $type, $self->species(), $self->group() ) );
996 "Could not get adaptor %s
for %s %s\n
",
997 $type, $self->species(), $self->group() ) );
999 } ## end sub AUTOLOAD
1001 sub DESTROY { } # required due to AUTOLOAD
1005 Example : my $hash = $dba->to_hash();
1006 my $new_dba = $dba->new(%{$hash});
1007 Description: Provides a hash which is compatible with the
1008 parameters for DBAdaptor's new() method. This can be
1009 useful during serialisation but be aware that Registry
1019 my $hash = $self->dbc()->to_hash();
1020 $hash->{-SPECIES} = $self->species();
1021 $hash->{-GROUP} = $self->group();
1022 $hash->{-SPECIES_ID} = $self->species_id();
1023 $hash->{-MULTISPECIES_DB} = $self->is_multispecies();
1027 #########################
1028 # Switchable adaptor methods
1029 #########################
1031 =head2 switch_adaptor
1033 Arg [1] : String name of the adaptor type to switch out
1034 Arg [2] : Reference The switchable adaptor implementation
1035 Arg [3] : (optional) CodeRef Provide a subroutine reference as a callback. The
1036 adaptor will be switched before your codeblock is executed and
1037 the adaptor switched back to the original once your code has finished running
1038 Arg [4] : (optional) Boolean override any existing switchable adaptor
1039 Example : $dba->switch_adaptor("sequence
", $my_replacement_sequence_adaptor);
1040 $dba->switch_adaptor("sequence
", $my_other_replacement_sequence_adaptor, 1);
1041 $dba->switch_adaptor("sequence
", $my_replacement_sequence_adaptor, sub {
1042 #Make calls as normal without having to do manual cleanup
1045 Description : Provides a wrapper around the Registry add_switchable_adaptor() method
1046 defaulting both species and group to the current DBAdaptor. Callbacks are
1047 also available providing automatic resource cleanup.
1049 The method also remembers the last switch you did. It will not remember
1050 multiple switches though.
1051 Exceptions : Thrown if no switchable adaptor instance was given
1055 sub switch_adaptor {
1056 my ($self, $adaptor_name, $instance, $callback, $force) = @_;
1057 my ($species, $group) = ($self->species(), $self->group());
1058 $REGISTRY->add_switchable_adaptor($species, $group, $adaptor_name, $instance, $force);
1059 $self->{_last_switchable_adaptor} = $adaptor_name;
1060 if(check_ref($callback, 'CODE')) {
1061 #Scope guard will reset the adaptor once it falls out of scope. They
1062 #are implemented as callback DESTROYS so are neigh on impossible
1064 my $guard = scope_guard(sub { $REGISTRY->remove_switchable_adaptor($species, $group, $adaptor_name); } );
1070 =head2 has_switched_adaptor
1072 Arg [1] : String name of the adaptor type to switch back in
1073 Example : $dba->has_switchable_adaptor("sequence
"); #explicit switching back
1074 Returntype : Boolean indicating if the given adaptor is being actively switched
1075 Description : Provides a wrapper around the Registry has_switchable_adaptor() method
1076 defaulting both species and group to the current DBAdaptor. This will
1077 inform if the specified adaptor is being switched out
1082 sub has_switched_adaptor {
1083 my ($self, $adaptor_name) = @_;
1084 return $REGISTRY->has_switchable_adaptor($self->species, $self->group, $adaptor_name);
1087 =head2 revert_adaptor
1089 Arg [1] : (optional) String name of the adaptor type to switch back in
1090 Example : $dba->revert_adaptor(); #implicit switching back whatever was the last switch_adaptor() call
1091 $dba->revert_adaptor("sequence
"); #explicit switching back
1092 Returntype : The removed adaptor
1093 Description : Provides a wrapper around the Registry remove_switchable_adaptor() method
1094 defaulting both species and group to the current DBAdaptor. This will remove
1095 a switchable adaptor. You can also remove the last adaptor you switched
1096 in without having to specify any parameter.
1097 Exceptions : Thrown if no switchable adaptor name was given or could be found in the internal
1098 last adaptor variable
1102 sub revert_adaptor {
1103 my ($self, $adaptor_name) = @_;
1104 $adaptor_name ||= $self->{_last_switchable_adaptor};
1105 throw "Not given an adaptor name to remove and cannot find the name of the last switched adaptor
" if ! $adaptor_name;
1106 my $deleted_adaptor = $REGISTRY->remove_switchable_adaptor($self->species, $self->group, $adaptor_name);
1107 delete $self->{last_switch};
1108 return $deleted_adaptor;