This function reads a file containing one or more trees in binary format.

read_binary_trees(file, tree.names = NULL, keep.multi = FALSE)

Arguments

file

A file name.

tree.names

A vector of mode character containing names for the trees that are read from the file; if NULL (the default), the trees will be named according to the names in the tree file or, if these are missing, as "tree1", "tree2", ...

keep.multi

If TRUE, this function will return an object of class "multiPhylo" even when the tree file contains only a single tree. Defaults to FALSE, which means that if the file contains a single tree, an object of class "phylo" is returned.

Value

An object of class "phylo" or "multiPhylo", compatible with the ape package.

In addition to the elements described in the documentation for the read.tree function of the ape package, a "phylo" object produced by this function will also have the following components:

tip.attributes

A named list of attributes for the tips of the tree. Each element of this list is a vector of mode character or numeric (depending on the attribute).

node.attributes

A named list of attributes for the internal nodes of the tree. Each element of this list is a vector of mode character or numeric (depending on the attribute).

Details

This function reads the whole file in memory at once. If you wish to process the file tree-by-tree, you should use the read_one_binary_tree function.

Node attributes (e.g. support values, rates, ages...) are parsed by this function and returned in the tip.attributes and node.attributes elements of the returned "phylo" objects.

Attribute names may appear in any kind of casing (e.g. Name, name or NAME), but they should be treated using case-insensitive comparisons.

If the file has an invalid trailer (e.g. because it is incomplete), the function will print a warning and attempt anyways to extract as many trees as possible.

References

https://github.com/arklumpus/TreeNode/blob/master/BinaryTree.md

See also

Examples

# Tree file (replace with your own) treeFile <- system.file("extdata", "oneTree.tbi", package="TreeNode") # Read the tree file tree <- read_binary_trees(treeFile) # Use support values as node labels tree$node.label = tree$node.attributes$Support # Plot the tree with support values at the nodes ape::plot.phylo(tree, show.node.label = TRUE)