Skip to contents

Read a tree file and store it in otu_tree or taxa_tree, optionally aligning the imported tree to the current dataset.

Usage

import_tree(
  object,
  file,
  tree = c("otu_tree", "taxa_tree"),
  format = c("newick"),
  align = TRUE
)

Arguments

object

A microbiome_dataset object.

file

Input tree path.

tree

Tree slot to import into, either "otu_tree" or "taxa_tree".

format

Tree format. Currently only "newick" is supported.

align

Should the imported tree be aligned to the current dataset?

Value

A microbiome_dataset object.

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"