X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=R%2Fcophenetic.phylo.R;h=bdcbfcf75e808d34abfc548da5352a07615e0be2;hb=fab4946bb5d41cd408dffd4b66aae8a697690cfa;hp=a40cce092e292bc0a54f6bb4451d5f173a951779;hpb=c827059eeafc8cbe41c812b26979543ab287803e;p=ape.git diff --git a/R/cophenetic.phylo.R b/R/cophenetic.phylo.R index a40cce0..bdcbfcf 100644 --- a/R/cophenetic.phylo.R +++ b/R/cophenetic.phylo.R @@ -1,8 +1,8 @@ -## cophenetic.phylo.R (2007-01-23) +## cophenetic.phylo.R (2010-11-15) ## Pairwise Distances from a Phylogenetic Tree -## Copyright 2006-2007 Emmanuel Paradis +## Copyright 2006-2010 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. @@ -10,10 +10,15 @@ dist.nodes <- function(x) { if (is.null(x$edge.length)) - stop("your tree has no branch lengths") + stop("your tree has no branch lengths") + + trim <- FALSE + if (!is.binary.tree(x) || !is.rooted(x)) { + trim <- TRUE + x <- makeNodeLabel(x) + x <- multi2di(x, random = FALSE) + } - if (!is.binary.tree(x) || !is.rooted(x)) - x <- multi2di(x, random = FALSE) n <- length(x$tip.label) n.node <- x$Nnode N <- n + n.node @@ -57,6 +62,11 @@ dist.nodes <- function(x) res[des1, nod] <- res[nod, des1] <- res[anc, des1] + l } } + if (trim) { + i <- which(x$node.label == "") + n + res <- res[-i, -i] + N <- dim(res)[1] + } dimnames(res)[1:2] <- list(1:N) res }