Skip to content
Snippets Groups Projects
Commit 11867896 authored by Andy Yates's avatar Andy Yates
Browse files

Brought in a new method for getting single value meta items from the meta...

Brought in a new method for getting single value meta items from the meta table. This is then used in MetaContainer for just about every call reducing duplicated logic.
parent fac15c51
No related branches found
No related tags found
No related merge requests found
......@@ -140,6 +140,42 @@ sub list_value_by_key {
return \@result;
} ## end sub list_value_by_key
=head2 single_value_by_key
Arg [1] : string $key
the key to obtain values from the meta table with
Arg [2] : boolean $warn
If true will cause the code to warn the non-existence of a value
Example : my $value = $mc->single_value_by_key($key);
Description: Gets a value for a key. Can be anything
Returntype : Scalar
Exceptions : Raised if more than 1 meta item is returned
=cut
sub single_value_by_key {
my ($self, $key, $warn) = @_;
my $results = $self->list_value_by_key($key);
if(defined $results) {
my $count = scalar(@{$results});
if($count == 1) {
return $results->[0];
}
elsif($count == 0) {
if($warn) {
my $group = $self->db()->group();
my $msg = sprintf(qq{Please insert meta_key '%s' in meta table at %s db\n}, $key, $group);
warning($msg);
}
}
else {
my $values = join(q{,}, @{$results});
throw sprintf(q{Found the values [%s] for the key '%s'}, $values, $key);
}
}
return;
} ## end sub single_value_by_key
=head2 store_key_value
Arg [1] : string $key
......
......@@ -70,15 +70,7 @@ use Bio::Species;
sub get_production_name {
my ($self) = @_;
my $listref = $self->list_value_by_key('species.production_name');
my $name;
if ( defined($listref) && @{$listref} ) {
$name = $listref->[0];
}
return $name;
return $self->single_value_by_key('species.production_name');
}
=head2 get_short_name
......@@ -95,15 +87,7 @@ sub get_production_name {
sub get_short_name {
my ($self) = @_;
my $listref = $self->list_value_by_key('species.short_name');
my $name;
if ( defined($listref) && @{$listref} ) {
$name = $listref->[0];
}
return $name;
return $self->single_value_by_key('species.short_name');
}
=head2 get_common_name
......@@ -119,18 +103,10 @@ sub get_short_name {
sub get_common_name {
my ($self) = @_;
my $listref = $self->list_value_by_key('species.common_name');
my $name;
if ( defined($listref) && @{$listref} ) {
$name = $listref->[0];
}
return $name;
return $self->single_value_by_key('species.common_name');
}
=head2 get_short_name
=head2 get_scientific_name
Args : none
Example : $species = $meta_container->get_scientific_name();
......@@ -142,15 +118,7 @@ sub get_common_name {
=cut
sub get_scientific_name {
my ($self) = @_;
my $listref = $self->list_value_by_key('species.scientific_name');
my $name;
if ( defined($listref) && @{$listref} ) {
$name = $listref->[0];
}
return $name;
return $self->single_value_by_key('species.scientific_name');
}
=head2 get_Species
......@@ -196,16 +164,8 @@ sub get_Species {
=cut
sub get_taxonomy_id {
my $self = shift;
my $arrRef = $self->list_value_by_key( 'species.taxonomy_id' );
if( @$arrRef ) {
return $arrRef->[0];
} else {
warning("Please insert meta_key 'species.taxonomy_id' " .
"in meta table at core db.\n");
}
my ($self) = @_;
return $self->single_value_by_key('species.taxonomy_id', 1);
}
......@@ -240,15 +200,8 @@ sub get_default_assembly {
#
sub get_max_assembly_contig {
my $self = shift;
deprecate('This method should either be fixed or removed');
my $value_list = $self->list_value_by_key( "assembly.maxcontig" );
if( @$value_list ) {
return $value_list->[0];
} else {
return undef;
}
return $self->single_value_by_key('assembly.maxcontig');
}
=head2 get_genebuild
......@@ -264,16 +217,8 @@ sub get_max_assembly_contig {
=cut
sub get_genebuild {
my $self = shift;
my $arrRef = $self->list_value_by_key( 'genebuild.start_date' );
if( @$arrRef ) {
return $arrRef->[0];
} else {
warning("Please insert meta_key 'genebuild.start_date' " .
"in meta table at core db.\n");
}
my ($self) = @_;
return $self->single_value_by_key('genebuild.start_date', 1);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment