From: paradis Date: Thu, 12 Jun 2008 07:37:31 +0000 (+0000) Subject: bug fix in root() X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6696b292cb86cc4d6a6197830a7f3f7022f4f07e;p=ape.git bug fix in root() git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@34 6e262413-ae40-0410-9e79-b911bd7a66b7 --- diff --git a/Changes b/Changes index f8562e4..e63867f 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,12 @@ NEW FEATURES set of DNA sequences. +BUG FIXES + + o root() failed with resolve.root = TRUE when the root was already + the specified root. + + OTHER CHANGES o unique.multiPhylo() is faster thanks to a suggestion by Vladimir diff --git a/DESCRIPTION b/DESCRIPTION index a9c4fc0..48797b0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ape Version: 2.2-1 -Date: 2008-06-09 +Date: 2008-06-12 Title: Analyses of Phylogenetics and Evolution Author: Emmanuel Paradis, Ben Bolker, Julien Claude, Hoa Sien Cuong, Richard Desper, Benoit Durand, Julien Dutheil, Olivier Gascuel, diff --git a/R/root.R b/R/root.R index e7c916b..a11fa1e 100644 --- a/R/root.R +++ b/R/root.R @@ -1,4 +1,4 @@ -## root.R (2008-02-12) +## root.R (2008-06-12) ## Root of Phylogenetic Trees @@ -113,14 +113,39 @@ root <- function(phy, outgroup, node = NULL, resolve.root = FALSE) if (!all(outgroup == desc)) stop(msg) } else newroot <- phy$edge[which(phy$edge[, 2] == outgroup), 1] } - if (newroot == ROOT) return(phy) + N <- Nedge(phy) + oldNnode <- phy$Nnode + if (newroot == ROOT) { + if (resolve.root) { + snw <- which(phy$edge[, 1] == newroot) + if (length(snw) > 2) { + a <- snw[1]:(snw[2] - 1) + b <- snw[2]:N + newnod <- oldNnode + n + 1 + phy$edge[snw[-1], 1] <- newnod + phy$edge <- rbind(phy$edge[a, ], c(ROOT, newnod), + phy$edge[b, ]) + if (!is.null(phy$edge.length)) + phy$edge.length <- + c(phy$edge.length[a], 0, phy$edge.length[b]) + phy$Nnode <- phy$Nnode + 1 + ## node renumbering (see comments below) + newNb <- integer(n + oldNnode) + newNb[newroot] <- n + 1L + sndcol <- phy$edge[, 2] > n + phy$edge[sndcol, 2] <- newNb[phy$edge[sndcol, 2]] <- + (n + 2):(n + phy$Nnode) + phy$edge[, 1] <- newNb[phy$edge[, 1]] + } + } + return(phy) + } phy$root.edge <- NULL # just in case... Nclade <- tabulate(phy$edge[, 1])[ROOT] # degree of the root node ## if only 2 edges connect to the root, we have to fuse them: fuseRoot <- Nclade == 2 - N <- Nedge(phy) start <- which(phy$edge[, 1] == ROOT) end <- c(start[-1] - 1, N) o <- integer(N) @@ -218,7 +243,6 @@ root <- function(phy, outgroup, node = NULL, resolve.root = FALSE) ne <- length(s) o[NEXT:(NEXT + ne - 1L)] <- s - oldNnode <- phy$Nnode if (fuseRoot) { phy$Nnode <- oldNnode - 1 N <- N - 1L