From 80e8a271ad2d74057ad749398caab89818a423bd Mon Sep 17 00:00:00 2001 From: Magali Ruffier <mr6@ebi.ac.uk> Date: Wed, 7 Jan 2015 13:15:52 +0000 Subject: [PATCH] ENSCORESW-1193: added is_empty method to check if there is genome data available --- modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm | 30 ++++++++++++++++++++ modules/t/genomeContainer.t | 8 ++++++ 2 files changed, 38 insertions(+) diff --git a/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm b/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm index c49a1c82c8..b68ac21966 100644 --- a/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm +++ b/modules/Bio/EnsEMBL/DBSQL/GenomeContainer.pm @@ -632,6 +632,36 @@ sub _get_statistic { return \@results; } +=head2 is_empty + + Arg [1] : none + Example : $results = $genome->is_empty; + Description: Boolean to check if there is data in the genome container + Returntype : Boolean + Exceptions : none + Caller : general + Status : Stable + +=cut + +sub is_empty { + my $self = shift; + my $db = $self->db; + my $species_id = $self->db->species_id(); + my $is_empty = 0; + my $count_sql = q{ + SELECT count(*) FROM genome_statistics + }; + + my $sth = $self->prepare($count_sql); + $sth->execute(); + if ($sth->fetchrow()) { + $is_empty = 1; + } + $sth->finish(); + return $is_empty; +} + =head2 get_attrib Arg [1] : statistic diff --git a/modules/t/genomeContainer.t b/modules/t/genomeContainer.t index d91b0a3c25..87880d49a7 100644 --- a/modules/t/genomeContainer.t +++ b/modules/t/genomeContainer.t @@ -173,6 +173,14 @@ is(0, $empty_genome->has_karyotype, "Empty db does not have chromosomes"); is(1, $genome->is_high_coverage, "Human genebuild is high coverage"); is(0, $empty_genome->is_high_coverage, "Empty db is not high coverage"); + +# +# Test if there is data +# + +is(1, $genome->is_empty, "Human core database has genome data"); +is(0, $empty_genome->is_empty, "Empty database has no genome data"); + # # Test polyploid genome support # -- GitLab