From: paradis Date: Thu, 17 Apr 2008 19:51:15 +0000 (+0000) Subject: fix on drop.tip() X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cc53d4b238132388c49561f647b8839d5bd6ef1e;p=ape.git fix on drop.tip() git-svn-id: https://svn.mpl.ird.fr/ape/dev/ape@26 6e262413-ae40-0410-9e79-b911bd7a66b7 --- diff --git a/Changes b/Changes index 5199d01..3eaf5b7 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,8 @@ BUG FIXES o zoom() failed when tip labels were used instead of their numbers (thanks to Yan Wong for the fix). + o drop.tip() failed with some trees (fixed by Yan Wong). + OTHER CHANGES diff --git a/R/drop.tip.R b/R/drop.tip.R index ee92d02..d65fd36 100644 --- a/R/drop.tip.R +++ b/R/drop.tip.R @@ -1,8 +1,8 @@ -## drop.tip.R (2007-12-21) +## drop.tip.R (2008-04-17) ## Remove Tips in a Phylogenetic Tree -## Copyright 2003-2007 Emmanuel Paradis +## Copyright 2003-2008 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -18,7 +18,9 @@ drop.tip <- function(phy, tip, trim.internal = TRUE, subtree = FALSE, } tmp <- as.numeric(phy$edge) nb.tip <- max(tmp) - nb.node <- -min(tmp) + ## fix by Yan Wong: + nodes <- setdiff(tmp,1:nb.tip) #not sure if this also needs sorting into order + ## end nobr <- is.null(phy$edge.length) if (is.numeric(tip)) tip <- phy$tip.label[tip] ## find the tips to drop...: @@ -76,15 +78,15 @@ drop.tip <- function(phy, tip, trim.internal = TRUE, subtree = FALSE, if (!nobr) phy$edge.length <- phy$edge.length[!ind] } } else { - temp <- phy$edge[, 2][as.numeric(phy$edge[, 2]) < 0] - k <- temp %in% phy$edge[, 1] - ind <- phy$edge[, 2] %in% temp[!k] + ## fix by Yan Wong: + k <- nodes %in% phy$edge[, 1] #nodes that have descendants + ind <- phy$edge[, 2] %in% nodes[!k] phy$edge[which(ind), 2] <- as.character(nb.tip + (1:sum(ind))) - if (is.null(phy$node.label)) new.tip.label <- rep("NA", sum(ind)) else { - new.tip.label <- phy$node.label[!k] - phy$node.label <- phy$node.label[k] - } + if (is.null(phy$node.label)) new.tip.label <- rep("NA", sum(ind)) + else new.tip.label <- phy$node.label[!k] phy$tip.label <- c(phy$tip.label, new.tip.label) + #N.B. phy$node.label can be left: it is altered later + ## end } useless.nodes <- names(which(table(phy$edge[, 1]) == 1)) if (subtree) {