diff --git a/modules/Bio/EnsEMBL/DBSQL/CoordSystemAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/CoordSystemAdaptor.pm index 685d8aea0a25193d2b3b94831166a9438638968a..49455208a482fdc9328c4066d4a3e6caac9df73c 100644 --- a/modules/Bio/EnsEMBL/DBSQL/CoordSystemAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/CoordSystemAdaptor.pm @@ -516,9 +516,31 @@ sub fetch_all_by_name { return $self->{'_name_cache'}->{$name} || []; } +=head2 fetch_all_by_version + Arg [1] : string $version + The version of the coordinate systems to retrieve. + Example : foreach my $cs (@{$csa->fetch_all_by_version('GRCh37')}){ + print $cs->name(), ' ', $cs->version(); + } + Description: Retrieves all coordinate systems of a particular version + Returntype : ArrayRef of Bio::EnsEMBL::CoordSystem objects + Exceptions : throw if no name argument provided + Caller : general + Status : Stable +=cut +sub fetch_all_by_version { + my ($self, $version) = @_; + throw "Version argument is required" if ! $version; + my $coord_systems = [ + grep { $_->version() eq $version } + map { $self->{_rank_cache}->{$_} } + sort keys %{$self->{_rank_cache}} + ]; + return $coord_systems; +} =head2 fetch_by_dbID diff --git a/modules/t/coordSystemAdaptor.t b/modules/t/coordSystemAdaptor.t index 91e6080bcb1cfc8426e6fbc377ae64ddf5f9d1ba..507055435d29121e0410d468ded295effb089e97 100644 --- a/modules/t/coordSystemAdaptor.t +++ b/modules/t/coordSystemAdaptor.t @@ -3,6 +3,7 @@ use strict; use Test::More; use Bio::EnsEMBL::Test::MultiTestDB; use Bio::EnsEMBL::Test::TestUtils; +use Test::Exception; our $verbose = 1; #set to 1 to turn on debug printouts @@ -176,6 +177,27 @@ ok( @{$new_path} == 2 && my $new_paths2 = $csa->store_mapping_path( $cs, $cln_cs ); ok( @{$new_paths2} == 0 ); # Should not update second time round +# +# Do some inserting of mock coord systems and +# do version retrieval +# +my $newcs_two = Bio::EnsEMBL::CoordSystem->new( + -NAME => 'newsystem_number_two', + -VERSION => 'NCBI35', + -DEFAULT => 0, + -SEQUENCE_LEVEL => 0, + -RANK => 11 +); +$csa->store($newcs_two); + +dies_ok { $csa->fetch_all_by_version() } 'fetch_all_by_version should die if not given a version to check'; +is_deeply($csa->fetch_all_by_version('NCBI35'), [ $cs, $newcs_two ], 'Checking version rank retrieval works'); +is_deeply( + $csa->fetch_all_by_version('NCBI33'), + [$csa->fetch_by_name('chromosome')], + 'Retrieval by name should return the same as version for NCBI33'); +is_deeply($csa->fetch_all_by_version('thisdoesnotexist'), [], 'Bogus coordinate system results in no results'); + $multi->restore('core', 'coord_system'); $multi->restore('core', 'meta');