]> git.donarmstrong.com Git - ape.git/blobdiff - R/as.phylo.R
a few changes....
[ape.git] / R / as.phylo.R
index e0ee65fec8575654d1cb1e56637006b7625093fc..b576a54e0b719992d2cf653ace068e15926566dc 100644 (file)
@@ -1,8 +1,8 @@
-## as.phylo.R (2007-03-05)
+## as.phylo.R (2010-09-30)
 
 ##     Conversion Among Tree Objects
 
-## Copyright 2005-2007 Emmanuel Paradis
+## Copyright 2005-2010 Emmanuel Paradis
 
 ## This file is part of the R-package `ape'.
 ## See the file ../COPYING for licensing issues.
@@ -47,20 +47,21 @@ as.phylo.hclust <- function(x, ...)
         edge[j:(j + 1), 1] <- node[i]
         for (l in 1:2) {
             k <- j + l - 1L
-            if (x$merge[i, l] > 0) {
-                edge[k, 2] <- node[x$merge[i, l]] <- cur.nod
+            y <- x$merge[i, l]
+            if (y > 0) {
+                edge[k, 2] <- node[y] <- cur.nod
                 cur.nod <- cur.nod + 1L
-                edge.length[k] <- x$height[i] - x$height[x$merge[i, l]]
+                edge.length[k] <- x$height[i] - x$height[y]
             } else {
-                edge[k, 2] <- -x$merge[i, l]
+                edge[k, 2] <- -y
                 edge.length[k] <- x$height[i]
             }
         }
         j <- j + 2L
     }
     if (is.null(x$labels))
-      x$labels <- as.character(1:(N + 1))
-    obj <- list(edge = edge, edge.length = edge.length,
+        x$labels <- as.character(1:(N + 1))
+    obj <- list(edge = edge, edge.length = edge.length / 2,
                 tip.label = x$labels, Nnode = N)
     class(obj) <- "phylo"
     reorder(obj)
@@ -90,7 +91,7 @@ as.hclust.phylo <- function(x, ...)
     n <- length(x$tip.label)
     bt <- rev(branching.times(x))
     N <- length(bt)
-    nm <- as.numeric(names(bt))
+    nm <- x$Nnode:1 + n # fix by Filipe G. Vieira (2010-09-30)
     merge <- matrix(NA, N, 2)
     for (i in 1:N) {
         ind <- which(x$edge[, 1] == nm[i])