Title: | Phylogenies with Annotations |
---|---|
Description: | Functions to read and write APE-compatible phylogenetic trees in NEXUS and Newick formats, while preserving annotations. |
Authors: | Daniel Beer [aut], Anusha Beer [aut] |
Maintainer: | Daniel Beer <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.3 |
Built: | 2025-03-01 04:20:26 UTC |
Source: | https://github.com/cran/phylotate |
phylotate provides functions that allow you to read and write NEXUS and Newick trees containing annotations, including those produced by MrBayes.
It does this by extending ape's phylo
object type with
extra data members containing per-node annotation information. This
information is stored in such a way that it can be manipulated easily
and will survive most manipulations using standard ape functions
(e.g. reorder
, chronopl
).
See the documentation for the parse_annotated
function
for more information on how annotations are stored internally.
The functions you probably want to use for most things are
read_annotated
and write_annotated
.
Daniel Beer [email protected], Anusha Beer [email protected]
A simple tree generated by MrBayes using the sequences for Darwin's finches from the example distributed with BEAST.
data(finches)
data(finches)
This function takes a tree object and produces a dataframe containing attributes attached to each node by MrBayes.
mb_attrs(tree)
mb_attrs(tree)
tree |
an object of type |
The returned dataframe contains one row per node, and one column per
attribute. The attributes parsed are prob
, prob_stddev
,
length_mean
, length_median
, length_95_HPD_low
,
and length_95_HPD_high
.
Attributes which are derivable from the others are not parsed (for example,
the prob_percent
attribute is not parsed, since it's prob
times 100.
A dataframe of attributes.
Anusha Beer [email protected]
parse_annotated
,
read_annotated
# Parse the example data included with this package data(finches) t <- parse_annotated(finches, format="nexus") # Obtain a table of MrBayes attributes for each node attrs <- mb_attrs(t)
# Parse the example data included with this package data(finches) t <- parse_annotated(finches, format="nexus") # Obtain a table of MrBayes attributes for each node attrs <- mb_attrs(t)
This function takes the given text string, containing data in either NEXUS or Newick format, and returns annotated phylogenetic trees.
parse_annotated(str, format="nexus")
parse_annotated(str, format="nexus")
str |
a text string, containing tree data |
format |
a format specifier; either |
The given file text is parsed and a tree object is constructed which can be used with the functions in the ape package. Annotations of the kind produced by, for example, MrBayes, are parsed and preserved in the returned object.
In addition to edge
, edge.length
and tip.label
,
two additional vectors are added. These are node.comment
and
node.distance.comment
. These contain annotations associated
with nodes and their distance values. These arrays are indexed by node
number, not by edge. The reason for this is that this ensures that the
object will remain in a valid state after a call to reorder
which might change the ordering of the edge arrays without being aware
of annotations. If you need to obtain annotations in edge-order,
subset by the second column of the edge
array.
an object of type "phylo"
or "multiPhylo"
, augmented with
node annotations.
Daniel Beer [email protected]
Paradis, E. Definition of Formats for Coding Phylogenetic Trees in R. http://ape-package.ird.fr/misc/FormatTreeR_24Oct2012.pdf
print_annotated
,
read_annotated
,
write_annotated
,
finches
# Parse the example data included with this package data(finches) t <- parse_annotated(finches, format="nexus") # Obtain annotations in edge-order, rather than node-order edge.comment <- t$node.comment[t$edge[,2]]
# Parse the example data included with this package data(finches) t <- parse_annotated(finches, format="nexus") # Obtain annotations in edge-order, rather than node-order edge.comment <- t$node.comment[t$edge[,2]]
This function takes the given tree object and returns a string
representing the tree in the requested format. The difference between
the "newick"
and "newick.named"
formats is that the
former uses only node numbers in its output, whereas the latter uses
the tip labels (sanitized and deduplicated if necessary).
print_annotated(tree, format="nexus")
print_annotated(tree, format="nexus")
tree |
a phylogentic tree, with optional annotations |
format |
a format specifier; either |
The tree object should be either a "phylo"
or
"multiPhylo"
object. It may optionally be augmented with
annotations, as described in the documentation for the
parse_annotated
function.
The output is a string suitable for writing to a file.
a string containing a serialized tree.
Daniel Beer [email protected]
parse_annotated
,
read_annotated
,
write_annotated
This function takes the given file, containing data in either NEXUS or Newick format, and returns annotated phylogenetic trees.
read_annotated(filename, format="nexus")
read_annotated(filename, format="nexus")
filename |
a file to read tree data from |
format |
a format specifier; either |
The given file text is parsed and a tree object is constructed which can be used with the functions in the ape package. Annotations of the kind produced by, for example, MrBayes, are parsed and preserved in the returned object.
See parse_annotated
for more information about the
structure of the returned value.
an object of type "phylo"
or "multiPhylo"
, augmented with
node annotations.
Daniel Beer [email protected]
print_annotated
,
parse_annotated
,
write_annotated
This function takes the given tree object and returns a string
representing the tree in the requested format. The difference between
the "newick"
and "newick.named"
formats is that the
former uses only node numbers in its output, whereas the latter uses
the tip labels (sanitized and deduplicated if necessary).
write_annotated(tree, filename, format="nexus")
write_annotated(tree, filename, format="nexus")
tree |
a phylogentic tree, with optional annotations |
filename |
a file to write no |
format |
a format specifier; either |
The tree object should be either a "phylo"
or
"multiPhylo"
object. It may optionally be augmented with
annotations, as described in the documentation for the
parse_annotated
function.
Daniel Beer [email protected]
parse_annotated
,
print_annotated
,
read_annotated