This function reads a file containing one or more trees in NEXUS format. Each tree is parsed according to the Newick-with-Attributes (NWKA) format.

read_nwka_nexus(file, tree.names = NULL, force.multi = FALSE, debug = 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", ...

force.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.

debug

A logical value indicating whether to enable verbose debug output while parsing the tree. If this is TRUE, the function will print information about each node in the each tree as it parses it.

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

Only the Trees block of the NEXUS file is parsed.

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. If the nodes contain a prob attribute, its value will also be copied to the Support attribute.

The translation table (if any) of the Trees block is used to translate the names of both tips and internal nodes. However, if the untranslated names of internal nodes are numbers, these may be interpreted as support values (and thus, not translated).

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

Setting the debug argument to TRUE can be useful when analysing malformed trees (to understand at which point in the tree the problem lies).

References

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

See also