]> git.donarmstrong.com Git - ape.git/blob - man/read.tree.Rd
final wrap for ape 3.0
[ape.git] / man / read.tree.Rd
1 \name{read.tree}
2 \alias{read.tree}
3 \alias{phylo}
4 \title{Read Tree File in Parenthetic Format}
5 \usage{
6 read.tree(file = "", text = NULL, tree.names = NULL, skip = 0,
7     comment.char = "#", keep.multi = FALSE, ...)
8 }
9 \arguments{
10   \item{file}{a file name specified by either a variable of mode character,
11     or a double-quoted string; if \code{file = ""} (the default) then the
12     tree is input on the keyboard, the entry being terminated with a
13     blank line.}
14   \item{text}{alternatively, the name of a variable of mode character
15     which contains the tree(s) in parenthetic format. By default, this
16     is ignored (set to \code{NULL}, meaning that the tree is read in a
17     file); if \code{text} is not \code{NULL}, then the argument
18     \code{file} is ignored.}
19   \item{tree.names}{if there are several trees to be read, a vector of
20     mode character that gives names to the individual trees; if
21     \code{NULL} (the default), the trees are named \code{"tree1"},
22     \code{"tree2"}, ...}
23   \item{skip}{the number of lines of the input file to skip before
24     beginning to read data (this is passed directly to\code{ scan()}).}
25   \item{comment.char}{a single character, the remaining of the line
26     after this character is ignored (this is passed directly to
27     \code{scan()}).}
28   \item{keep.multi}{if \code{TRUE} and \code{tree.names = NULL} then
29     single trees are returned in \code{"multiPhylo"} format, with any
30     name that is present (see details). Default is \code{FALSE}.}
31   \item{\dots}{further arguments to be passed to \code{scan()}.}
32 }
33 \description{
34   This function reads a file which contains one or several trees in
35   parenthetic format known as the Newick or New Hampshire format.
36 }
37 \details{
38   The default option for \code{file} allows to type directly the tree on
39   the keyboard (or possibly to copy from an editor and paste in R's
40   console) with, e.g., \code{mytree <- read.tree()}.
41
42   `read.tree' tries to represent correctly trees with a badly
43   represented root edge (i.e. with an extra pair of parentheses). For
44   instance, the tree "((A:1,B:1):10);" will be read like "(A:1,B:1):10;"
45   but a warning message will be issued in the former case as this is
46   apparently not a valid Newick format. If there are two root edges
47   (e.g., "(((A:1,B:1):10):10);"), then the tree is not read and an error
48   message is issued.
49
50   If there are any characters preceding the first "(" in a line then
51   this is assigned to the name. This is returned when a "multiPhylo"
52   object is returned and \code{tree.names = NULL}.
53 }
54 \value{
55   an object of class \code{"phylo"} with the following components:
56   \item{edge}{a two-column matrix of mode numeric where each row
57     represents an edge of the tree; the nodes and the tips are
58     symbolized with numbers; the tips are numbered 1, 2, \dots, and the
59     nodes are numbered after the tips. For each row, the first column
60     gives the ancestor.}
61   \item{edge.length}{(optional) a numeric vector giving the lengths of the
62     branches given by \code{edge}.}
63   \item{tip.label}{a vector of mode character giving the names of the
64     tips; the order of the names in this vector corresponds to the
65     (positive) number in \code{edge}.}
66   \item{Nnode}{the number of (internal) nodes.}
67   \item{node.label}{(optional) a vector of mode character giving the
68     names of the nodes.}
69   \item{root.edge}{(optional) a numeric value giving the length of the
70     branch at the root if it exists.}
71
72   If several trees are read in the file, the returned object is of class
73   \code{"multiPhylo"}, and is a list of objects of class \code{"phylo"}.
74   The name of each tree can be specified by \code{tree.names}, or can be
75   read from the file (see details).
76 }
77 \references{
78   Felsenstein, J. The Newick tree format.
79   \url{http://evolution.genetics.washington.edu/phylip/newicktree.html}
80
81   Olsen, G. Interpretation of the "Newick's 8:45" tree format standard.
82   \url{http://evolution.genetics.washington.edu/phylip/newick_doc.html}
83
84   Paradis, E. (2008) Definition of Formats for Coding Phylogenetic Trees
85   in R. \url{http://ape.mpl.ird.fr/misc/FormatTreeR_28July2008.pdf}
86
87   Paradis, E. (2012) \emph{Analysis of Phylogenetics and Evolution with
88     R (Second Edition).} New York: Springer.
89 }
90
91 \author{Emmanuel Paradis and Daniel Lawson \email{dan.lawson@bristol.ac.uk}}
92 \seealso{
93   \code{\link{write.tree}}, \code{\link{read.nexus}},
94   \code{\link{write.nexus}}, \code{\link[base]{scan}} for the basic R
95   function to read data in a file
96 }
97 \examples{
98 ### An extract from Sibley and Ahlquist (1990)
99 cat("owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);", file = "ex.tre", sep = "\n")
100 tree.owls <- read.tree("ex.tre")
101 str(tree.owls)
102 tree.owls
103 tree.owls <- read.tree("ex.tre", keep.multi = TRUE)
104 tree.owls
105 names(tree.owls)
106 unlink("ex.tre") # delete the file "ex.tre"
107 ### Only the first three species using the option `text'
108 TREE <- "((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3);"
109 TREE
110 tree.owls.bis <- read.tree(text = TREE)
111 str(tree.owls.bis)
112 tree.owls.bis
113 }
114 \keyword{manip}
115 \keyword{IO}