[Phylobase-commits] r293 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 21 11:09:39 CET 2008


Author: jombart
Date: 2008-11-21 11:09:39 +0100 (Fri, 21 Nov 2008)
New Revision: 293

Modified:
   pkg/R/treewalk.R
Log:
Fixed one bug in MRCA: function failed when N01 was in the list of nodes. 


Modified: pkg/R/treewalk.R
===================================================================
--- pkg/R/treewalk.R	2008-11-21 09:45:50 UTC (rev 292)
+++ pkg/R/treewalk.R	2008-11-21 10:09:39 UTC (rev 293)
@@ -106,17 +106,26 @@
     if (length(nodes)==1 && length(nodes[[1]])>1) {
         nodes <- as.list(nodes[[1]])
     }
-    ## Correct behavior in case of MRCA of identical taxa
+
+    ## Correct behavior when the root is part of the nodes
     testNodes <- lapply(nodes, getnodes, phy=phy)
     uniqueNodes <- unique(testNodes)
+    root <- nTips(phy)+1
+    if(root %in% uniqueNodes) {
+        res <- getnodes(phy, root)
+        return(res)
+    }
+    ## Correct behavior in case of MRCA of identical taxa
     if(length(uniqueNodes) == 1) {
-        uniqueNodes[[1]]
+        res <- uniqueNodes[[1]]
+        return(res)
     }
     else {
         ancests <- lapply(nodes, ancestors, phy=phy, which="ALL")
-        getnodes(phy, max(Reduce(intersect, ancests)))
+        res <- getnodes(phy, max(Reduce(intersect, ancests)))
+        return(res)
     }
-}
+} # end MRCA
 
 
 



More information about the Phylobase-commits mailing list