1 ## makeNodeLabel.R (2009-03-22)
5 ## Copyright 2009 Emmanuel Paradis
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
10 makeNodeLabel <- function(phy, method = "number", prefix = "Node",
11 nodeList = list(), ...)
13 method <- sapply(method, match.arg, c("number", "md5sum", "user"),
16 if ("number" %in% method)
17 phy$node.label <- paste(prefix, 1:phy$Nnode, sep = "")
19 if ("md5sum" %in% method) {
20 nl <- character(phy$Nnode)
21 pp <- prop.part(phy, check.labels = FALSE)
22 labs <- attr(pp, "labels")
24 for (i in seq_len(phy$Nnode)) {
25 cat(sort(labs[pp[[i]]]), sep = "\n", file = fl)
26 nl[i] <- tools::md5sum(fl)
32 if ("user" %in% method) {
33 if (is.null(phy$node.label))
34 phy$node.label <- character(phy$Nnode)
36 if (is.null(nl)) stop("argument 'nodeList' has no names")
37 Ntip <- length(phy$tip.label)
38 seq.nod <- .Call("seq_root2tip", phy$edge, Ntip, phy$Nnode,
40 ## a local version to avoid the above call many times:
41 .getMRCA <- function(seq.nod, tip) {
46 x <- unique(unlist(lapply(sn, "[", i)))
47 if (length(x) != 1) break
53 for (i in seq_along(nodeList)) {
54 tips <- sapply(nodeList[[i]], grep, phy$tip.label, ...,
56 j <- .getMRCA(seq.nod, unique(unlist(tips)))
57 phy$node.label[j - Ntip] <- nl[i]