]> git.donarmstrong.com Git - ape.git/blob - R/cophenetic.phylo.R
final commit for ape 3.0-8
[ape.git] / R / cophenetic.phylo.R
1 ## cophenetic.phylo.R (2012-08-14)
2
3 ##   Pairwise Distances from a Phylogenetic Tree
4
5 ## Copyright 2006-2012 Emmanuel Paradis
6
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
9
10 dist.nodes <- function(x)
11 {
12     x <- reorder(x) # required for the C code
13     n <- Ntip(x)
14     m <- x$Nnode
15     nm <- n + m
16
17     d <- .C("dist_nodes", as.integer(n), as.integer(m),
18             as.integer(x$edge[, 1] - 1L), as.integer(x$edge[, 2] - 1L),
19             as.double(x$edge.length), as.integer(Nedge(x)),
20             double(nm * nm), DUP = FALSE, NAOK = TRUE,
21             PACKAGE = "ape")[[7]]
22     dim(d) <- c(nm, nm)
23     dimnames(d) <- list(1:nm, 1:nm)
24     d
25 }
26
27 cophenetic.phylo <- function(x)
28 {
29     n <- length(x$tip.label)
30     ans <- dist.nodes(x)[1:n, 1:n]
31     dimnames(ans)[1:2] <- list(x$tip.label)
32     ans
33 }