From 2144ec36e9134e62871622d556465bb1eb3dc4bc Mon Sep 17 00:00:00 2001
From: Magali Ruffier <mr6@ebi.ac.uk>
Date: Thu, 19 Sep 2013 09:43:43 +0000
Subject: [PATCH] ENSPROD-55: removing AssemblyAdaptor, wrong object and should
 not have been there replaced by GenomeContainer, hopefully more generic and
 in line with what already exists presenting most of the generic features the
 assemblyadaptor add, but less REST only focused will be further expanded with
 a genome table

---
 modules/Bio/EnsEMBL/DBSQL/AssemblyAdaptor.pm | 229 -------
 modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm | 605 +++++++++++++++++++
 2 files changed, 605 insertions(+), 229 deletions(-)
 delete mode 100644 modules/Bio/EnsEMBL/DBSQL/AssemblyAdaptor.pm
 create mode 100644 modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm

diff --git a/modules/Bio/EnsEMBL/DBSQL/AssemblyAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/AssemblyAdaptor.pm
deleted file mode 100644
index 5ea710722a..0000000000
--- a/modules/Bio/EnsEMBL/DBSQL/AssemblyAdaptor.pm
+++ /dev/null
@@ -1,229 +0,0 @@
-=head1 LICENSE
-
-  Copyright (c) 1999-2013 The European Bioinformatics Institute and
-  Genome Research Limited.  All rights reserved.
-
-  This software is distributed under a modified Apache license.
-  For license details, please see
-
-    http://www.ensembl.org/info/about/code_licence.html
-
-=head1 CONTACT
-
-  Please email comments or questions to the public Ensembl
-  developers list at <dev@ensembl.org>.
-
-  Questions may also be sent to the Ensembl help desk at
-  <helpdesk@ensembl.org>.
-
-=cut
-
-=head1 NAME
-
-Bio::EnsEMBL::DBSQL::AssemblyAdaptor - Retrieves meta information
-related to the assembly, density features/counts per chromosome or if none
-provided, all top level seq regions
-
-
-=head1 SYNOPSIS
-
-
-=head1 DESCRIPTION
-
-=head1 METHODS
-
-=cut
-
-package Bio::EnsEMBL::DBSQL::AssemblyAdaptor;
-
-use strict;
-use warnings;
-
-use Bio::EnsEMBL::DBSQL::BaseAdaptor;
-use Bio::EnsEMBL::DBSQL::MetaContainer;
-use Bio::EnsEMBL::Attribute;
-
-use Bio::EnsEMBL::Utils::Exception qw(throw deprecate warning);
-
-use vars qw(@ISA);
-
-@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
-
-
-
-=head2 new
-
-  Arg [1]    : Bio::EnsEMBL::DBAdaptor $dbadaptor the adaptor for
-               the database this assembly info adaptor is using.
-  Example    : my $aia = new Bio::EnsEMBL::AssemblyAdaptor($dbadaptor);
-  Description: Creates a new AssemblyAdaptor object
-  Returntype : Bio::EnsEMBL::DBSQL::AssemblyAdaptor
-  Exceptions : none
-  Caller     : Bio::EnsEMBL::DBSQL::DBAdaptor
-  Status     : Stable
-
-=cut
-
-sub new {
-  my($class, $dbadaptor) = @_;
-
-  my $self = $class->SUPER::new($dbadaptor);
-
-  return $self;
-}
-
-=head2 fetch_info
-    
-  Description: Returns a hash containing information about the assembly
-               stored in the meta table, such as assembly name, date etc., 
-               a reference to array of top level seq_region names and a
-               reference to array of all coordinate system versions found
-  Returntype : reference to a hash with assembly info key and value pairs
-  Exceptions : none
-  Caller     : general
-  Status     : Stable
-
-=cut
-
-
-sub fetch_info {
-  my $self = shift;
-
-  #fetch assembly information stored in the meta table
-
-  my $meta_container = $self->db()->get_adaptor('MetaContainer');
-
-  my @meta_keys = qw(assembly.name       assembly.date                    genebuild.start_date
-                     genebuild.method    genebuild.initial_release_date   genebuild.last_geneset_update);
-  my %assembly_info;
-
-  foreach my $meta_key (@meta_keys) {
-      my @values = @{ $meta_container->list_value_by_key($meta_key) };     
-      if (@values) {
-	  $assembly_info{$meta_key} = $values[0];
-      }
-  }
- 
-  my $schema_build = $self->db()->_get_schema_build();
-  if ($schema_build) {
-      $assembly_info{'schema_build'} = $schema_build;
-  }
-  
-  #fetch available coordinate systems
-  my $csa = $self->db()->get_adaptor('CoordSystem');
-  my $coord_systems = $csa->fetch_all();
-  my %versions = map { $_->version(), 1 } @{$coord_systems};
-  $assembly_info{'coord_system_versions'} = [keys %versions];
-  my ($default_assembly) = @{$coord_systems};
-  $assembly_info{default_coord_system_version} = $default_assembly->version();
-
-  #fetch top level seq_region names
-
-  my $sa = $self->db()->get_adaptor('Slice');
-
-  my $slices = $sa->fetch_all('toplevel');
-  my %unique = map { $_->seq_region_name(), 0 } @{$slices};
-  my $names = [sort { $a cmp $b } keys %unique];
-  $assembly_info{'top_level_seq_region_names'} = $names;
-
-  my $karyotype = $sa->fetch_all_karyotype();
-  $assembly_info{karyotype} = [ map { $_->seq_region_name() } @{$karyotype}];
-
-  return \%assembly_info;
-}
-
-
-=head2 fetch_stats
-
-  Arg [1]    : string $seq_region_name (optional)
-               The name of the toplevel seq_region for which statistics should be fetched
-
-  Description: Returns a reference to a hash containing density features/ density related 
-               seq_region attributes for a toplevel seq_region provided or if none
-               provided - all top level seq regions
-  Returntype : hashref
-  Exceptions : throw if the toplevel slice with seq_region_name provided does not exist
-  Caller     : general
-  Status     : Stable
-
-=cut
-
-
-sub fetch_stats {
-  my $self = shift;
-
-  my $seq_region_name = shift;
-
-  my @slices;
-
-  my %assembly_stats;
-
-  my $sa = $self->db()->get_adaptor('Slice');
-  
-  if ($seq_region_name) {
-      my $slice = $sa->fetch_by_region('toplevel',$seq_region_name);
-      if (!$slice) {
-	  throw("Top level slice $seq_region_name not found");
-      }
-      push(@slices, $slice);
-      $assembly_stats{'seq_region_name'} = $seq_region_name;
-  } else {
-      @slices = @{$sa->fetch_all('toplevel')};
-  }
-
-  my @density_types  = qw(genedensity knowngenedensity snpdensity percentgc);
-
-  my @attrib_types = qw(GeneNo% SNPCount);
-
-  my $aa = $self->db()->get_adaptor('Attribute');
-
-  my $dfa = $self->db()->get_adaptor('DensityFeature');
-
-  #used to calculate the average density value for density types represented as ratios
- 
-  my %density_ft_count = ();
-
-  foreach my $slice (@slices) {
-
-     $assembly_stats{'Length (bps)'} += $slice->length();
-
-     foreach my $density_type (@density_types) {
-	      
-	  my $density_features = $dfa->fetch_all_by_Slice($slice,$density_type);
-	  
-	  foreach my $density_feature (@$density_features) {
-
-	      if ($density_feature->density_type()->value_type() eq 'ratio') {
-		  $density_ft_count{$density_feature->density_type()->analysis()->display_label()} += 1;
-	      }
-
-	       $assembly_stats{$density_feature->density_type()->analysis()->display_label()} += $density_feature->density_value(); 
-	  }
-     }
-
-     foreach my $attrib_type (@attrib_types) {
-
-	  my $attribs = $aa->fetch_all_by_Slice($slice,$attrib_type);
-	      
-	  foreach my $attrib (@$attribs) {
-		 $assembly_stats{$attrib->description()} += $attrib->value(); 
-	  }
-     }
-  }
-
-  foreach my $density_analysis (keys %density_ft_count) {
-
-      if ($density_ft_count{$density_analysis} > 1) {
-	  $assembly_stats{$density_analysis} /= $density_ft_count{$density_analysis};
-	  $assembly_stats{$density_analysis} = sprintf "%.2f", $assembly_stats{$density_analysis}; 
-	  $assembly_stats{$density_analysis} .= '%';
-      }
-  }
-
-  return \%assembly_stats;
-}
-
-
-
-1;
-
diff --git a/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm b/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm
new file mode 100644
index 0000000000..0b94f1774a
--- /dev/null
+++ b/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm
@@ -0,0 +1,605 @@
+=head1 LICENSE
+
+  Copyright (c) 1999-2013 The European Bioinformatics Institute and
+  Genome Research Limited.  All rights reserved.
+
+  This software is distributed under a modified Apache license.
+  For license details, please see
+
+    http://www.ensembl.org/info/about/code_licence.html
+
+=head1 CONTACT
+
+  Please email comments or questions to the public Ensembl
+  developers list at <dev@ensembl.org>.
+
+  Questions may also be sent to the Ensembl help desk at
+  <helpdesk@ensembl.org>.
+
+=cut
+
+=head1 NAME
+
+=head1 NAME
+
+Bio::EnsEMBL::DBSQL::GenomeContainer - Encapsulates all access to 
+genome related information
+
+=head1 SYNOPSIS
+
+  use Bio::EnsEMBL::Registry;
+
+  Bio::EnsEMBL::Registry->load_registry_from_db(
+    -host => 'ensembldb.ensembl.org',
+    -user => 'anonymous'
+  );
+
+  $genome =
+    Bio::EnsEMBL::Registry->get_adaptor( "human", "core", "GenomeContainer" );
+
+  my $version = $genome->get_version;
+
+  my $ref_length = $genome->get_ref_length;
+
+  my $coord_systems = $genome->get_coord_systems;
+
+
+
+=head1 DESCRIPTION
+
+This module is responsible for fetching and storing genome-wide information.
+Genome is an abstract object which contains information linking the species, the assembly and the ensembl annotation.
+
+=head1 METHODS
+
+=cut
+
+package Bio::EnsEMBL::DBSQL::GenomeContainer;
+
+use strict;
+use warnings;
+use Bio::EnsEMBL::DBSQL::DBAdaptor;
+use Bio::EnsEMBL::DBSQL::BaseAdaptor;
+use Bio::EnsEMBL::Utils::Exception qw( deprecate throw warning );
+use Bio::EnsEMBL::Utils::Scalar qw( assert_ref );
+
+use vars qw(@ISA);
+
+@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
+
+
+
+=head2 new
+
+  Arg [...]  : Superclass args.  See Bio::EnsEMBL::DBSQL::BaseAdaptor
+  Description: Instantiates a Bio::EnsEMBL::DBSQL::GenomeContainer
+  Returntype : Bio::EnsEMBL::GenomeContainer
+  Exceptions : none
+  Caller     : DBAdaptor
+  Status     : Stable
+
+=cut
+
+
+sub new {
+  my $class = shift;
+
+  my $self = $class->SUPER::new(@_);
+
+  # cache creation could go here
+  return $self;
+}
+
+=head2 _meta_container
+
+  Arg [1]    : none
+  Example    : $meta_container = $genome->_meta_container();
+  Description: Internal method to return a MetaContainer object for the genome
+  Returntype : Bio::EnsEMBL::DBSQL::MetaContainer
+  Exceptions : none
+  Caller     : general
+  Status     : At risk
+
+=cut
+
+sub _meta_container {
+  my $self = shift;
+  return $self->db->get_adaptor('MetaContainer');
+}
+
+
+=head2 get_version
+
+  Arg [1]    : (optional) assembly version
+  Example    : $version = $genome->get_version();
+  Description: Getter/Setter for the assembly version
+
+  Returntype : string
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_version {
+  my ($self, $version) = @_;
+  if (defined $version) {
+    $self->{'version'} = $version;
+  }
+  if (!defined $self->{'version'}) {
+    my $csa = $self->db()->get_adaptor('CoordSystem');
+    my @cs = @{ $csa->fetch_all() };
+    $self->{'version'} = $cs[0]->version();
+  }
+  return $self->{'version'};
+}
+
+=head2 get_accession
+
+  Arg [1]    : (optional) assembly accession
+  Example    : $accession = $genome->get_accession();
+  Description: Getter/setter for the accession of the assembly currently used
+
+  Returntype : string
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_accession {
+  my ($self, $accession) = @_;
+  if (defined $accession) {
+    $self->{'accession'} = $accession;
+  }
+  if (!defined $self->{'accession'}) {
+    $self->{'accession'} = $self->_meta_container->single_value_by_key('assembly.accession');
+  }
+  return $self->{'accession'};
+}
+
+=head2 _get_length
+
+  Arg [1]    : none
+  Example    : $length = $genome->_get_length('toplevel');
+  Description: Internal method to return the length for a type of slices
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : At risk
+
+=cut
+
+sub _get_length {
+  my ($self, $cs_name) = @_;
+  my $slice_adaptor = $self->db->get_adaptor('Slice');
+  my $seqlevel = $slice_adaptor->fetch_all($cs_name);
+  my $count;
+  foreach my $seq (@$seqlevel) {
+    $count += $seq->length();
+  }
+  return $count;
+}
+
+
+
+=head2 get_ref_length
+
+  Arg [1]    : (optional) golden path length
+  Example    : $ref_length = $genome->get_ref_length();
+  Description: Getter/setter for the golden path of the assembly currently used
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_ref_length {
+  my ($self, $ref_length) = @_;
+  if (defined $ref_length) {
+    $self->{'ref_length'} = $ref_length;
+  }
+  if (!defined $self->{'ref_length'}) {
+    $self->{'ref_length'} = $self->_get_length('toplevel');
+  }
+  return $self->{'ref_length'};
+}
+
+
+=head2 get_total_length
+
+  Arg [1]    : (optional) base pair length
+  Example    : $total_length = $genome->get_total_length();
+  Description: Getter/setter for the total length (number of base pairs) for the assembly currently used
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_total_length {
+  my ($self, $total_length) = @_;
+  if (defined $total_length) {
+    $self->{'total_length'} = $total_length;
+  }
+  if (!defined $self->{'total_length'}) {
+    $self->{'total_length'} = $self->_get_length('seqlevel');
+  }
+  return $self->{'total_length'};
+}
+
+=head2 get_toplevel
+
+  Arg [1]    : none
+  Example    : $toplevel = $genome->get_toplevel();
+  Description: Returns the toplevel for the assembly currently used
+
+  Returntype : ListRef of Bio::EnsEMBL::Slice
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_toplevel {
+  my $self = @_;
+  if (!defined $self->{'toplevel'}) {
+    my $sa = $self->db()->get_adaptor('Slice');
+    $self->{'toplevel'} = $sa->fetch_all('toplevel');
+  }
+  return $self->{'toplevel'};
+}
+
+
+=head2 get_karyotype
+
+  Arg [1]    : none
+  Example    : $karyotype = $genome->get_karyotype();
+  Description: Returns the karyotype for the assembly currently used
+
+  Returntype : ListRef of Bio::EnsEMBL::Slice
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_karyotype {
+  my $self = @_;
+  if (!defined $self->{'karyotype'}) {
+    my $sa = $self->db()->get_adaptor('Slice');
+    $self->{'karyotype'} = $sa->fetch_all_karyotype;
+  }
+  return $self->{'karyotype'};
+}
+
+=head2 get_coord_systems
+
+  Arg [1]    : none
+  Example    : $coord_systems = $genome->get_coord_systems();
+  Description: Returns the coord_systems for the assembly currently used
+
+  Returntype : ListRef of Bio::EnsEMBL::CoordSystem
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_coord_systems {
+  my $self = @_;
+  if (!defined $self->{'coord_systems'}) {
+    my $version = $self->version();
+    my $csa = $self->db->get_adaptor('CoordSystem');
+    $self->{'coord_systems'} = $csa->fetch_all_by_version($version);
+  }
+  return $self->{'coord_systems'};
+}
+
+=head2 _get_count
+
+  Arg [1]    : none
+  Example    : $count = $genome->_get_count('coding_cnt');
+  Description: Internal method to return a count for a given attribute code
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : At risk
+
+=cut
+
+sub _get_count {
+  my ($self, $code) = @_;
+  my $aa = $self->db()->get_adaptor('Attribute');
+  my $attributes = $aa->fetch_all_by_Object(undef, 'seq_region', $code);
+  my $count;
+  foreach my $attribute (@$attributes) {
+    $count += $attribute->value();
+  }
+  return $count;
+}
+
+=head2 get_coding_count
+
+  Arg [1]    : none
+  Example    : $coding_count = $genome->get_coding_count();
+  Description: Returns the number of coding genes in the current build
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_coding_count {
+  my ($self, $coding_count) = @_;
+  if (defined $coding_count) {
+    $self->{'coding_count'} = $coding_count;
+  }
+  if (!defined $self->{'coding_count'}) {
+    $self->{'coding_count'} = $self->_get_count('coding_cnt');
+  }
+  return $self->{'coding_count'};
+}
+
+
+=head2 get_snoncoding_count
+
+  Arg [1]    : none
+  Example    : $snoncoding_count = $genome->get_snoncoding_count();
+  Description: Returns the number of short non coding genes in the current build
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_snoncoding_count {
+  my ($self, $snoncoding_count) = @_;
+  if (defined $snoncoding_count) {
+    $self->{'snoncoding_count'} = $snoncoding_count;
+  }
+  if (!defined $self->{'snoncoding_count'}) {
+    $self->{'snoncoding_count'} = $self->_get_count('snoncoding_cnt');
+  }
+  return $self->{'snoncoding_count'};
+}
+
+=head2 get_lnoncoding_count
+
+  Arg [1]    : none
+  Example    : $lnoncoding_count = $genome->get_lnoncoding_count();
+  Description: Returns the number of long non coding genes in the current build
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_lnoncoding_count {
+  my ($self, $lnoncoding_count) = @_;
+  if (defined $lnoncoding_count) {
+    $self->{'lnoncoding_count'} = $lnoncoding_count;
+  }
+  if (!defined $self->{'lnoncoding_count'}) {
+    $self->{'lnoncoding_count'} = $self->_get_count('lnoncoding_cnt');
+  }
+  return $self->{'lnoncoding_count'};
+}
+
+=head2 get_pseudogene_count
+
+  Arg [1]    : none
+  Example    : $pseudogene_count = $genome->get_pseudogene_count();
+  Description: Returns the number of pseudogenes in the current build
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+
+sub get_pseudogene_count {
+  my ($self, $pseudogene_count) = @_;
+  if (defined $pseudogene_count) {
+    $self->{'pseudogene_count'} = $pseudogene_count;
+  }
+  if (!defined $self->{'pseudogene_count'}) {
+    $self->{'pseudogene_count'} = $self->_get_count('pseudogene_cnt');
+  }
+  return $self->{'pseudogene_count'};
+}
+
+=head2 get_alt_coding_count
+
+  Arg [1]    : none
+  Example    : $alt_coding_count = $genome->get_alt_coding_count();
+  Description: Returns the number of coding genes on alternate sequences
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_alt_coding_count {
+  my ($self, $alt_coding_count) = @_;
+  if (defined $alt_coding_count) {
+    $self->{'alt_coding_count'} = $alt_coding_count;
+  }
+  if (!defined $self->{'alt_coding_count'}) {
+    $self->{'alt_coding_count'} = $self->_get_count('coding_acnt');
+  }
+  return $self->{'alt_coding_count'};
+}
+
+
+=head2 get_alt_snoncoding_count
+
+  Arg [1]    : none
+  Example    : $alt_snoncoding_count = $genome->get_alt_snoncoding_count();
+  Description: Returns the number of short non coding genes on alternate sequences
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_alt_snoncoding_count {
+  my ($self, $alt_snoncoding_count) = @_;
+  if (defined $alt_snoncoding_count) {
+    $self->{'alt_snoncoding_count'} = $alt_snoncoding_count;
+  }
+  if (!defined $self->{'alt_snoncoding_count'}) {
+    $self->{'alt_snoncoding_count'} = $self->_get_count('snoncoding_acnt');
+  }
+  return $self->{'alt_snoncoding_count'};
+}
+
+=head2 get_alt_lnoncoding_count
+
+  Arg [1]    : none
+  Example    : $alt_lnoncoding_count = $genome->get_alt_lnoncoding_count();
+  Description: Returns the number of long non coding genes on alternate sequences
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_alt_lnoncoding_count {
+  my ($self, $alt_lnoncoding_count) = @_;
+  if (defined $alt_lnoncoding_count) {
+    $self->{'alt_lnoncoding_count'} = $alt_lnoncoding_count;
+  }
+  if (!defined $self->{'alt_lnoncoding_count'}) {
+    $self->{'alt_lnoncoding_count'} = $self->_get_count('lnoncoding_acnt');
+  }
+  return $self->{'alt_lnoncoding_count'};
+}
+
+
+=head2 get_alt_pseudogene_count
+
+  Arg [1]    : none
+  Example    : $alt_pseudogene_count = $genome->get_alt_pseudogene_count();
+  Description: Returns the number of pseudogenes on alternate sequences
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_alt_pseudogene_count {
+  my ($self, $alt_pseudogene_count) = @_;
+  if (defined $alt_pseudogene_count) {
+    $self->{'alt_pseudogene_count'} = $alt_pseudogene_count;
+  }
+  if (!defined $self->{'alt_pseudogene_count'}) {
+    $self->{'alt_pseudogene_count'} = $self->_get_count('pseudogene_acnt');
+  }
+  return $self->{'alt_pseudogene_count'};
+}
+
+=head2 get_snp_count
+
+  Arg [1]    : none
+  Example    : $snp_count = $genome->get_snp_count();
+  Description: Returns the number of snps in the current build
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_snp_count {
+  my ($self, $snp_count) = @_;
+  if (defined $snp_count) {
+    $self->{'snp_count'} = $snp_count;
+  }
+  if (!defined $self->{'snp_count'}) {
+    $self->{'snp_count'} = $self->_get_count('snp_count');
+  }
+  return $self->{'snp_count'};
+}
+
+
+=head2 get_prediction_count
+
+  Arg [1]    : (optional) logic_name
+  Arg [2]    : (optional) prediction_count
+  Example    : $prediction_count = $genome->get_prediction_count();
+  Description: Return the number of predicted genes in the current build
+               Can be restricted to a given analysis
+
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : Stable
+
+=cut
+
+sub get_prediction_count {
+  my ($self, $logic_name, $prediction_count) = @_;
+  if (defined $prediction_count) {
+    $self->{'prediction_count'} = $prediction_count;
+  }
+  if (!defined $self->{'prediction_count'}) {
+    my $constraint;
+    my $pa = $self->db->get_adaptor('PredictionTranscript');
+    if ($logic_name) {
+      my $analysis_adaptor = $self->get_adaptor('Analysis');
+      my $analysis = $analysis_adaptor->fetch_by_logic_name($logic_name);
+      $constraint = 'analysis_id = ' . $analysis->dbID;
+    }
+    $self->{'prediction_count'} = $pa->generic_count($constraint);
+  }
+  return $self->{'prediction_count'};
+}
+
+
+=head2 get_struct_count
+
+  Arg [1]    : none
+  Example    : $struct_count = $genome->_get_struct_count();
+  Description: Internal method to return the length for a type of slices
+  Returntype : integer
+  Exceptions : none
+  Caller     : general
+  Status     : At risk
+
+=cut
+
+sub get_struct_count {
+  my $self = @_;
+  my $slice_adaptor = $self->db->get_adaptor('Slice');
+  my $slices = $slice_adaptor->fetch_all('toplevel');
+  my $count;
+  foreach my $seq (@$slices) {
+    $count += scalar(@{ $seq->get_all_StructuralVariationFeatures() });
+  }
+  return $count;
+}
+
+
+1;
-- 
GitLab