Archive Ensembl HomeArchive Ensembl Home
DBAdaptor.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::DBSQL::DBAdaptor
00024 
00025 =head1 SYNOPSIS
00026 
00027   $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
00028     -user   => 'root',
00029     -dbname => 'pog',
00030     -host   => 'caldy',
00031     -driver => 'mysql'
00032   );
00033 
00034   $gene_adaptor = $db->get_GeneAdaptor();
00035 
00036   $gene = $gene_adaptor->fetch_by_stable_id($stable_id);
00037 
00038   $slice =
00039     $db->get_SliceAdaptor()->fetch_by_chr_start_end( 'X', 1, 10000 );
00040 
00041 =head1 DESCRIPTION
00042 
00043 Formerly this class provided database connectivity and a means
00044 to retrieve object adaptors.  This class is now provided for
00045 convenience and backwards compatibility, and delegates its connection
00046 responsibilities to the DBConnection class (no longer inherited from)
00047 and its object adaptor retrieval to the static Bio::EnsEMBL::Registry.
00048 
00049 Please use Bio::EnsEMBL::Registry to retrieve object adaptors.
00050 
00051 =head1 METHODS
00052 
00053 =cut
00054 
00055 package Bio::EnsEMBL::DBSQL::DBAdaptor;
00056 
00057 use strict;
00058 
00059 use Bio::EnsEMBL::DBSQL::DBConnection;
00060 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
00061 use Bio::EnsEMBL::Utils::SeqRegionCache;
00062 use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
00063 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00064 use Bio::EnsEMBL::Registry;
00065 use Bio::EnsEMBL::Utils::ConfigRegistry;
00066 
00067 my $reg = "Bio::EnsEMBL::Registry";
00068 
00069 =head2 new
00070 
00071   Arg [-DNADB]: (optional) Bio::EnsEMBL::DBSQL::DBAdaptor DNADB 
00072                All sequence, assembly, contig information etc, will
00073                be retrieved from this database instead.
00074 
00075   Arg [-NO_CACHE]: (optional) int 1
00076                This option will turn off caching for slice features,
00077                so, every time a set of features is retrieved,
00078                they will come from the database instead of the
00079                cache.  This option is only recommended for advanced
00080                users, specially if you need to store and retrieve
00081                features.  It might reduce performance when querying
00082                the database if not used properly.  If in doubt, do
00083                not use it or ask in the developer mailing list.
00084 
00085   Arg [..]   : Other args are passed to superclass
00086                Bio::EnsEMBL::DBSQL::DBConnection
00087 
00088   Example    : $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
00089                 -user   => 'root',
00090                 -dbname => 'pog',
00091                 -host   => 'caldy',
00092                 -driver => 'mysql'
00093               );
00094 
00095   Example2   : $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
00096                 -species => 'Homo_sapiens',
00097                 -group   => 'core',
00098                 -user    => 'root',
00099                 -dbname  => 'pog',
00100                 -host    => 'caldy',
00101                 -driver  => 'mysql'
00102               );
00103 
00104   Example3   : $db = new Bio::EnsEMBL::DBSQL::DBAdaptor(
00105                 -species         => 'staphylococcus_aureus',
00106                 -group           => 'core',
00107                 -user            => 'root',
00108                 -dbname          => 'staphylococcus_collection_1_52_1a',
00109                 -multispecies_db => 1,
00110                 -host            => 'caldy',
00111                 -driver          => 'mysql'
00112               );
00113 
00114   Description: Constructor for DBAdaptor.
00115   Returntype : Bio::EnsEMBL::DBSQL::DBAdaptor
00116   Exceptions : none
00117   Caller     : general
00118   Status     : Stable
00119 
00120 =cut
00121 
00122 sub new {
00123   my ( $class, @args ) = @_;
00124 
00125   my $self = bless {}, $class;
00126 
00127   my ( $is_multispecies, $species, $species_id, $group, $con, $dnadb,
00128     $no_cache, $dbname )
00129     = rearrange( [
00130       'MULTISPECIES_DB', 'SPECIES', 'SPECIES_ID', 'GROUP',
00131       'DBCONN',          'DNADB',   'NO_CACHE',   'DBNAME'
00132     ],
00133     @args
00134     );
00135 
00136   if ( defined($con) ) { $self->dbc($con) }
00137   else {
00138     if(! defined $dbname) {
00139       throw "-DBNAME is a required parameter when creating a DBAdaptor";
00140     }
00141     $self->dbc( new Bio::EnsEMBL::DBSQL::DBConnection(@args) );
00142   }
00143 
00144   if ( defined($species) ) { $self->species($species) }
00145   if ( defined($group) )   { $self->group($group) }
00146 
00147  
00148   $self = Bio::EnsEMBL::Utils::ConfigRegistry::gen_load($self);
00149 
00150 #  if(!defined($species) ){
00151 #     $reg->find_and_add_aliases($self);
00152 #  }
00153 
00154   $self->species_id( $species_id || 1 );
00155 
00156   $self->is_multispecies( defined($is_multispecies)
00157                           && $is_multispecies == 1 );
00158 
00159   if ( defined($dnadb) )    { $self->dnadb($dnadb) }
00160   if ( defined($no_cache) ) { $self->no_cache($no_cache) }
00161 
00162   return $self;
00163 } ## end sub new
00164 
00165 
00166 
00167 =head2 dbc
00168 
00169   Arg[1]    : (optional) Bio::EnsEMBL::DBSQL::DBConnection
00170 
00171   Example    : $dbc = $dba->dbc();
00172   Description: Getter/Setter for DBConnection.
00173   Returntype : Bio::EnsEMBL::DBSQL::DBConnection
00174   Exceptions : throws if argument not a Bio::EnsEMBL::DBSQL::DBConnection
00175   Caller     : general
00176   Status     : Stable
00177 
00178 =cut
00179 
00180 sub dbc{
00181   my $self  = shift;
00182   
00183   if(@_){
00184     my $arg = shift;
00185     if(defined($arg)){
00186       if(!$arg->isa('Bio::EnsEMBL::DBSQL::DBConnection')){
00187     throw("$arg is no a DBConnection\n");
00188       }
00189     }
00190     $self->{_dbc} = $arg;
00191   }
00192   return $self->{_dbc};
00193 }
00194 
00195 
00196 
00197 =head2 add_db_adaptor
00198 
00199   Arg [1]    : string $name
00200                the name of the database to attach to this database
00201   Arg [2]    : Bio::EnsEMBL::DBSQL::DBConnection
00202                the db adaptor to attach to this database
00203   Example    : $db->add_db_adaptor('lite', $lite_db_adaptor);
00204   Description: Attaches another database instance to this database so 
00205                that it can be used in instances where it is required.
00206   Returntype : none
00207   Exceptions : none
00208   Caller     : EnsWeb
00209   Status     : At Risk
00210              : may get deprecated, please use add_db from the registry instead
00211 
00212 =cut
00213 
00214 sub add_db_adaptor {
00215   my ($self, $name, $adaptor) = @_;
00216 
00217   unless($name && $adaptor && ref $adaptor) {
00218     throw('adaptor and name arguments are required');
00219   }
00220 
00221   Bio::EnsEMBL::Registry->add_db($self, $name, $adaptor);
00222 
00223 }
00224 
00225 
00226 =head2 remove_db_adaptor
00227 
00228   Arg [1]    : string $name
00229                the name of the database to detach from this database.
00230   Example    : $lite_db = $db->remove_db_adaptor('lite');
00231   Description: Detaches a database instance from this database and returns
00232                it.
00233   Returntype : none
00234   Exceptions : none
00235   Caller     : ?
00236   Status     : At Risk
00237              : mey get deprecated, use remove_db instead from the Registry
00238 
00239 =cut
00240 
00241 sub remove_db_adaptor {
00242   my ($self, $name) = @_;
00243 
00244   return Bio::EnsEMBL::Registry->remove_db($self, $name);
00245 }
00246 
00247 
00248 =head2 get_all_db_adaptors
00249 
00250   Arg [1]    : none
00251   Example    : @attached_dbs = values %{$db->get_all_db_adaptors()};
00252   Description: returns all of the attached databases as 
00253                a hash reference of key/value pairs where the keys are
00254                database names and the values are the attached databases  
00255   Returntype : hash reference with Bio::EnsEMBL::DBSQL::DBConnection values
00256   Exceptions : none
00257   Caller     : Bio::EnsEMBL::DBSQL::ProxyAdaptor
00258   Status     : At Risk
00259              : may get deprecated soon
00260              : please use  Bio::EnsEMBL::Registry->get_all_db_adaptors
00261 
00262 =cut
00263 
00264 sub get_all_db_adaptors {
00265   my ($self) = @_;
00266   return Bio::EnsEMBL::Registry->get_all_db_adaptors($self);
00267 }
00268 
00269 
00270 
00271 =head2 get_db_adaptor
00272 
00273   Arg [1]    : string $name
00274                the name of the attached database to retrieve
00275   Example    : $lite_db = $db->get_db_adaptor('lite');
00276   Description: returns an attached db adaptor of name $name or undef if
00277                no such attached database exists
00278   Returntype : Bio::EnsEMBL::DBSQL::DBConnection
00279   Exceptions : none
00280   Caller     : ?
00281   Status     : At Risk
00282              : may get deprecated soon
00283              : please use  Bio::EnsEMBL::Registry->get_db_adaptors
00284 
00285 =cut
00286 
00287 sub get_db_adaptor {
00288   my ($self, $name) = @_;
00289 
00290   return Bio::EnsEMBL::Registry->get_db($self, $name);
00291 }
00292 
00293 =head2 get_available_adaptors
00294 
00295   Example    : my %pairs = %{$dba->get_available_adaptors()};
00296   Description: gets a hash of the available adaptors
00297   ReturnType : reference to a hash
00298   Exceptions : none
00299   Caller     : Bio::EnsEMBL::Utils::ConfigRegistry
00300   Status     : Stable
00301 
00302 =cut 
00303 
00304 sub get_available_adaptors {
00305   my %pairs = (
00306     # Firstly those that just have an adaptor named after there object
00307     # in the main DBSQL directory.
00308     map( { $_ => "Bio::EnsEMBL::DBSQL::${_}Adaptor" } qw(
00309         Analysis                 ArchiveStableId      Attribute
00310         AssemblyExceptionFeature AssemblyMapper       CoordSystem
00311         CompressedSequence       DBEntry              DnaAlignFeature
00312         DensityFeature           DensityType          Exon
00313         Gene                     KaryotypeBand        MiscSet
00314         MiscFeature              PredictionTranscript PredictionExon
00315         ProteinFeature           ProteinAlignFeature  RepeatConsensus
00316         RepeatFeature            Sequence             SeqRegionSynonym  SimpleFeature
00317         Slice                    SupportingFeature    Transcript
00318         TranscriptSupportingFeature Translation       UnmappedObject
00319         UnconventionalTranscriptAssociation           AssemblySlice
00320         SplicingEvent            SplicingEventFeature SplicingTranscriptPair
00321         Operon                  OperonTranscript
00322         DataFile
00323         ) ),
00324     # Those whose adaptors are in Map::DBSQL
00325     map( { $_ => "Bio::EnsEMBL::Map::DBSQL::${_}Adaptor" } qw(
00326         Marker MarkerFeature QtlFeature Qtl Ditag DitagFeature
00327         ) ),
00328     # Finally the exceptions... those that have non-standard mapping
00329     # between object / adaptor ....
00330     # 'Blast'                => 'Bio::EnsEMBL::External::BlastAdaptor',
00331     'MetaCoordContainer' => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
00332     'MetaContainer'      => 'Bio::EnsEMBL::DBSQL::MetaContainer',
00333     'SNP'                => 'Bio::EnsEMBL::DBSQL::ProxySNPAdaptor',
00334   );
00335 
00336   return ( \%pairs );
00337 } ## end sub get_available_adaptors
00338 
00339 ###########################################################
00340 #
00341 # Support for DAS
00342 #
00343 ###########################################################
00344 
00345 =head2 add_DASFeatureFactory
00346 
00347   Arg [1]    : Bio::EnsEMBL::ExternalFeatureFactory $value 
00348   Example    : none
00349   Description: Attaches a DAS Feature Factory to this method.  
00350                ExternalFeatureFactory objects are not really used right now.
00351                They may be reintroduced or taken out completely.  The fate
00352                of this function is unknown (although it is presently needed).
00353   Returntype : none
00354   Exceptions : none
00355   Caller     : EnsWeb
00356   Status     : At Risk
00357              : with the new web code this may not be needed/supported
00358 
00359 =cut
00360 
00361 sub add_DASFeatureFactory{
00362  
00363  my ($self,$value) = @_;
00364   
00365   push(@{$self->{'_das_ff'}},$value);
00366 }
00367 
00368 
00369 sub remove_all_DASFeatureFactories {
00370   $_[0]->{'_das_ff'} = [];
00371 }
00372 =head2 _each_DASFeatureFactory
00373 
00374   Args       : none
00375   Example    : none
00376   Description: Not sure if this is used, or if it should be removed.  It 
00377                does not seem to be used at the moment
00378   Returntype : Bio::EnsEMBL::ExternalFeatureFactory
00379   Exceptions : none
00380   Caller     : ??
00381   Status     : At Risk
00382              : with the new web code this may not be needed/supported
00383 
00384 =cut
00385 
00386 sub _each_DASFeatureFactory{
00387    my ($self) = @_;
00388 
00389    return @{$self->{'_das_ff'}||[]}
00390 }
00391 
00392 
00393 ################################################################## 
00394 # 
00395 # SUPPORT FOR EXTERNAL FEATURE FACTORIES 
00396 # 
00397 ##################################################################
00398 
00399 
00400 
00401 =head2 add_ExternalFeatureAdaptor
00402 
00403   Arg [1]    : Bio::EnsEMBL::External::ExternalFeatureAdaptor
00404   Example    : $db_adaptor->add_ExternalFeatureAdaptor($xfa);
00405   Description: Adds an external feature adaptor to this database adaptor.
00406                Adding the external adaptor in this way allows external
00407                features to be obtained from Slices and from RawContigs.
00408 
00409                The external feature adaptor which is passed to this method
00410                will have its db attribuite set to this DBAdaptor object via 
00411                the db accessor method. 
00412 
00413                ExternalFeatureAdaptors passed to this method are stored 
00414                internally in a hash keyed on the string returned by the 
00415                ExternalFeatureAdaptors track_name method.
00416                
00417                If the track name method is not implemented then the 
00418                a default key named 'External features' is assigned.  In the
00419                event of duplicate key names, a number is appended to the
00420                key name, and incremented for each subsequent adaptor with the
00421                same track name.  For example, if no track_names are specified 
00422                then the the external feature adaptors will be stored under the
00423                keys 'External features', 'External features2' 
00424                'External features3' etc.
00425   Returntype : none
00426   Exceptions : none
00427   Caller     : general
00428   
00429 =cut
00430 
00431 sub add_ExternalFeatureAdaptor {
00432   my ($self, $adaptor) = @_;
00433 
00434   unless($adaptor && ref $adaptor && 
00435      $adaptor->isa('Bio::EnsEMBL::External::ExternalFeatureAdaptor')) {
00436      throw("[$adaptor] is not a " .
00437            "Bio::EnsEMBL::External::ExternalFeatureAdaptor");
00438   }
00439 
00440   unless(exists $self->{'_xf_adaptors'}) {
00441     $self->{'_xf_adaptors'} = {};
00442   }
00443 
00444   my $track_name = $adaptor->{'_track_name'};
00445   if(!$track_name) {
00446     $track_name = $adaptor->track_name();
00447   }
00448 
00449   #use a generic track name if one hasn't been defined
00450   unless(defined $track_name) {
00451     $track_name = "External features";
00452   }
00453 
00454   #if the track name exists add numbers to the end until a free name is found
00455   if(exists $self->{'_xf_adaptors'}->{"$track_name"}) {
00456     my $num = 2;
00457     $num++ while(exists $self->{'_xf_adaptors'}->{"$track_name$num"});
00458     $self->{'_xf_adaptors'}->{"$track_name$num"} = $adaptor;
00459   } else {
00460     $self->{'_xf_adaptors'}->{"$track_name"} = $adaptor;
00461   }
00462 
00463   $adaptor->ensembl_db($self);
00464 }
00465 
00466 
00467 
00468 =head2 get_ExternalFeatureAdaptors
00469 
00470   Arg [1]    : none
00471   Example    : @xfas = values %{$db_adaptor->get_ExternalFeatureAdaptors}; 
00472   Description: Retrieves all of the ExternalFeatureAdaptors which have been
00473                added to this DBAdaptor.  The ExternalFeatureAdaptors are 
00474                returned in a reference to a hash keyed on the track names
00475                of the external adaptors
00476   Returntype : Reference to a hash of ExternalFeatureAdaptors keyed on 
00477                their track names.
00478   Exceptions : none
00479   Caller     : general
00480 
00481 =cut
00482 
00483 sub get_ExternalFeatureAdaptors {
00484   my $self = shift;
00485 
00486   return $self->{'_xf_adaptors'};
00487 }
00488 
00489 
00490 =head2 add_ExternalFeatureFactory
00491 
00492   Arg [1]    : Bio::EnsEMBL::DB::ExternalFeatureFactoryI $value
00493   Example    : $db_adaptor->add_ExternalFeatureFactory
00494   Description: It is recommended that add_ExternalFeatureAdaptor be used 
00495                instead.  See documentation for 
00496                Bio::EnsEMBL::External::ExternalFeatureAdaptor
00497 
00498                Adds an external feature factory to the core database
00499                so that features from external sources can be displayed in 
00500                ensembl. This method is still available mainly for legacy
00501                support for external EnsEMBL installations.
00502   Returntype : none
00503   Exceptions : none
00504   Caller     : external
00505 
00506 =cut
00507 
00508 sub add_ExternalFeatureFactory{
00509    my ($self,$value) = @_;
00510 
00511    $self->add_ExternalFeatureAdaptor($value);
00512 }
00513 
00514 #
00515 # OVERWRITABLE STANDARD ADAPTORS
00516 #
00517 
00518 =head2 get_adaptor
00519 
00520   Arg [1]    : Canonical data type for which an adaptor is required.
00521   Example    : $db_adaptor->get_adaptor("Protein")
00522   Description: Gets an adaptor object for a standard data type.
00523   Returntype : Adaptor Object of arbitrary type or undef
00524   Exceptions : none
00525   Caller     : external
00526   Status     : Medium Risk
00527              : please use the Registry method, as at some time this
00528              : may no longer be supprted.
00529  
00530 =cut
00531 
00532 sub get_adaptor {
00533   my ($self, $canonical_name, @other_args) = @_;
00534 
00535   return $reg->get_adaptor($self->species(),$self->group(),$canonical_name);
00536 }
00537 
00538 
00539 
00540 =head2 set_adaptor
00541 
00542   Arg [1]    : Canonical data type for new adaptor.
00543     Arg [2]    : Object defining the adaptor for arg1.
00544   Example    : $aa = Bio::EnsEMBL::DBSQL::GeneAdaptor->new($db_adaptor);
00545              : $db_adaptor->set_adaptor("Gene", $ga)
00546   Description: Stores the object which represents the adaptor for the
00547                arg1 data type.
00548   Returntype : none
00549   Exceptions : none
00550   Caller     : external
00551   Status     : Medium Risk
00552              : please use the Registry method, as at some time this
00553              : may no longer be supprted.
00554  
00555 =cut
00556 
00557 sub set_adaptor {
00558   my ($self, $canonical_name, $module) = @_;
00559 
00560   $reg->add_adaptor($self->species(),$self->group(),$canonical_name,$module);
00561 
00562   return $module;
00563 }
00564 
00565 
00566 #
00567 # GENERIC FEATURE ADAPTORS
00568 #
00569 
00570 =head2 get_GenericFeatureAdaptors
00571 
00572   Arg [1]    : List of names of feature adaptors to get. If no
00573                adaptor names are given, all the defined adaptors are returned.
00574   Example    : $db->get_GenericFeature("SomeFeature", "SomeOtherFeature")
00575   Description: Returns a hash containing the named feature adaptors (or
00576                all feature adaptors).
00577   Returntype : reference to a Hash containing the named
00578                feature adaptors (or all feature adaptors).
00579   Exceptions : If any of the the named generic feature adaptors do not exist.
00580   Caller     : external
00581 
00582 =cut
00583 
00584 sub get_GenericFeatureAdaptors {
00585 
00586   my ($self, @names) = @_;
00587 
00588   my %adaptors = ();
00589 
00590   if (!@names) {
00591     %adaptors = %{$self->{'generic_feature_adaptors'}};
00592   } else {
00593     foreach my $name (@names) {
00594       if (!exists($self->{'generic_feature_adaptors'}->{$name})) {
00595         throw("No generic feature adaptor has been defined for $name" );
00596       }
00597 
00598 
00599       $adaptors{$name} = $self->{'generic_feature_adaptors'}->{$name};
00600     }
00601   }
00602 
00603   return \%adaptors;
00604 }
00605 
00606 
00607 =head2 add_GenericFeatureAdaptor
00608 
00609   Arg [1]    : The name of the feature.
00610   Arg [2]    : Adaptor object for a generic feature.
00611   Example    : $db->add_GenericFeatureAdaptor("SomeFeature",
00612                               "Bio::EnsEMBL::DBSQL::SomeFeatureAdaptor")
00613   Description: Stores the object which represents the adaptor for the
00614                named feature type.
00615   Returntype : none
00616   Exceptions :
00617   Caller     : external
00618 
00619 =cut
00620 
00621 sub add_GenericFeatureAdaptor {
00622   my ($self, $name, $adaptor_obj) = @_;
00623     
00624   # check that $adaptor is an object that subclasses BaseFeatureAdaptor 
00625   if (!$adaptor_obj->isa("Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor")) {
00626     throw("$name is a " . ref($adaptor_obj) . "which is not a " .
00627           "subclass of Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor" );
00628   }
00629 
00630   $self->{'generic_feature_adaptors'}->{$name} = $adaptor_obj;
00631 }
00632 
00633 =head2 species
00634 
00635   Arg [1]    : (optional) string $arg
00636                The new value of the species used by this DBAdaptor. 
00637   Example    : $species = $dba->species()
00638   Description: Getter/Setter for the species of to use for 
00639                this connection.  There is currently no point in setting 
00640                this value after the connection has already been established 
00641                by the constructor.
00642   Returntype : string
00643   Exceptions : none
00644   Caller     : new
00645   Status     : Stable
00646 
00647 =cut
00648 
00649 sub species {
00650   my ( $self, $arg ) = @_;
00651 
00652   if ( defined($arg) ) {
00653     $self->{_species} = $arg;
00654   }
00655 
00656   $self->{_species};
00657 }
00658 
00659 =head2 all_species
00660 
00661   Args       : NONE
00662   Example    : @all_species = @{$dba->all_species()};
00663   Description: Returns the names of all species contained in the
00664                database to which this DBAdaptor is connected.
00665   Returntype : array reference
00666   Exceptions : none
00667   Caller     : general
00668   Status     : Stable
00669 
00670 =cut
00671 
00672 sub all_species {
00673   my ($self) = @_;
00674 
00675   if ( !$self->is_multispecies() ) { return [ $self->species() ] }
00676 
00677   if ( exists( $self->{'_all_species'} ) ) {
00678     return $self->{'_all_species'};
00679   }
00680 
00681   my $statement =
00682       "SELECT meta_value "
00683     . "FROM meta "
00684     . "WHERE meta_key = 'species.db_name'";
00685 
00686   my $sth = $self->dbc()->db_handle()->prepare($statement);
00687 
00688   $sth->execute();
00689 
00690   my $species;
00691   $sth->bind_columns( \$species );
00692 
00693   my @all_species;
00694   while ( $sth->fetch() ) { push( @all_species, $species ) }
00695 
00696   $self->{'_all_species'} = \@all_species;
00697 
00698   return $self->{'_all_species'};
00699 } ## end sub all_species
00700 
00701 
00702 =head2 is_multispecies
00703 
00704   Arg [1]    : (optional) boolean $arg
00705   Example    : if ($dba->is_multispecies()) { }
00706   Description: Getter/Setter for the is_multispecies boolean of
00707                to use for this connection.  There is currently no
00708                point in setting this value after the connection has
00709                already been established by the constructor.
00710   Returntype : boolean
00711   Exceptions : none
00712   Caller     : new
00713   Status     : Stable
00714 
00715 =cut
00716 
00717 sub is_multispecies {
00718   my ( $self, $arg ) = @_;
00719 
00720   if ( defined($arg) ) {
00721     $self->{_is_multispecies} = $arg;
00722   }
00723 
00724   return $self->{_is_multispecies};
00725 }
00726 
00727 
00728 =head2 species_id
00729 
00730   Arg [1]    : (optional) string $arg
00731                The new value of the species_id used by this DBAdaptor
00732                when dealing with multi-species databases.
00733   Example    : $species_id = $dba->species_id()
00734   Description: Getter/Setter for the species_id of to use for this
00735                connection.  There is currently no point in setting
00736                this value after the connection has already been
00737                established by the constructor.
00738   Returntype : string
00739   Exceptions : none
00740   Caller     : new
00741   Status     : Stable
00742 
00743 =cut
00744 
00745 sub species_id {
00746   my ( $self, $arg ) = @_;
00747 
00748   if ( defined($arg) ) {
00749     $self->{_species_id} = $arg;
00750   }
00751 
00752   return $self->{_species_id};
00753 }
00754 
00755 
00756 =head2 no_cache
00757 
00758   Arg [1]    : (optional) int $arg
00759                The new value of the no cache attribute used by this DBAdaptor. 
00760   Example    : $no_cache = $dba->no_cache();
00761   Description: Getter/Setter for the no_cache to use for 
00762                this connection.  There is currently no point in setting 
00763                this value after the connection has already been established 
00764                by the constructor.
00765   Returntype : int
00766   Exceptions : none
00767   Caller     : new
00768   Status     : Stable
00769 
00770 =cut
00771 
00772 sub no_cache {
00773   my ($self, $arg ) = @_;
00774 
00775   if ( defined $arg ){
00776       if ($arg != 1 && $arg != 0){
00777       throw("$arg is not allowed for this attribute. Only value 1|0 is allowed");
00778       }
00779       $self->{_no_cache} = $arg;
00780   }
00781   $self->{_no_cache};
00782 }
00783 
00784 
00785 =head2 group
00786 
00787   Arg [1]    : (optional) string $arg
00788                The new value of the group used by this DBAdaptor. 
00789   Example    : $group = $dba->group()
00790   Description: Getter/Setter for the group of to use for 
00791                this connection.  There is currently no point in setting 
00792                this value after the connection has already been established 
00793                by the constructor.
00794   Returntype : string
00795   Exceptions : none
00796   Caller     : new
00797   Status     : Stable
00798 
00799 =cut
00800 
00801 sub group {
00802   my ($self, $arg ) = @_;
00803   ( defined $arg ) &&
00804     ( $self->{_group} = $arg );
00805   $self->{_group};
00806 }
00807 
00808 =head2 get_SeqRegionCache
00809 
00810   Arg [1]    : none
00811   Example    : my $srcache = $dba->get_SeqRegionCache();
00812   Description: Retrieves a seq_region cache for this database
00813   Returntype : Bio::EnsEMBL::Utils::SeqRegionCache
00814   Exceptions : none
00815   Caller     : SliceAdaptor, AssemblyMapperAdaptor
00816   Status     : Stable
00817 
00818 =cut
00819 
00820 sub get_SeqRegionCache {
00821   my $self = shift;
00822 
00823   # use the cache from the database where seq_regions are stored
00824   if($self != $self->dnadb()) {
00825     return $self->dnadb()->get_SeqRegionCache();
00826   }
00827 
00828   if(!$self->{'seq_region_cache'}) {
00829     $self->{'seq_region_cache'} = Bio::EnsEMBL::Utils::SeqRegionCache->new();
00830   }
00831 
00832   return $self->{'seq_region_cache'};
00833 }
00834 
00835 
00836 
00837 #convenient method to retrieve the schema_build version for the database being used
00838 
00839 sub _get_schema_build{
00840   my ($self) = @_;
00841 
00842   #avoided using dnadb by default to avoid obfuscation of behaviour
00843   
00844   my @dbname = split/_/, $self->dbc->dbname();
00845 
00846   #warn "dbname is $schema_build";
00847 
00848   my $schema_build = pop @dbname;
00849   $schema_build = pop(@dbname).'_'.$schema_build;
00850 
00851 
00852   return $schema_build;
00853 }
00854 
00855 
00856 =head2 dnadb
00857 
00858  Title   : dnadb
00859  Usage   : my $dnadb = $db->dnadb();
00860  Function: returns the database adaptor where the dna lives
00861            Useful if you only want to keep one copy of the dna
00862            on disk but have other databases with genes and features in
00863  Returns : dna database adaptor
00864  Args    : Bio::EnsEMBL::DBSQL::BaseAdaptor
00865  Status  : Medium Risk.
00866          : Use the Registry method add_DNAAdaptor/get_DNAAdaptor instead
00867 
00868 =cut
00869 
00870 sub dnadb {
00871   my $self = shift;
00872 
00873   if(@_) {
00874     my $arg = shift;
00875     $reg->add_DNAAdaptor($self->species(),$self->group(),$arg->species(),$arg->group());
00876   }
00877 
00878 #  return $self->{'dnadb'} || $self;
00879   return $reg->get_DNAAdaptor($self->species(),$self->group()) || $self;
00880 }
00881 
00882 
00883 use vars '$AUTOLOAD';
00884 
00885 sub AUTOLOAD {
00886   my ( $self, @args ) = @_;
00887 
00888   my $type;
00889   if ( $AUTOLOAD =~ /^.*::get_(\w+)Adaptor$/ ) {
00890     $type = $1;
00891   } elsif ( $AUTOLOAD =~ /^.*::get_(\w+)$/ ) {
00892     $type = $1;
00893   } else {
00894     throw( sprintf( "Could not work out type for %s\n", $AUTOLOAD ) );
00895   }
00896   my $ret =
00897     $reg->get_adaptor( $self->species(), $self->group(), $type );
00898 
00899   if ($ret) {
00900 
00901     return $ret;
00902 
00903   } else {
00904     warning(
00905          sprintf(
00906                 "Could not find %s adaptor in the registry for %s %s\n",
00907                 $type, $self->species(), $self->group() ) );
00908 
00909     throw( sprintf( "Could not get adaptor %s for %s %s\n",
00910                     $type, $self->species(), $self->group() ) );
00911 
00912     return $ret;
00913   }
00914 
00915   die( sprintf( "No such method: %s\n", $AUTOLOAD ) );
00916 
00917 } ## end sub AUTOLOAD
00918 
00919 sub DESTROY { }    # required due to AUTOLOAD
00920 
00921 
00922 #########################
00923 # sub DEPRECATED METHODS
00924 #########################
00925 =head2 db
00926   
00927   Description: DEPRECATED 
00928   
00929 =cut
00930 
00931 sub db{
00932   my ($self, $arg ) = @_;
00933  deprecate("db Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
00934  return $self->dbc($arg);
00935 }
00936 
00937 
00938 sub source { deprecate('Do not use - this method does nothing'); }
00939 
00940 
00941 =head2 assembly_type
00942 
00943   Description: DEPRECATED - Use CoordSystemAdaptor to obtain default coordinate
00944                system instead.
00945 
00946 =cut
00947 
00948 sub assembly_type{
00949   my $self = shift;
00950 
00951   deprecate('Use CoordSystemAdaptor $csa->fetch_all->[0]->version() instead');
00952 
00953   my $csa = $self->get_CoordSystemAdaptor();
00954   my ($cs) = @{$csa->fetch_all()};
00955   return ($cs) ? $cs->version() : undef;
00956 }
00957 
00958 
00959 
00960 =head2 list_supported_assemblies
00961 
00962   Description: DEPRECATED - Use CoordSystemAdaptor to obtain list of top-level
00963                coordinate systems instead
00964 
00965 =cut
00966 
00967 sub list_supported_assemblies {
00968   my($self) = @_;
00969   deprecate('Use CoordSystemAdaptor::fetch_all instead');
00970 
00971   my $csa = $self->get_CoordSystemAdaptor();
00972   my %versions;
00973   foreach my $cs (@{$csa->fetch_all()}) {
00974     $versions{$cs->version()} = 1;
00975   }
00976 
00977   return keys %versions;
00978 }
00979 
00980 
00981 sub prepare{
00982   my ($self, @args) = @_;
00983 
00984  deprecate("prepare Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
00985   $self->dbc->prepare(@args);
00986 }
00987 
00988 sub dbname{
00989   my ($self, @args) = @_;
00990 
00991  deprecate("dbname Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
00992   $self->dbc->dbname(@args);
00993 } 
00994 
00995 sub disconnect_when_inactive{
00996   my ($self, @args) = @_;
00997 
00998  deprecate("disconnect_when_inactive Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
00999   $self->dbc->disconnect_when_inactive(@args);
01000 }
01001 
01002 sub reconnect_when_lost{
01003   my ($self, @args) = @_;
01004 
01005  deprecate("reconnect_when_lost Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01006   $self->dbc->reconnect_when_lost(@args);
01007 }
01008 
01009 
01010 sub host{
01011   my ($self, @args) = @_;
01012 
01013  deprecate("host Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01014   $self->dbc->host(@args);
01015 }
01016 sub username{
01017   my ($self, @args) = @_;
01018 
01019  deprecate("username Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01020   $self->dbc->username(@args);
01021 }
01022 sub password{
01023   my ($self, @args) = @_;
01024 
01025  deprecate("password Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01026   $self->dbc->password(@args);
01027 }
01028 sub driver{
01029   my ($self, @args) = @_;
01030 
01031  deprecate("driver Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01032   $self->dbc->driver(@args);
01033 }
01034 sub port{
01035   my ($self, @args) = @_;
01036 
01037  deprecate("port Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01038   $self->dbc->port(@args);
01039 }
01040 
01041 sub db_handle{
01042   my ($self, @args) = @_;
01043 
01044 
01045  deprecate("db_handle Should no longer be called from the DBAdaptor. DBConnection should now be used OR preferably the object adaptor itself\n");
01046   $self->dbc->db_handle(@args);
01047 }
01048 
01049 
01050 1;