1 ## summary.phylo.R (2008-04-22)
3 ## Print Summary of a Phylogeny
5 ## Copyright 2003-2008 Emmanuel Paradis, and 2006 Ben Bolker
7 ## This file is part of the R-package `ape'.
8 ## See the file ../COPYING for licensing issues.
12 if (class(phy) != "phylo")
13 stop('object "phy" is not of class "phylo"')
17 Nnode <- function(phy, internal.only = TRUE)
19 if (class(phy) != "phylo")
20 stop('object "phy" is not of class "phylo"')
21 if (internal.only) return(phy$Nnode)
22 phy$Nnode + length(phy$tip.label)
25 Nedge <- function(phy)
27 if (class(phy) != "phylo")
28 stop('object "phy" is not of class "phylo"')
32 summary.phylo <- function(object, ...)
34 cat("\nPhylogenetic tree:", deparse(substitute(object)), "\n\n")
35 nb.tip <- length(object$tip.label)
36 nb.node <- object$Nnode
37 cat(" Number of tips:", nb.tip, "\n")
38 cat(" Number of nodes:", nb.node, "\n")
39 if (is.null(object$edge.length))
40 cat(" No branch lengths.\n")
42 cat(" Branch lengths:\n")
43 cat(" mean:", mean(object$edge.length), "\n")
44 cat(" variance:", var(object$edge.length), "\n")
45 cat(" distribution summary:\n")
46 print(summary(object$edge.length)[-4])
48 if (is.null(object$root.edge))
49 cat(" No root edge.\n")
51 cat(" Root edge:", object$root.edge, "\n")
53 cat(" Tip labels:", object$tip.label[1], "\n")
54 cat(paste(" ", object$tip.label[-1]), sep = "\n")
57 cat(" First ten tip labels:", object$tip.label[1], "\n")
58 cat(paste(" ", object$tip.label[2:10]), sep = "\n")
60 if (is.null(object$node.label))
61 cat(" No node labels.\n")
64 cat(" Node labels:", object$node.label[1], "\n")
65 cat(paste(" ", object$node.label[-1]), sep = "\n")
68 cat(" First ten node labels:", object$node.label[1], "\n")
69 cat(paste(" ", object$node.label[2:10]), sep = "\n")
73 if (!is.null(attr(object, "loglik"))) {
74 cat("Phylogeny estimated by maximum likelihood.\n")
75 cat(" log-likelihood:", attr(object, "loglik"), "\n\n")
76 npart <- length(attr(object, "para"))
78 cat("partition ", i, ":\n", sep = "")
79 print(attr(object, "para")[[i]])
81 else cat(" contrast parameter (xi):",
82 attr(object, "xi")[i - 1], "\n")
88 print.phylo <- function(x, printlen = 6,...)
90 nb.tip <- length(x$tip.label)
92 cat(paste("\nPhylogenetic tree with", nb.tip, "tips and", nb.node,
93 "internal nodes.\n\n"))
95 if (nb.tip > printlen) {
96 cat(paste("\t", paste(x$tip.label[1:printlen],
97 collapse=", "), ", ...\n", sep = ""))
98 } else print(x$tip.label)
99 if (!is.null(x$node.label)) {
100 cat("\tNode labels:\n")
101 if (nb.node > printlen) {
102 cat(paste("\t", paste(x$node.label[1:printlen],
103 collapse=", "), ",...\n", sep = ""))
104 } else print(x$node.label)
106 rlab <- if (is.rooted(x)) "Rooted" else "Unrooted"
107 cat("\n", rlab, "; ", sep="")
109 blen <- if (is.null(x$edge.length)) "no branch lengths." else
110 "includes branch lengths."
111 cat(blen, "\n", sep = "")
114 print.multiPhylo <- function(x, details = FALSE, ...)
117 cat(N, "phylogenetic trees\n")
120 cat("tree", i, ":", length(x[[i]]$tip.label), "tips\n")
124 "[[.multiPhylo" <- function(x, i)
128 if (!is.null(attr(x, "TipLabel")))
129 phy$tip.label <- attr(x, "TipLabel")
133 `$.multiPhylo` <- function(x, name) x[[name]]
135 "[.multiPhylo" <- function(x, i)
138 structure(x[i], TipLabel = attr(x, "TipLabel"),
139 class = "multiPhylo")
142 str.multiPhylo <- function(object, ...)
144 class(object) <- NULL
145 cat('Class "multiPhylo"\n')