Read a tree file and store it in otu_tree or taxa_tree, optionally
aligning the imported tree to the current dataset.
Examples
data("global_patterns", package = "microbiomedataset")
x0 <- prune_taxa(global_patterns, variable_id = global_patterns@variable_info$variable_id[1:80])
x <- microbiomedataset::convert2microbiome_dataset(
microbiomedataset::convert2phyloseq(x0)
)
#> Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
#> Also defined by ‘tidytree’
#> Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
#> Also defined by ‘tidytree’
#> Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
#> Also defined by ‘tidytree’
#> Found more than one class "phylo" in cache; using the first, from namespace 'phyloseq'
#> Also defined by ‘tidytree’
tree_file <- tempfile(fileext = ".nwk")
otu_phylo <- ape::rtree(
n = nrow(x@variable_info),
tip.label = x@variable_info$variable_id
)
ape::write.tree(otu_phylo, file = tree_file)
x <- import_tree(x, file = tree_file, tree = "otu_tree")
class(x@otu_tree)
#> [1] "treedata"
#> attr(,"package")
#> [1] "tidytree"
