Archive Ensembl HomeArchive Ensembl Home
MetaContainer.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::MetaContainer - Encapsulates all access to core
00024 database meta information
00025 
00026 =head1 SYNOPSIS
00027 
00028   my $meta_container =
00029     $registry->get_adaptor( 'Human', 'Core', 'MetaContainer' );
00030 
00031   my @mapping_info =
00032     @{ $meta_container->list_value_by_key('assembly.mapping') };
00033   
00034   my $scientific_name = $meta_container->get_scientific_name();
00035 
00036 =head1 DESCRIPTION
00037 
00038   An object that encapsulates specific access to core db meta data
00039 
00040 =head1 METHODS
00041 
00042 =cut
00043 
00044 package Bio::EnsEMBL::DBSQL::MetaContainer;
00045 
00046 use strict;
00047 use warnings;
00048 
00049 use Bio::EnsEMBL::Utils::Exception qw/deprecate/;
00050 use Bio::Species;
00051 
00052 
00053 use base qw/Bio::EnsEMBL::DBSQL::BaseMetaContainer/;
00054 
00055 # add well known meta info get-functions below
00056 
00057 =head2 get_production_name
00058 
00059   Args          : none
00060   Example       : $species = $meta_container->get_production_name();
00061   Description   : Obtains the name of the species in a form usable as, for
00062                   example, a table name, file name etc.
00063   Returntype    : string
00064   Exceptions    : none
00065   Status        : Stable
00066 
00067 =cut
00068 
00069 sub get_production_name {
00070   my ($self) = @_;
00071   return $self->single_value_by_key('species.production_name');
00072 }
00073 
00074 =head2 get_short_name
00075 
00076   Args          : none
00077   Example       : $species = $meta_container->get_short_name();
00078   Description   : Obtains the name of the species in a form usable as, for
00079                   example, a short label in a GUI.
00080   Returntype    : string
00081   Exceptions    : none
00082   Status        : Stable
00083 
00084 =cut
00085 
00086 sub get_short_name {
00087   my ($self) = @_;
00088   return $self->single_value_by_key('species.short_name');
00089 }
00090 
00091 =head2 get_common_name
00092 
00093   Args          : none
00094   Example       : $species = $meta_container->get_common_name();
00095   Description   : Obtains the common name of the species.
00096   Returntype    : string
00097   Exceptions    : none
00098   Status        : Stable
00099 
00100 =cut
00101 
00102 sub get_common_name {
00103   my ($self) = @_;
00104   return $self->single_value_by_key('species.common_name');
00105 }
00106 
00107 =head2 get_scientific_name
00108 
00109   Args          : none
00110   Example       : $species = $meta_container->get_scientific_name();
00111   Description   : Obtains the full scientific name of the species.
00112   Returntype    : string
00113   Exceptions    : none
00114   Status        : Stable
00115 
00116 =cut
00117 sub get_scientific_name {
00118   my ($self) = @_;
00119   return $self->single_value_by_key('species.scientific_name');
00120 }
00121 
00122 =head2 get_Species
00123 
00124   Arg [1]    : none
00125   Example    : $species = $meta_container->get_Species();
00126   Description: Obtains the species from this databases meta table. Call is
00127                deprecated; please use other subroutines in this package
00128   Returntype : Bio::Species
00129   Exceptions : none
00130   Caller     : ?
00131   Status     : Deprecated
00132 
00133 =cut
00134 
00135 sub get_Species {
00136   my ($self) = @_;
00137 
00138   deprecate('Call is deprecated. Use $self->get_common_name() / $self->get_classification() / $self->get_scientific_name() instead');
00139 
00140   my $common_name = $self->get_common_name();
00141   my $classification =
00142     $self->list_value_by_key('species.classification');
00143   if ( !@$classification ) {
00144     return undef;
00145   }
00146 
00147   my $species = Bio::Species->new();
00148   $species->common_name($common_name);
00149   $species->classification($classification, 1); #always force it
00150 
00151   return $species;
00152 }
00153 
00154 
00155 =head2 get_taxonomy_id
00156 
00157   Arg [1]    : none
00158   Example    : $tax_id = $meta_container->get_taxonomy_id();
00159   Description: Retrieves the taxonomy id from the database meta table
00160   Returntype : string
00161   Exceptions : none
00162   Caller     : ?
00163   Status     : Stable
00164 
00165 =cut
00166 
00167 sub get_taxonomy_id {
00168   my ($self) = @_;
00169   return $self->single_value_by_key('species.taxonomy_id', 1);
00170 }
00171 
00172 
00173 
00174 =head2 get_default_assembly
00175 
00176   Description: DEPRECATED. Use the version of the coordinate system you are
00177              interested in instead.
00178 
00179   Example:     #use this instead
00180                my ($highest_cs) = @{$db->get_CoordSystemAdaptor->fetch_all()};
00181                my $assembly = $highest_cs->version();
00182 
00183 =cut
00184 
00185 sub get_default_assembly {
00186   my $self = shift;
00187 
00188   deprecate("Use version of coordinate system you are interested in instead.\n".
00189             "Example:\n".
00190             '  ($cs) = @{$coord_system_adaptor->fetch_all()};'."\n" .
00191             '  $assembly = $cs->version();');
00192 
00193   my ($cs) = @{$self->db->get_CoordSystemAdaptor->fetch_all()};
00194 
00195   return $cs->version();
00196 }
00197 
00198 
00199 #
00200 # TBD This method should be removed/deprecated
00201 #
00202 sub get_max_assembly_contig {
00203   my $self = shift;
00204   deprecate('This method should either be fixed or removed');
00205   return $self->single_value_by_key('assembly.maxcontig');
00206 }
00207 
00208 =head2 get_genebuild
00209 
00210   Arg [1]    : none
00211   Example    : $tax_id = $meta_container->get_genebuild();
00212   Description: Retrieves the genebuild from the database meta table
00213   Returntype : string
00214   Exceptions : none
00215   Caller     : ?
00216   Status     : Stable
00217 
00218 =cut
00219 
00220 sub get_genebuild {
00221   my ($self) = @_;
00222   return $self->single_value_by_key('genebuild.start_date', 1);
00223 }
00224 
00225 =head2 get_genebuild
00226 
00227   Example    : $classification = $meta_container->get_classification();
00228   Description: Retrieves the classification held in the backing database minus
00229                any species specific levels. This means that the first element
00230                in the array will be subfamily/family level ascending to
00231                superkingdom
00232   Returntype : ArrayRef[String]
00233   Exceptions : none
00234   Caller     : ?
00235   Status     : Stable
00236 
00237 =cut
00238 
00239 sub get_classification {
00240   my ($self) = @_;
00241   my $classification = $self->list_value_by_key('species.classification');
00242   splice(@{$classification}, 0, 2); # remove the sapiens, Homo from the backing array
00243   return $classification;
00244 }
00245 
00246 
00247 1;
00248