From 9825a9c1b372f78abc6e4a2349eb52063b2638b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?= <ak4@sanger.ac.uk> Date: Tue, 25 Oct 2011 12:54:07 +0000 Subject: [PATCH] Throw an exception if the real species name for an alias can not be found in get_adaptor(). Suggested by jm18 on dev. Also reformat get_alias() and get_DBAdaptor(). --- modules/Bio/EnsEMBL/Registry.pm | 38 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/modules/Bio/EnsEMBL/Registry.pm b/modules/Bio/EnsEMBL/Registry.pm index 74eba4c9bd..0baf778bd2 100644 --- a/modules/Bio/EnsEMBL/Registry.pm +++ b/modules/Bio/EnsEMBL/Registry.pm @@ -572,12 +572,12 @@ sub add_DBAdaptor { =cut sub get_DBAdaptor { - my ( $class, $species, $group , $no_alias_check) = @_; -throw 'Species not defined.' if ! defined $species; + my ( $class, $species, $group, $no_alias_check ) = @_; + throw 'Species not defined.' if !defined $species; -# if(!defined($no_alias_check) or !$no_alias_check){ - $species = $class->get_alias($species, $no_alias_check) || $species; -# } + #if ( !defined($no_alias_check) or !$no_alias_check ) { + $species = $class->get_alias( $species, $no_alias_check ) || $species; + #} return $registry_register{_SPECIES}{$species}{ lc($group) }{'_DB'}; } @@ -936,7 +936,12 @@ sub add_adaptor { sub get_adaptor { my ( $class, $species, $group, $type ) = @_; - $species = $class->get_alias($species); + my $ispecies = $class->get_alias($species); + + if ( !defined($species) ) { + throw("Can not find internal name for species '$species'"); + } + else { $species = $ispecies } my %dnadb_adaptors = ( 'sequence' => 1, @@ -1130,19 +1135,22 @@ sub remove_alias{ =cut -sub get_alias{ - my ($class, $key, $no_warn) = @_; +sub get_alias { + my ( $class, $key, $no_warn ) = @_; - if(!defined($registry_register{'_ALIAS'}{lc($key)})){ - if((!defined( $registry_register{_SPECIES}{ lc($key) })) and (!defined ($registry_register{_ALIAS}{ lc($key) }))){ - warn "$key is not a valid species name for this instance\n" if((!defined($no_warn)) or (!$no_warn)); + if ( !defined( $registry_register{'_ALIAS'}{ lc($key) } ) ) { + if ( ( !defined( $registry_register{_SPECIES}{ lc($key) } ) ) and + ( !defined( $registry_register{_ALIAS}{ lc($key) } ) ) ) + { + if ( ( !defined($no_warn) ) or ( !$no_warn ) ) { + warn "$key is not a valid species name for this instance\n"; + } return; } - else{ - return $key; - } + else { return $key } } - return $registry_register{'_ALIAS'}{lc($key)}; + + return $registry_register{'_ALIAS'}{ lc($key) }; } =head2 get_all_aliases -- GitLab