From ecd21be477ae127db4a2c05b4bb5f914163a0c22 Mon Sep 17 00:00:00 2001 From: Ian Longden <ianl@sanger.ac.uk> Date: Wed, 3 Jan 2007 13:34:48 +0000 Subject: [PATCH] Added optional argument to get_all_DBEntries and get_all_DBLinks which is the database name. Use like in sql statment so percentage sign can be used for wild cards etc. --- modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm | 25 ++++++++++------ modules/Bio/EnsEMBL/Gene.pm | 32 ++++++++++++++------- modules/Bio/EnsEMBL/Transcript.pm | 21 +++++++++----- modules/Bio/EnsEMBL/Translation.pm | 17 +++++++---- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm index f0f80fafb5..e4994a6e5f 100644 --- a/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/DBEntryAdaptor.pm @@ -474,6 +474,7 @@ sub exists { Arg [1] : Bio::EnsEMBL::Gene $gene (The gene to retrieve DBEntries for) + Arg [2] : optional external database name Example : @db_entries = @{$db_entry_adaptor->fetch_by_Gene($gene)}; Description: This returns a list of DBEntries associated with this gene. Note that this method was changed in release 15. Previously @@ -489,19 +490,20 @@ sub exists { =cut sub fetch_all_by_Gene { - my ( $self, $gene ) = @_; + my ( $self, $gene, $ex_db_reg ) = @_; if(!ref($gene) || !$gene->isa('Bio::EnsEMBL::Gene')) { throw("Bio::EnsEMBL::Gene argument expected."); } - return $self->_fetch_by_object_type($gene->dbID(), 'Gene'); + return $self->_fetch_by_object_type($gene->dbID(), 'Gene', $ex_db_reg); } =head2 fetch_all_by_Transcript Arg [1] : Bio::EnsEMBL::Transcript + Arg [2] : optional external database name Example : @db_entries = @{$db_entry_adaptor->fetch_by_Gene($trans)}; Description: This returns a list of DBEntries associated with this transcript. Note that this method was changed in release 15. @@ -517,13 +519,13 @@ sub fetch_all_by_Gene { =cut sub fetch_all_by_Transcript { - my ( $self, $trans ) = @_; + my ( $self, $trans, $ex_db_reg ) = @_; if(!ref($trans) || !$trans->isa('Bio::EnsEMBL::Transcript')) { throw("Bio::EnsEMBL::Transcript argument expected."); } - return $self->_fetch_by_object_type( $trans->dbID(), 'Transcript'); + return $self->_fetch_by_object_type( $trans->dbID(), 'Transcript', $ex_db_reg); } @@ -531,6 +533,7 @@ sub fetch_all_by_Transcript { Arg [1] : Bio::EnsEMBL::Translation $trans (The translation to fetch database entries for) + Arg [2] : optional external database name Example : @db_entries = @{$db_entry_adptr->fetch_by_Translation($trans)}; Description: Retrieves external database entries for an EnsEMBL translation Returntype : listref of Bio::EnsEMBL::DBEntries; may be of type IdentityXref if @@ -542,7 +545,7 @@ sub fetch_all_by_Transcript { =cut sub fetch_all_by_Translation { - my ( $self, $trans ) = @_; + my ( $self, $trans, $ex_db_reg ) = @_; if(!ref($trans) || !$trans->isa('Bio::EnsEMBL::Translation')) { throw('Bio::EnsEMBL::Translation argument expected.'); @@ -551,7 +554,7 @@ sub fetch_all_by_Translation { warning( "Cannot fetch_all_by_Translation without a dbID" ); return []; } - return $self->_fetch_by_object_type( $trans->dbID(), 'Translation' ); + return $self->_fetch_by_object_type( $trans->dbID(), 'Translation', $ex_db_reg ); } @@ -661,6 +664,7 @@ sub remove_from_object { Arg [1] : string $ensID Arg [2] : string $ensType (object type to be returned) + Arg [3] : optional $exdbname (external database name) Example : $self->_fetch_by_object_type( $translation_id, 'Translation' ) Description: Fetches DBEntry by Object type Returntype : arrayref of DBEntry objects; may be of type IdentityXref if @@ -674,7 +678,7 @@ sub remove_from_object { =cut sub _fetch_by_object_type { - my ( $self, $ensID, $ensType ) = @_; + my ( $self, $ensID, $ensType, $exdbname ) = @_; my @out; if (!defined($ensID)) { @@ -683,7 +687,8 @@ sub _fetch_by_object_type { if (!defined($ensType)) { throw("Can't fetch_by_EnsObject_type without a type"); } - my $sth = $self->prepare(" +# my $sth = $self->prepare(" + my $sql = (<<SSQL); SELECT xref.xref_id, xref.dbprimary_acc, xref.display_label, xref.version, xref.description, exDB.dbprimary_acc_linkable, exDB.display_label_linkable, exDB.priority, @@ -703,7 +708,9 @@ sub _fetch_by_object_type { AND xref.external_db_id = exDB.external_db_id AND oxr.ensembl_id = ? AND oxr.ensembl_object_type = ? - "); +SSQL + $sql .= " AND exDB.db_name like '".$exdbname."' " if($exdbname); + my $sth = $self->prepare($sql); $sth->bind_param(1,$ensID,SQL_INTEGER); $sth->bind_param(2,$ensType,SQL_VARCHAR); diff --git a/modules/Bio/EnsEMBL/Gene.pm b/modules/Bio/EnsEMBL/Gene.pm index cc863c5379..90c2564d15 100755 --- a/modules/Bio/EnsEMBL/Gene.pm +++ b/modules/Bio/EnsEMBL/Gene.pm @@ -435,23 +435,29 @@ sub add_DBEntry { =cut sub get_all_DBEntries { - my $self = shift; + my ($self, $db_name_exp) = @_; + my $cache_name = "dbentries"; + if(defined($db_name_exp)){ + $cache_name .= $db_name_exp; + } # if not cached, retrieve all of the xrefs for this gene - if(!defined $self->{'dbentries'} && $self->adaptor()) { - $self->{'dbentries'} = - $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Gene($self); + if(!defined $self->{$cache_name} && $self->adaptor()) { + $self->{$cache_name} = + $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Gene($self,$db_name_exp); } - $self->{'dbentries'} ||= []; + $self->{$cache_name} ||= []; - return $self->{'dbentries'}; + return $self->{$cache_name}; } =head2 get_all_DBLinks Example : @dblinks = @{ $gene->get_all_DBLinks }; + : @dblinks = @{ $gene->get_all_DBLinks("Uniprot%") }; + Arg [1] : <optional> database name use % for wild card as sent to sql directly Description: Retrieves _all_ related DBEntries for this gene. This includes all DBEntries that are associated with the transcripts and corresponding translations of this gene. @@ -459,6 +465,11 @@ sub get_all_DBEntries { If you only want to retrieve the DBEntries associated with the gene (and not the transcript and translations) then you should use the get_all_DBEntries call instead. + + Note: Each entry may be listed more than once. No uniqueness checks are done. + Also if you put in an incorrect external database name no checks are done + to see if this exists, you will just get an empty list. + Returntype : Listref of Bio::EnsEMBL::DBEntry objects Exceptions : none Caller : general @@ -468,15 +479,16 @@ sub get_all_DBEntries { sub get_all_DBLinks { my $self = shift; + my $db_name_exp = shift; - my @links = @{$self->get_all_DBEntries()}; + my @links = @{$self->get_all_DBEntries($db_name_exp)}; # add all of the transcript and translation xrefs to the return list - foreach my $transc (@{$self->get_all_Transcripts()}) { - push @links, @{$transc->get_all_DBEntries}; + foreach my $transc (@{$self->get_all_Transcripts}) { + push @links, @{$transc->get_all_DBEntries($db_name_exp)}; my $transl = $transc->translation(); - push @links, @{$transl->get_all_DBEntries} if($transl); + push @links, @{$transl->get_all_DBEntries($db_name_exp)} if($transl); } return \@links; diff --git a/modules/Bio/EnsEMBL/Transcript.pm b/modules/Bio/EnsEMBL/Transcript.pm index c2a0ea680c..31ff92ffe2 100755 --- a/modules/Bio/EnsEMBL/Transcript.pm +++ b/modules/Bio/EnsEMBL/Transcript.pm @@ -180,13 +180,14 @@ sub new { sub get_all_DBLinks { my $self = shift; + my $ex_db_exp = shift; my @links; - push @links, @{$self->get_all_DBEntries}; + push @links, @{$self->get_all_DBEntries($ex_db_exp)}; my $transl = $self->translation(); - push @links, @{$transl->get_all_DBEntries} if($transl); + push @links, @{$transl->get_all_DBEntries($ex_db_exp)} if($transl); @links = sort {_compare_xrefs()} @links; @@ -214,16 +215,22 @@ sub get_all_DBLinks { sub get_all_DBEntries { my $self = shift; + my $ex_db_exp = shift; + my $cache_name = "dbentries"; + + if(defined($ex_db_exp)){ + $cache_name .= $ex_db_exp; + } # if not cached, retrieve all of the xrefs for this gene - if(!defined $self->{'dbentries'} && $self->adaptor()) { - $self->{'dbentries'} = - $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Transcript($self); + if(!defined $self->{$cache_name} && $self->adaptor()) { + $self->{$cache_name} = + $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Transcript($self, $ex_db_exp); } - $self->{'dbentries'} ||= []; + $self->{$cache_name} ||= []; - return $self->{'dbentries'}; + return $self->{$cache_name}; } diff --git a/modules/Bio/EnsEMBL/Translation.pm b/modules/Bio/EnsEMBL/Translation.pm index f0f3908483..5a218516e7 100755 --- a/modules/Bio/EnsEMBL/Translation.pm +++ b/modules/Bio/EnsEMBL/Translation.pm @@ -337,21 +337,28 @@ sub transform { sub get_all_DBEntries { my $self = shift; + my $ex_db_exp = shift; + + my $cache_name = "dbentries"; + + if(defined($ex_db_exp)){ + $cache_name .= $ex_db_exp; + } #if not cached, retrieve all of the xrefs for this gene - if(!defined $self->{'dbentries'}) { + if(!defined $self->{$cache_name}) { my $adaptor = $self->adaptor(); my $dbID = $self->dbID(); return [] if(!$adaptor || !$dbID); - $self->{'dbentries'} = - $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Translation($self); + $self->{$cache_name} = + $self->adaptor->db->get_DBEntryAdaptor->fetch_all_by_Translation($self, $ex_db_exp); } - $self->{'dbentries'} ||= []; + $self->{$cache_name} ||= []; - return $self->{'dbentries'}; + return $self->{$cache_name}; } -- GitLab