From 313dc75e17bd652344995a4efa6c7f434cc9ffee Mon Sep 17 00:00:00 2001 From: Andrew Yates <ayates@ebi.ac.uk> Date: Fri, 27 Sep 2013 15:22:03 +0000 Subject: [PATCH] Deprecating a number of calls. Instead we want more API compatible calls --- modules/Bio/EnsEMBL/AltAlleleGroup.pm | 4 +- .../EnsEMBL/DBSQL/AltAlleleGroupAdaptor.pm | 127 +++++++++++++----- modules/t/altAlleleGroup.t | 24 ++-- 3 files changed, 105 insertions(+), 50 deletions(-) diff --git a/modules/Bio/EnsEMBL/AltAlleleGroup.pm b/modules/Bio/EnsEMBL/AltAlleleGroup.pm index 3414eb0e1e..a908141db4 100644 --- a/modules/Bio/EnsEMBL/AltAlleleGroup.pm +++ b/modules/Bio/EnsEMBL/AltAlleleGroup.pm @@ -459,7 +459,7 @@ sub get_all_Genes { } -=head2 get_all_Gene_ids +=head2 get_all_Genes_types Arg[1] : Boolean - Do not include representative gene in list of ids. Description : Fetches all the Gene objects within the allele group and their @@ -516,4 +516,4 @@ sub get_all_members { } -1; \ No newline at end of file +1; diff --git a/modules/Bio/EnsEMBL/DBSQL/AltAlleleGroupAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/AltAlleleGroupAdaptor.pm index 056d71c056..9f72fc83ce 100644 --- a/modules/Bio/EnsEMBL/DBSQL/AltAlleleGroupAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/AltAlleleGroupAdaptor.pm @@ -32,16 +32,16 @@ Alternative allele groupings my $aag_adaptor = Bio::EnsEMBL::Registry->get_DBAdaptor("Human","core","AltAlleleGroup"); # For a known Gene, find the reference alternative allele - my $aag = $aag_adaptor->fetch_Group_by_dbID($gene->dbID); + my $aag = $aag_adaptor->fetch_by_gene_id($gene->dbID); my $reference_gene = $aag->get_ref_Gene; # Get a list of AltAlleleGroups - my $list = $aag_adaptor->fetch_all_Groups_by_type('IS_REPRESENTATIVE'); - $list = $aag_adaptor->fetch_all_Groups(); + my $list = $aag_adaptor->fetch_all_('IS_REPRESENTATIVE'); + $list = $aag_adaptor->fetch_all(); my $dbID = $aag_adaptor->store($aag); - $aag = $aag_adaptor->fetch_Group_by_id($dbID); + $aag = $aag_adaptor->fetch_by_dbID($dbID); $aag_adaptor->remove($aag); =head1 DESCRIPTION @@ -59,23 +59,41 @@ use warnings; use base qw/Bio::EnsEMBL::DBSQL::BaseAdaptor/; use Bio::EnsEMBL::AltAlleleGroup; -use Bio::EnsEMBL::Utils::Exception qw/throw/; +use Bio::EnsEMBL::Utils::Exception qw/throw deprecate/; use Bio::EnsEMBL::Utils::Scalar qw/assert_ref/; use DBI qw( :sql_types ); =head2 fetch_all_Groups Arg[1] : (optional) String - type of group + Description : DEPRECATED. Please use fetch_all() + Returntype : ArrayRef of Bio::EnsEMBL::AltAlleleGroup + +=cut + +sub fetch_all_Groups { + my ($self, $type) = @_; + deprecate('Please use fetch_all()'); + return $self->fetch_all($type); +} + +=head2 fetch_all + + Arg[1] : (optional) String - type of group + Restrict group fetches to just one type. Technically it selects + out mixed-annotation groups where a single member contains that type. Description : Fetches all the alt-allele groups, creates objects to represent - them and returns them in a list + them and returns them in a list. Specifying a group type + identifies all groups containing a member of this type. It + does not filter out the other members + Multispecies support is triggered by the is_multispecies flag and species_id of the DBAdaptor. - Specifying a group type identifies all groups containing a - member of this type. It does not filter out the other members - Returntype : Listref of Bio::EnsEMBL::AltAlleleGroup + Returntype : ArrayRef of Bio::EnsEMBL::AltAlleleGroup + =cut -sub fetch_all_Groups { +sub fetch_all { my $self = shift; my $type = shift; @@ -103,16 +121,18 @@ sub fetch_all_Groups { WHERE c.species_id = ? AND b.attrib = ? ); } - $get_all_sql = q( - SELECT DISTINCT alt_allele_group_id FROM alt_allele a - JOIN (gene g, seq_region s, coord_system c) - ON ( - c.coord_system_id = s.coord_system_id - AND s.seq_region_id = g.seq_region_id - AND g.gene_id = a.gene_id - ) - WHERE c.species_id = ? - ); + else { + $get_all_sql = q( + SELECT DISTINCT alt_allele_group_id FROM alt_allele a + JOIN (gene g, seq_region s, coord_system c) + ON ( + c.coord_system_id = s.coord_system_id + AND s.seq_region_id = g.seq_region_id + AND g.gene_id = a.gene_id + ) + WHERE c.species_id = ? + ); + } } else { if ($type) { $get_all_sql = q(SELECT DISTINCT alt_allele_group_id @@ -144,7 +164,7 @@ sub fetch_all_Groups { $sth->bind_col(1, \$group_id ); while ( $sth->fetch() ) { - my $aag = $self->fetch_Group_by_id($group_id); + my $aag = $self->fetch_by_dbID($group_id); push @group_list, $aag; } $sth->finish; @@ -154,22 +174,34 @@ sub fetch_all_Groups { =head2 fetch_all_Groups_by_type Arg[1] : String - type of group - Description : Convenience method for restricting group fetches to just one - type. Technically it selects out mixed-annotation groups where - a single member contains that type. - Returntype : Listref of Bio::EnsEMBL::AltAlleleGroup + Description : DEPRECATED. Please use fetch_all() + Returntype : ArrayRef of Bio::EnsEMBL::AltAlleleGroup + =cut sub fetch_all_Groups_by_type { - my $self = shift; - my $type = shift; # refers to alt_allele_attrib type - - my $group_list = $self->fetch_all_Groups($type); + my ($self, $type) = @_; + deprecate('Please use fetch_all()'); + my $group_list = $self->fetch_all($type); return $group_list; } =head2 fetch_Group_by_id + Arg[1] : AltAlleleGroup dbID. + Description : DEPRECATED. Please use fetch_by_dbID + Returntype : Bio::EnsEMBL::AltAlleleGroup + +=cut + +sub fetch_Group_by_id { + my ($self, $group_id) = @_; + deprecate('Please use fetch_by_dbID()'); + return $self->fetch_by_dbID($group_id); +} + +=head2 fetch_by_dbID + Arg[1] : AltAlleleGroup dbID. Description : Creates and returns an AltAlleleGroup for the given group id @@ -177,7 +209,7 @@ sub fetch_all_Groups_by_type { =cut -sub fetch_Group_by_id { +sub fetch_by_dbID { my $self = shift; my $group_id = shift; @@ -225,10 +257,33 @@ sub fetch_Group_by_id { return; } +=head2 fetch_Group_by_Gene_dbID + + Arg[1] : Integer Gene ID of the member to query by + Description : DEPRECATED. Please use fetch_by_gene_id + Returntype : Bio::EnsEMBL::AltAlleleGroup + +=cut + + sub fetch_Group_by_Gene_dbID { - my $self = shift; - my $gene_id = shift; - + my ($self, $gene_id) = @_; + deprecate('Please use fetch_by_gene_id()'); + return $self->fetch_by_gene_id($gene_id); +} + +=head2 fetch_by_gene_id + + Arg[1] : Integer Gene ID of the member to query by + Description : Creates and returns an AltAlleleGroup which contains + the specified gene member + Returntype : Bio::EnsEMBL::AltAlleleGroup + +=cut + +sub fetch_by_gene_id { + my ($self, $gene_id) = @_; + my $gene_id_sql = q( SELECT alt_allele_group_id FROM alt_allele WHERE gene_id = ? @@ -242,14 +297,14 @@ sub fetch_Group_by_Gene_dbID { $sth->fetch; $sth->finish; if (!$@ && $group_id) { - return $self->fetch_Group_by_id($group_id); + return $self->fetch_by_dbID($group_id); } return; } =head2 store - Arg[0] : Bio::EnsEMBL::AltAlleleGroup + Arg[1] : Bio::EnsEMBL::AltAlleleGroup Description: Used for persisting new groups to the database. It updates the dbID of the object handed to it to match the database. @@ -373,4 +428,4 @@ sub _tables { return (['alt_allele', 'a'], ['alt_allele_group', 'g'], ['alt_allele_attrib', 'b']); } -1; \ No newline at end of file +1; diff --git a/modules/t/altAlleleGroup.t b/modules/t/altAlleleGroup.t index 6169376b6f..fea128be57 100644 --- a/modules/t/altAlleleGroup.t +++ b/modules/t/altAlleleGroup.t @@ -86,7 +86,7 @@ ok($db, 'DB was retrieved'); my $aaga = $db->get_adaptor('AltAlleleGroup'); # Test data consists of a single group, of type AUTOMATIC, with a reference Allele and 3 others -my $group_list = $aaga->fetch_all_Groups; +my $group_list = $aaga->fetch_all; my $aag = $group_list->[0]; is($aag->rep_Gene_id, 18256,"Check for correct selection of allele"); @@ -101,26 +101,26 @@ $gene = $gene_list->[0]; is (ref($gene),'Bio::EnsEMBL::Gene',"Returned object type from get_all_Genes"); ok ($gene->dbID == 18256,"Ensure Gene objects acquire correct information"); -# test fetch_all_Groups_by_type -$group_list = $aaga->fetch_all_Groups_by_type('UNLIKELY STRING'); +# test fetch_all +$group_list = $aaga->fetch_all('UNLIKELY STRING'); ok(scalar(@{$group_list}) == 0,"Try outlandish typed group lookup"); -$group_list = $aaga->fetch_all_Groups_by_type('HAS_CODING_POTENTIAL'); +$group_list = $aaga->fetch_all('HAS_CODING_POTENTIAL'); ok(scalar(@$group_list) == 1,"Try known group type lookup"); # fetch_Group_by_id $aag = $group_list->[0]; my $group_id = $aag->dbID; -my $new_aag = $aaga->fetch_Group_by_id($group_id); +my $new_aag = $aaga->fetch_by_dbID($group_id); is_deeply($aag, $new_aag, "Compare previously fetched group with group found by using the dbID"); -$aag = $aaga->fetch_Group_by_id(undef); +$aag = $aaga->fetch_by_dbID(undef); ok(!defined($aag), "See what happens if no argument is given"); # fetch_Group_by_Gene_dbID -$aag = $aaga->fetch_all_Groups->[0]; -$new_aag = $aaga->fetch_Group_by_Gene_dbID(18257); +$aag = $aaga->fetch_all->[0]; +$new_aag = $aaga->fetch_by_gene_id(18257); is_deeply($new_aag,$aag,"Check single gene ID returns entire group correctly"); # check store method @@ -128,7 +128,7 @@ my $dbID = $aaga->store($group); ok($dbID, 'A dbID was returned from the store method'); { - my $aag2 = $aaga->fetch_Group_by_id($dbID); + my $aag2 = $aaga->fetch_by_dbID($dbID); is_deeply($aag2->get_all_members,$group->get_all_members,"Compare stored with original"); $group->add_member(4, {}); my $update_dbID = $aaga->update($group); @@ -137,11 +137,11 @@ ok($dbID, 'A dbID was returned from the store method'); $group->remove_member(4); $aaga->remove($group); -ok(! defined $aaga->fetch_Group_by_id($dbID), 'Using a deleted ID means no group returned'); +ok(! defined $aaga->fetch_by_dbID($dbID), 'Using a deleted ID means no group returned'); my $new_dbID = $aaga->store($group); cmp_ok($new_dbID, '!=', $dbID, 'Should have been assgined a new ID'); -my $aag2 = $aaga->fetch_Group_by_id($new_dbID); +my $aag2 = $aaga->fetch_by_dbID($new_dbID); my $gene_ids = $aag2->get_all_Gene_ids(); eq_or_diff($gene_ids,[1,2,3], "Update and re-retrieve the same AltAlleleGroup") or diag explain $gene_ids; @@ -149,7 +149,7 @@ eq_or_diff($gene_ids,[1,2,3], "Update and re-retrieve the same AltAlleleGroup") # Proper test data is hard to fabricate and no samples exist. $aaga->db->is_multispecies(1); -$group_list = $aaga->fetch_all_Groups; +$group_list = $aaga->fetch_all; $aag = $group_list->[0]; ok(scalar(@$group_list) == 1, "Pretend multi-species fetch returns same groups as normal."); -- GitLab