diff --git a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm index 59323535ec9fb2f40e230d4da4abf1b4c35f3f7d..f2075b09898e5c70824d9f61fe149503b5c059f8 100644 --- a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm @@ -901,6 +901,85 @@ sub deleteObj { #flush the cache %{$self->{'_slice_gene_cache'}} = (); } + + +=head2 get_external_name + + Arg [1] : int $dbID + the database identifier of the gene whose external name is + sought + Example : $external_name = $gene_adaptor->get_external_name(42); + Description: Retrieves the external name for a gene. This is implemented + by joining across the xref and gene tables, using the + relevant_xref_id column. + Returntype : string + Exceptions : thrown if $dbId arg is not defined + Caller : general + +=cut + +sub get_external_name { + my ($self, $dbID) = @_; + + if( !defined $dbID ) { + $self->throw("Must call with a dbID"); + } + + my $sth = $self->prepare("SELECT x.display_label + FROM gene g, + xref x + WHERE g.gene_id = ? + AND g.relevant_xref_id = x.xref_id + "); + $sth->execute($dbID); + + my ($xref) = $sth->fetchrow_array(); + if( !defined $xref ) { + return undef; + } + + return $xref; +} + +=head2 get_external_dbname + + Arg [1] : int $dbID + the database identifier of the gene for which the name of + external db from which its external name is derived. + Example : $external_dbname = $gene_adaptor->get_external_dbname(42); + Description: Retrieves the external db name for a gene from which its external + name is derived.. This is implemented by joining across the xref, + gene and external_db tables, using the relevant_xref_id column. + Returntype : string + Exceptions : thrown if $dbId arg is not defined + Caller : general + +=cut + +sub get_external_dbname { + my ($self, $dbID) = @_; + + if( !defined $dbID ) { + $self->throw("Must call with a dbID"); + } + + my $sth = $self->prepare("SELECT e.db_name + FROM gene g, + xref x, + external_db e + WHERE g.gene_id = ? + AND g.relevant_xref_id = x.xref_id + AND x.external_db_id = e.external_db_id + "); + $sth->execute($dbID); + + my ($db_name) = $sth->fetchrow_array(); + if( !defined $db_name ) { + return undef; + } + + return $db_name; +} diff --git a/modules/Bio/EnsEMBL/Gene.pm b/modules/Bio/EnsEMBL/Gene.pm index 9cffc9a869be6b3404804cb359ed20a70ec3e6b5..8f3e1e55a69af42ebd50cf0d2075276a2e8d0ac3 100755 --- a/modules/Bio/EnsEMBL/Gene.pm +++ b/modules/Bio/EnsEMBL/Gene.pm @@ -380,11 +380,7 @@ sub dbID { Arg [1] : string $external_name Example : none - Description: get/set for attribute external_name. It initially calculates - the longest transcript for the gene in question and then - delegates the call to the external_name method on Transcript. - Species dependant searching is handled by this method on - Transcript. + Description: get/set for attribute external_name. Returntype : string Exceptions : none Caller : general @@ -392,6 +388,18 @@ sub dbID { =cut sub external_name { + my ($self, $ext_name) = @_; + + if(defined $ext_name) { + $self->{'_ext_name'} = $ext_name; + } + + if( exists $self->{'_ext_name'} ) { + return $self->{'_ext_name'}; + } + + $self->{'_ext_name'} = $self->adaptor->get_external_name($self->dbID); + return $self->{'_ext_name'}; } @@ -401,11 +409,7 @@ sub external_name { Arg [1] : string $external_db Example : none Description: get/set for attribute external_db. The db is the one that - belongs to the external_name. It initially calculates - the longest transcript for the gene in question and then - delegates the call to the external_db method on Transcript. - Species dependant searching is handled by this method on - Transcript. + belongs to the external_name. Returntype : string Exceptions : none Caller : general @@ -413,7 +417,18 @@ sub external_name { =cut sub external_db { - my ($self, $arg ) = @_; + my ($self, $ext_dbname) = @_; + + if(defined $ext_dbname) { + $self->{'_ext_dbname'} = $ext_dbname; + } + + if( exists $self->{'_ext_dbname'} ) { + return $self->{'_ext_dbname'}; + } + + $self->{'_ext_dbname'} = $self->adaptor->get_external_dbname($self->dbID); + return $self->{'_ext_dbname'}; }