Title: | A Tidy Tool for Phylogenetic Tree Data Manipulation |
---|---|
Description: | Phylogenetic tree generally contains multiple components including node, edge, branch and associated data. 'tidytree' provides an approach to convert tree object to tidy data frame as well as provides tidy interfaces to manipulate tree data. |
Authors: | Guangchuang Yu [aut, cre, cph] , Bradley Jones [ctb], Zebulun Arendsee [ctb] |
Maintainer: | Guangchuang Yu <[email protected]> |
License: | Artistic-2.0 |
Version: | 0.4.6.002 |
Built: | 2024-10-25 02:44:36 UTC |
Source: | https://github.com/yulab-smu/tidytree |
access ancestor data
ancestor(.data, .node, ...) ## S3 method for class 'tbl_tree' ancestor(.data, .node, ...)
ancestor(.data, .node, ...) ## S3 method for class 'tbl_tree' ancestor(.data, .node, ...)
.data |
phylo or tbl_tree object |
.node |
node number |
... |
additional parameters |
ancestor data
Guangchuang Yu
library(ape) tree <- rtree(4) x <- as_tibble(tree) ancestor(x, 3)
library(ape) tree <- rtree(4) x <- as_tibble(tree) ancestor(x, 3)
convert a tree object to treedata object
as.treedata(tree, ...) ## S3 method for class 'tbl_tree' as.treedata(tree, ...)
as.treedata(tree, ...) ## S3 method for class 'tbl_tree' as.treedata(tree, ...)
tree |
tree object |
... |
additional parameters |
treedata object
library(ape) set.seed(2017) tree <- rtree(4) d <- tibble(label = paste0('t', 1:4), trait = rnorm(4)) x <- as_tibble(tree) full_join(x, d, by = 'label') %>% as.treedata
library(ape) set.seed(2017) tree <- rtree(4) d <- tibble(label = paste0('t', 1:4), trait = rnorm(4)) x <- as_tibble(tree) full_join(x, d, by = 'label') %>% as.treedata
as.ultrametric
as.ultrametric(tree, ...)
as.ultrametric(tree, ...)
tree |
tree object |
... |
additional parameters |
treedata or phylo object
access child data
child(.data, .node, ...) ## S3 method for class 'tbl_tree' child(.data, .node, ...)
child(.data, .node, ...) ## S3 method for class 'tbl_tree' child(.data, .node, ...)
.data |
phylo or tbl_tree object |
.node |
node number |
... |
additional parameters |
child data
Guangchuang Yu
library(ape) tree <- rtree(4) x <- as_tibble(tree) child(x, 4)
library(ape) tree <- rtree(4) x <- as_tibble(tree) child(x, 4)
drop.tip method
drop.tip(object, tip, ...) keep.tip(object, tip, ...) ## S4 method for signature 'treedata' drop.tip(object, tip, ...) ## S4 method for signature 'phylo' drop.tip(object, tip, ...) ## S4 method for signature 'treedata' keep.tip(object, tip, ...) ## S4 method for signature 'phylo' keep.tip(object, tip, ...)
drop.tip(object, tip, ...) keep.tip(object, tip, ...) ## S4 method for signature 'treedata' drop.tip(object, tip, ...) ## S4 method for signature 'phylo' drop.tip(object, tip, ...) ## S4 method for signature 'treedata' keep.tip(object, tip, ...) ## S4 method for signature 'phylo' keep.tip(object, tip, ...)
object |
A treedata or phylo object |
tip |
a vector of mode numeric or character specifying the tips to delete |
... |
additional parameters |
updated object
Casey Dunn http://dunnlab.org and Guangchuang Yu https://guangchuangyu.github.io
drop.tip for phylo object is a wrapper method of ape::drop.tip from the ape package. The documentation you should read for the drop.tip function can be found here: drop.tip
library(tidytree) set.seed(123) tr <- ape::rtree(6) da <- data.frame(id=tip.label(tr), value = letters[seq_len(6)]) trda <- tr %>% dplyr::left_join(da, by = c('label'='id')) tr1 <- drop.tip(tr, c("t2", "t1")) tr2 <- keep.tip(tr, c("t2", "t1"))
library(tidytree) set.seed(123) tr <- ape::rtree(6) da <- data.frame(id=tip.label(tr), value = letters[seq_len(6)]) trda <- tr %>% dplyr::left_join(da, by = c('label'='id')) tr1 <- drop.tip(tr, c("t2", "t1")) tr2 <- keep.tip(tr, c("t2", "t1"))
get associated data stored in treedata object
get_tree_data(tree_object)
get_tree_data(tree_object)
tree_object |
a |
tbl_df
guangchuang yu
get.data method
get.data method
get.data(object, ...) ## S4 method for signature 'treedata' get.data(object)
get.data(object, ...) ## S4 method for signature 'treedata' get.data(object)
object |
|
... |
additional parameter |
associated data of phylogeny
get.fields method
get.fields(object, ...) ## S4 method for signature 'treedata' get.fields(object)
get.fields(object, ...) ## S4 method for signature 'treedata' get.fields(object)
object |
|
... |
additional parameter |
available annotation variables
access tree text (newick text) from tree object
get.treetext(object, ...) ## S4 method for signature 'treedata' get.treetext(object)
get.treetext(object, ...) ## S4 method for signature 'treedata' get.treetext(object)
object |
treedata object |
... |
additional parameter |
phylo object
calculate total number of nodes
getNodeNum(tree)
getNodeNum(tree)
tree |
tree object |
number
Guangchuang Yu
getNodeNum(rtree(30))
getNodeNum(rtree(30))
grouping clades
groupClade(.data, .node, group_name = "group", overlap = "overwrite", ...)
groupClade(.data, .node, group_name = "group", overlap = "overwrite", ...)
.data |
tree object (phylo, treedata, tbl_tree, ggtree etc.) |
.node |
selected nodes |
group_name |
character the name of the group cluster, default is |
overlap |
character one of |
... |
additional parameter |
updated tree with group information or group index
Guangchuang Yu
grouping OTUs
groupOTU(.data, .node, group_name = "group", ...)
groupOTU(.data, .node, group_name = "group", ...)
.data |
tree object (phylo, treedata, tbl_tree, ggtree etc.) |
.node |
selected nodes |
group_name |
character the name of the group cluster, default is |
... |
additional parameter |
updated tree with group information or group index
Guangchuang Yu
whether the node is a tip
isTip(.data, .node, ...) ## S3 method for class 'tbl_tree' isTip(.data, .node, ...) ## S3 method for class 'phylo' isTip(.data, .node, ...) ## S3 method for class 'treedata' isTip(.data, .node, ...)
isTip(.data, .node, ...) ## S3 method for class 'tbl_tree' isTip(.data, .node, ...) ## S3 method for class 'phylo' isTip(.data, .node, ...) ## S3 method for class 'treedata' isTip(.data, .node, ...)
.data |
phylo, treedata or tbl_tree object |
.node |
node number |
... |
additional parameters |
logical value
Guangchuang Yu
access most recent common ancestor data
MRCA(.data, ...)
MRCA(.data, ...)
.data |
phylo or tbl_tree object |
... |
additional parameters |
MRCA data
Guangchuang Yu
number of nodes
## S3 method for class 'treedata' Nnode(phy, internal.only = TRUE, ...)
## S3 method for class 'treedata' Nnode(phy, internal.only = TRUE, ...)
phy |
treedata object |
internal.only |
whether only count internal nodes |
... |
additional parameters |
number of nodes
Guangchuang Yu
Nnode(rtree(30))
Nnode(rtree(30))
extract the node label of phylo, treedata or tbl_tree
node.label(x, node = "internal", ...)
node.label(x, node = "internal", ...)
x |
object, should be one of |
node |
character, to extract which type node label,
default is |
... |
additional parameters. |
label character vector.
convert tree label to internal node number
nodeid(tree, label)
nodeid(tree, label)
tree |
tree object |
label |
tip/node label(s) |
node number
Guangchuang Yu
convert internal node number tip/node label
nodelab(tree, id)
nodelab(tree, id)
tree |
tree object |
id |
node number |
tip/node label(s)
Guangchuang Yu
access offspring data
offspring(.data, .node, tiponly, self_include, ...) ## S3 method for class 'tbl_tree' offspring(.data, .node, tiponly = FALSE, self_include = FALSE, ...)
offspring(.data, .node, tiponly, self_include, ...) ## S3 method for class 'tbl_tree' offspring(.data, .node, tiponly = FALSE, self_include = FALSE, ...)
.data |
phylo or tbl_tree object |
.node |
node number |
tiponly |
whether only return tip nodes |
self_include |
whether include the input node, only applicable for tiponly = FALSE |
... |
additional parameters |
offspring data
Guangchuang Yu
library(ape) tree <- rtree(4) x <- as_tibble(tree) offspring(x, 4)
library(ape) tree <- rtree(4) x <- as_tibble(tree) offspring(x, 4)
access parent data
parent(.data, .node, ...) ## S3 method for class 'tbl_tree' parent(.data, .node, ...)
parent(.data, .node, ...) ## S3 method for class 'tbl_tree' parent(.data, .node, ...)
.data |
phylo or tbl_tree object |
.node |
node number |
... |
additional parameters |
parent data
Guangchuang Yu
library(ape) tree <- rtree(4) x <- as_tibble(tree) parent(x, 2)
library(ape) tree <- rtree(4) x <- as_tibble(tree) parent(x, 2)
re-root a tree
## S3 method for class 'treedata' root(phy, outgroup, node = NULL, edgelabel = TRUE, ...)
## S3 method for class 'treedata' root(phy, outgroup, node = NULL, edgelabel = TRUE, ...)
phy |
tree object |
outgroup |
a vector of mode numeric or character specifying the new outgroup |
node |
node to reroot |
edgelabel |
a logical value specifying whether to treat node labels as edge labels and thus eventually switching them so that they are associated with the correct edges. |
... |
additional parameters passed to ape::root.phylo |
rerooted treedata
access root node data
rootnode(.data, ...)
rootnode(.data, ...)
.data |
phylo or tbl_tree object |
... |
additional parameters |
root node data
Guangchuang Yu
show method for treedata
instance
show(object)
show(object)
object |
|
print info
Guangchuang Yu https://guangchuangyu.github.io
access sibling data
sibling(.data, ...)
sibling(.data, ...)
.data |
phylo or tbl_tree object |
... |
additional parameters |
sibling
Guangchuang Yu
the tip or internal node label assign of tbl_tree phylo and treedata
tip.label(x) <- value node.label(x) <- value ## S3 replacement method for class 'phylo' node.label(x) <- value ## S3 replacement method for class 'treedata' node.label(x) <- value ## S3 replacement method for class 'tbl_tree' node.label(x) <- value ## S3 replacement method for class 'phylo' tip.label(x) <- value ## S3 replacement method for class 'treedata' tip.label(x) <- value ## S3 replacement method for class 'tbl_tree' tip.label(x) <- value
tip.label(x) <- value node.label(x) <- value ## S3 replacement method for class 'phylo' node.label(x) <- value ## S3 replacement method for class 'treedata' node.label(x) <- value ## S3 replacement method for class 'tbl_tree' node.label(x) <- value ## S3 replacement method for class 'phylo' tip.label(x) <- value ## S3 replacement method for class 'treedata' tip.label(x) <- value ## S3 replacement method for class 'tbl_tree' tip.label(x) <- value
x |
object, should be one of |
value |
character, the character vector |
extract the tip label of phylo treedata or tbl_tree
tip.label(x, ...)
tip.label(x, ...)
x |
object, should be one of |
... |
additional parameters. |
This function allows for a tree object to be subset by specifying a node and returns all related nodes within a selected number of levels
tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE ) ## S3 method for class 'phylo' tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE ) ## S3 method for class 'treedata' tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE )
tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE ) ## S3 method for class 'phylo' tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE ) ## S3 method for class 'treedata' tree_subset( tree, node, levels_back = 5, group_node = TRUE, group_name = "group", root_edge = TRUE )
tree |
a tree object of class phylo |
node |
either a tip label or a node number for the given tree that will be the focus of the subsetted tree |
levels_back |
a number specifying how many nodes back from the selected node the subsetted tree should include |
group_node |
whether add grouping information of selected node |
group_name |
group name (default 'group') for storing grouping information if group_node = TRUE |
root_edge |
If TRUE (by default), set root.edge to path length of orginal root to the root of subset tree |
This function will take a tree and a specified node from
that tree and subset the tree showing all relatives back to a specified
number of nodes. This function allows for a combination of
ancestor
and offspring
to return a subsetted
tree that is of class phylo. This allows for easy graphing of the tree
with ggtree
set.seed(123) tree <- ape::rtree(6) sub_tree <- tree_subset(tree, node = "t1", levels_back = 2)
set.seed(123) tree <- ape::rtree(6) sub_tree <- tree_subset(tree, node = "t1", levels_back = 2)
treedata object contructor
treedata(...)
treedata(...)
... |
parameters |
treedata object
guangchuang yu
Class "treedata" This class stores phylogenetic tree with associated data
file
tree file
treetext
newick tree string
phylo
phylo object for tree structure
data
associated data
extraInfo
extra information, reserve for merge_tree
tip_seq
tip sequences
anc_seq
ancestral sequences
seq_type
sequence type, one of NT or AA
tipseq_file
tip sequence file
ancseq_file
ancestral sequence file
info
extra information, e.g. metadata, software version etc.
Guangchuang Yu https://guangchuangyu.github.io