read.dendrogram
parses a text file or character string in Newick
(New Hampshire) format and creates an object of class "dendrogram"
.
read.dendrogram(file = "", text = NULL, edges = TRUE, ...)
character string giving a valid path to the file from where to read the data.
optional character string in lieu of a "file" argument. If a text argument is provided instead of a file path, the data are read via a text connection.
logical indicating whether edge weights provided in the Newick string should be retained in the returned object (defaults to TRUE).
further arguments to be passed to scan
.
Returns an object of class "dendrogram"
.
There are varying interpretations of the Newick/New Hampshire text format. This function tries to adhere to the Felsenstein standard outlined here. The function supports weighted edges, labels with special metacharacters (enclosed in single quotation marks), comments (enclosed in square brackets; ignored by the parser), multifuricating nodes, and both rooted and unrooted trees. Comments enclosed in square brackets are also discarded. Inner-node labels (for example "(B:6.0,(A:5.0,C:3.0,E:4.0)Ancestor1:5.0,D:11.0);"); are also currently ignored; however, the parsing of <U+201C>label<U+201D> attributes for non-leaf dendrogram nodes will be available in a future version.
http://evolution.genetics.washington.edu/phylip/newicktree.html http://evolution.genetics.washington.edu/phylip/newick_doc.html
write.dendrogram
writes an object of
class "dendrogram"
to a text string.
The read.tree
function in the
ape
package performs a similar operation for objects
of class "phylo"
and "multiPhylo"
.
newick <- "(A:0.1,B:0.2,(C:0.3,D:0.4):0.5);"
x <- read.dendrogram(text = newick)
plot(x, horiz = TRUE)
Run the code above in your browser using DataLab