## cophenetic.phylo.R (2012-08-14) ## Pairwise Distances from a Phylogenetic Tree ## Copyright 2006-2012 Emmanuel Paradis ## This file is part of the R-package `ape'. ## See the file ../COPYING for licensing issues. dist.nodes <- function(phy) { phy <- reorder(phy) n <- Ntip(phy) m <- phy$Nnode d <- .C("dist_nodes", as.integer(n), as.integer(m), as.integer(phy$edge[, 1] - 1L), as.integer(phy$edge[, 2] - 1L), as.double(phy$edge.length), as.integer(Nedge(phy)), double(nm * nm), DUP = FALSE, NAOK = TRUE, PACKAGE = "ape")[[7]] nm <- n + m dim(d) <- c(nm, nm) dimnames(d) <- list(1:nm, 1:nm) d } cophenetic.phylo <- function(x) { n <- length(x$tip.label) ans <- dist.nodes(x)[1:n, 1:n] dimnames(ans)[1:2] <- list(x$tip.label) ans }