[Phylobase-commits] r348 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 19 22:29:14 CET 2008


Author: pdc
Date: 2008-12-19 22:29:14 +0100 (Fri, 19 Dec 2008)
New Revision: 348

Modified:
   pkg/R/methods-phylo4.R
Log:
update reorder to work with new explicit root
also updated to check for labels and lengths before reassigning

Modified: pkg/R/methods-phylo4.R
===================================================================
--- pkg/R/methods-phylo4.R	2008-12-19 21:28:08 UTC (rev 347)
+++ pkg/R/methods-phylo4.R	2008-12-19 21:29:14 UTC (rev 348)
@@ -360,6 +360,7 @@
         ##     root <- tips + 1
         ## }
         ## if(root <= tips) {return()}
+        edge  <- edge[!is.na(edge[,1]), ]
         index <- edge[, 1] == root
         nextr <- edge[index, 2]
         ## paths <- apply(as.matrix(nextr), 1, reorder, edge = edge, tips = tips)
@@ -372,9 +373,12 @@
     }
     if(order == 'pruningwise') {
         index <- reorder.prune(x at edge, length(x at tip.label))
-    }
-    x at edge        <- x at edge[index, ]
-    x at edge.label  <- x at edge.label[index]
-    x at edge.length <- x at edge.length[index]
+        ## add the root node to the end, there may be more elegant ways to do this
+        index <- c(index, which(x at edge[,2] == rootNode(x)))
+    } else {stop(paste("Method for", order, "not implemented"))}
+    
+    x at edge <- x at edge[index, ]
+    if(hasEdgeLabels(x)) { x at edge.label  <- x at edge.label[index] }
+    if(hasEdgeLength(x)) { x at edge.length <- x at edge.length[index] }
     x
 })



More information about the Phylobase-commits mailing list