read.tree {ape} | R Documentation |
This function reads a file which contains one or several trees in parenthetic format known as the Newick or New Hampshire format.
read.tree(file = "", format = "Newick", rooted = TRUE, text = NULL, tree.names = NULL, skip = 0, comment.char = "#", ...)
file |
a file name specified by either a variable of mode character,
or a double-quoted string; if file = "" (the default) then the
tree is input on the keyboard, the entry being terminated with a blank line. |
format |
a character giving the format of the tree file; by
default "Newick" . Currently only the Newick format is available. |
rooted |
a logical indicating whether the tree is rooted or not;
defaults to TRUE . This is currently not implemented, meaning
that all trees are read as rooted. |
text |
alternatively, the name of a variable of mode character
which contains the tree(s) in parenthetic format. By default, this
is ignored (set to NULL , meaning that the tree is read in a
file); if text is not NULL , then the argument
file is ignored. |
tree.names |
if there are several trees to be read, a vector of
mode character that gives names to the individual trees; if
NULL (the default), the trees are named "tree1" ,
"tree2" , ... |
skip |
the number of lines of the input file to skip before
beginning to read data (this is passed directly to scan() ). |
comment.char |
a single character, the remaining of the line
after this character is ignored (this is passed directly to
scan() ). |
... |
Further arguments to be passed to scan() . |
The default option for file
allows to type directly the tree on
the keyboard (or possibly to copy from an editor and paste in R's
console) with, e.g., mytree <- read.tree()
.
an object of class "phylo"
with the following components:
edge |
a two-column matrix of mode character where each row
represents an edge of the tree; the nodes and the tips are
symbolized with numbers (these numbers are not treated as numeric,
hence the mode character); the nodes are represented with negative
numbers (the root being "-1" ), and the tips are represented with
positive numbers. For each row, the first column gives the
ancestor. This representation allows an easy manipulation of the
tree, particularly if it is rooted. |
edge.length |
(optional) a numeric vector giving the lengths of the
branches given by edge . |
tip.label |
a vector of mode character giving the names of the
tips; the order of the names in this vector corresponds to the
(positive) number in edge . |
node.label |
(optional) a vector of mode character giving the
names of the nodes (set to NULL if not available in the file). |
root.edge |
(optional) a numeric value giving the length of the
branch at the root is it exists (NULL otherwise). |
If several trees are read in the file, the returned object is of class
c("phylo", "multi.tree")
, and is a list of objects of class "phylo"
.
Emmanuel Paradis paradis@isem.univ-montp2.fr
http://evolution.genetics.washington.edu/phylip/newick_doc.html
http://evolution.genetics.washington.edu/phylip/newicktree.html
write.tree
, scan
for the basic R
function to read data in a file
### An extract from Sibley and Ahlquist (1990) cat("(((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") tree.owls <- read.tree("ex.tre") str(tree.owls) tree.owls unlink("ex.tre") # delete the file "ex.tre" ### Only the first three species using the option `text' TREE <- "((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3);" TREE tree.owls.bis <- read.tree(text = TREE) str(tree.owls.bis) tree.owls.bis