From 5868233e60f95d48ad03914835afcfc11c2facd7 Mon Sep 17 00:00:00 2001
From: Kieron Taylor <ktaylor@ebi.ac.uk>
Date: Fri, 15 Mar 2013 16:57:22 +0000
Subject: [PATCH] Added fetch_all_by_description with simple testcase.

---
 modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm | 18 ++++++++++++++++++
 modules/t/gene.t                         |  8 ++++++++
 2 files changed, 26 insertions(+)

diff --git a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
index 93f5551f98..b6e613bd0d 100644
--- a/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
+++ b/modules/Bio/EnsEMBL/DBSQL/GeneAdaptor.pm
@@ -845,6 +845,24 @@ sub fetch_all_by_external_name {
   return \@result;
 }
 
+=head2 fetch_all_by_description
+
+  Arg [1]    : String of description
+  Example    : $gene_list = $gene_adaptor->fetch_all_by_description('RNA%');
+  Description: Fetches genes by their textual description. Fully supports SQL
+               wildcards, since getting an exact hit is unlikely.
+  Returntype : listref of Bio::EnsEMBL::Gene
+
+=cut
+
+sub fetch_all_by_description {
+    my ($self,$description) = @_;
+    
+    my $constraint = "g.description LIKE ?";
+    $self->bind_param_generic_fetch($description, SQL_VARCHAR);
+    return $self->generic_fetch($constraint);
+}
+
 =head2 fetch_all_by_GOTerm
 
   Arg [1]   : Bio::EnsEMBL::OntologyTerm
diff --git a/modules/t/gene.t b/modules/t/gene.t
index 96d000721a..a70031446b 100644
--- a/modules/t/gene.t
+++ b/modules/t/gene.t
@@ -441,6 +441,14 @@ ok(($genes[0]->stable_id() eq 'ENSG00000174873') || ($genes[1]->stable_id() eq '
 debug($gene->stable_id);
 ok($gene->stable_id() eq 'ENSG00000101367');
 
+#
+# test fetch_all_by_description
+#
+
+my $gene_list = $ga->fetch_all_by_description('%APC-BINDING PROTEIN EB1%');
+ok(scalar(@$gene_list) == 1, "Get by description");
+ok($gene_list->[0]->stable_id eq "ENSG00000101367", "check we got the right one by description");
+
 #
 # test fetch_all_by_external_name with wildcard restrictions
 #
-- 
GitLab