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