From 416140567c9cf8a0669627a67404645dcc3ebe23 Mon Sep 17 00:00:00 2001 From: Monika Komorowska <mk8@sanger.ac.uk> Date: Fri, 16 Mar 2012 12:00:39 +0000 Subject: [PATCH] added method fetch_all_by_display_label and changed fetch_by_display_label to return a gene on the reference slice if there is one --- modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm | 44 ++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm index 81301457e2..c82faefe78 100644 --- a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm +++ b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm @@ -182,8 +182,9 @@ sub list_seq_region_ids { Arg [1] : String $label - display label of gene to fetch Example : my $gene = $geneAdaptor->fetch_by_display_label("BRCA2"); Description: Returns the gene which has the given display label or undef if - there is none. If there are more than 1, only the first is - reported. + there is none. If there are more than 1, the gene on the + reference slice is reported or if none are on the reference, + the first one is reported. Returntype : Bio::EnsEMBL::Gene Exceptions : none Caller : general @@ -197,12 +198,49 @@ sub fetch_by_display_label { my $constraint = "x.display_label = ? AND g.is_current = 1"; $self->bind_param_generic_fetch($label,SQL_VARCHAR); - my ($gene) = @{ $self->generic_fetch($constraint) }; + my @genes = @{ $self->generic_fetch($constraint) }; + my $gene; + if (scalar(@genes) > 1) { + foreach my $gene_tmp (@genes) { + if ($gene_tmp->slice->is_reference) { + $gene = $gene_tmp; + } + last if ($gene); + } + if (!$gene) { + $gene = @genes[0]; + } + + } elsif (scalar(@genes) == 1) { + $gene = @genes[0]; + } return $gene; } +=head2 fetch_all_by_display_label + + Arg [1] : String $label - display label of genes to fetch + Example : my @genes = @{$geneAdaptor->fetch_by_display_label("PPP1R2P1")}; + Description: Returns all genes which have the given display label or undef if + there are none. + Returntype : listref of Bio::EnsEMBL::Gene objects + Exceptions : none + Caller : general + Status : Stable + +=cut + +sub fetch_all_by_display_label { + my $self = shift; + my $label = shift; + + my $constraint = "x.display_label = ? AND g.is_current = 1"; + $self->bind_param_generic_fetch($label,SQL_VARCHAR); + my $genes = $self->generic_fetch($constraint) ; + return $genes; +} =head2 fetch_by_stable_id -- GitLab