From 64b686c262ed40e6f502e48df38cf188db43a0b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Kusalananda=20K=C3=A4h=C3=A4ri?=
 <ak4@sanger.ac.uk>
Date: Wed, 25 Mar 2009 14:17:19 +0000
Subject: [PATCH] Make children() and parents() take a list of strings
 representing the relationship types to consider, e.g. qw(is_a part_of).

---
 modules/Bio/EnsEMBL/OntologyTerm.pm | 46 +++++++++++++++--------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/modules/Bio/EnsEMBL/OntologyTerm.pm b/modules/Bio/EnsEMBL/OntologyTerm.pm
index 7a6ae0e7d1..1944a02855 100644
--- a/modules/Bio/EnsEMBL/OntologyTerm.pm
+++ b/modules/Bio/EnsEMBL/OntologyTerm.pm
@@ -181,28 +181,29 @@ sub defintion {
 
 =head2 children
 
-  Arg           : (optional) String
-                  The type of relation to retrieve children for.
+  Args          : (optional) List of strings
+                  The type of relations to retrieve children for.
 
   Description   : Returns the children terms of this ontology term.
 
-  Example       : my @children = @{ $term->children('is_a') };
+  Example       : my @children =
+                    @{ $term->children( 'is_a', 'part_of' ) };
 
   Return type   : listref of Bio::EnsEMBL::OntologyTerm
 
 =cut
 
 sub children {
-  my ( $this, $relation ) = @_;
+  my ( $this, @relations ) = @_;
 
-  my @terms;
+  my @terms = @{ $this->adaptor()->fetch_by_parent_term($this) };
 
-  @terms = @{ $this->adaptor()->fetch_by_parent_term($this); };
-  if ( defined($relation) ) {
-    if ( exists( $this->{'children'}{$relation} ) ) {
-      @terms = @{ $this->{'children'}{$relation} };
-    } else {
-      @terms = ();
+  if (@relations) {
+    @terms = ();
+    foreach my $relation (@relations) {
+      if ( exists( $this->{'children'}{$relation} ) ) {
+        push( @terms, @{ $this->{'children'}{$relation} } );
+      }
     }
   }
 
@@ -230,28 +231,29 @@ sub descendants {
 
 =head2 parents
 
-  Arg           : (optional) String
-                  The type of relation to retrieve parents for.
+  Args          : (optional) List of strings
+                  The type of relations to retrieve parents for.
 
   Description   : Returns the parent terms of this ontology term.
 
-  Example       : my @parents = @{ $term->parents('is_a')) };
+  Example       : my @parents =
+                    @{ $term->parents( 'is_a', 'part_of' ) };
 
   Return type   : listref of Bio::EnsEMBL::OntologyTerm
 
 =cut
 
 sub parents {
-  my ( $this, $relation ) = @_;
+  my ( $this, @relations ) = @_;
 
-  my @terms;
+  my @terms = @{ $this->adaptor()->fetch_by_child_term($this) };
 
-  @terms = @{ $this->adaptor()->fetch_by_child_term($this); };
-  if ( defined($relation) ) {
-    if ( exists( $this->{'parents'}{$relation} ) ) {
-      @terms = @{ $this->{'parents'}{$relation} };
-    } else {
-      @terms = ();
+  if (@relations) {
+    @terms = ();
+    foreach my $relation (@relations) {
+      if ( exists( $this->{'parents'}{$relation} ) ) {
+        push( @terms, @{ $this->{'parents'}{$relation} } );
+      }
     }
   }
 
-- 
GitLab