]> git.donarmstrong.com Git - ape.git/blob - R/cophenetic.phylo.R
new dist.nodes() with C code
[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(phy)
11 {
12     phy <- reorder(phy)
13     n <- Ntip(phy)
14     m <- phy$Nnode
15
16     d <- .C("dist_nodes", as.integer(n), as.integer(m),
17             as.integer(phy$edge[, 1] - 1L), as.integer(phy$edge[, 2] - 1L),
18             as.double(phy$edge.length), as.integer(Nedge(phy)),
19             double(nm * nm), DUP = FALSE, NAOK = TRUE,
20             PACKAGE = "ape")[[7]]
21     nm <- n + m
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 }