[Phylobase-commits] r191 - branches/pdcgsoc/misc

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 22 06:33:06 CEST 2008


Author: pdc
Date: 2008-06-22 06:33:06 +0200 (Sun, 22 Jun 2008)
New Revision: 191

Modified:
   branches/pdcgsoc/misc/plot.phylo.R
Log:
Usually good to reorder the branch lengths if you reorder the branches

Modified: branches/pdcgsoc/misc/plot.phylo.R
===================================================================
--- branches/pdcgsoc/misc/plot.phylo.R	2008-06-22 04:17:13 UTC (rev 190)
+++ branches/pdcgsoc/misc/plot.phylo.R	2008-06-22 04:33:06 UTC (rev 191)
@@ -26,6 +26,14 @@
     c(nord, which(index))
 }
 
+reorder.phylo4 <- function(phy) {
+    index <- myorder(phy at edge, length(phy at tip.label))
+    phy at edge        <- phy at edge[index, ]
+    phy at edge.label  <- phy at edge.label[index]
+    phy at edge.length <- phy at edge.length[index]
+    phy
+}
+
 myplot <- function(x, type = "phylogram", use.edge.length = TRUE,
                        node.pos = NULL, show.tip.label = TRUE,
                        show.node.label = FALSE, edge.color = "black",
@@ -52,7 +60,7 @@
     if (!use.edge.length) root.edge <- FALSE
 
     xe <- x at edge
-    x at edge <- x at edge[myorder(x at edge, Ntip), ]
+    x <- reorder.phylo4(x)
     ## TODO does is make sense to pile edge and node data into a phylo4d object?
     ## Fix from Klaus Schliep (2007-06-16):
     ## fix from Li-San Wang (2007-01-23):
@@ -284,15 +292,15 @@
     n <- length(phy at tip.label)
     m <- phy at Nnode
     N <- dim(phy at edge)[1]
-    phy at edge <- phy at edge[myorder(phy at edge, n), ]
+    phy <- reorder.phylo4(phy)
     .C("node_depth", as.integer(n), as.integer(m),
        as.integer(phy at edge[, 1]), as.integer(phy at edge[, 2]),
        as.integer(N), double(n + m), DUP = FALSE, PACKAGE = "ape")[[6]]
 }
 
 ## testing
-## require(phylobase)
-## bar <- rcoal(7)
-## bar$tip.label <- c("one", "two", "three", "four", "five", "six", "seven")
-## bar <- as(bar, 'phylo4')
-## myplot(bar, show.tip.label = TRUE)
+require(phylobase)
+bar <- rcoal(7)
+bar$tip.label <- c("one", "two", "three", "four", "five", "six", "seven")
+bar <- as(bar, 'phylo4')
+myplot(bar, show.tip.label = TRUE)



More information about the Phylobase-commits mailing list