File: cophenetic.phylo.R

package info (click to toggle)
r-cran-ape 5.8-1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,676 kB
  • sloc: ansic: 7,676; cpp: 116; sh: 17; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## cophenetic.phylo.R (2024-12-10)

##   Pairwise Distances from a Phylogenetic Tree

## Copyright 2006-2024 Emmanuel Paradis

## This file is part of the R-package `ape'.
## See the file ../COPYING for licensing issues.

dist.nodes <- function(x, fail.if.no.length = FALSE)
{
    if (is.null(x$edge.length)) {
        if (fail.if.no.length) stop("the tree has no branch length")
        warning("the tree has no branch length: fixing them to one.")
        x <- compute.brlen(x, 1)
    }
    x <- reorder(x) # required for the C code
    n <- Ntip(x)
    m <- x$Nnode
    d <- .Call(dist_nodes, n, m, x$edge, x$edge.length)
    nm <- n + m
    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
}