Skip to contents

Rebuild taxa_tree using only taxa that match selected labels at a chosen taxonomy rank, without changing the abundance matrix.

Usage

filter_tree_by_rank(
  object,
  taxonomic_rank = c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", "Species"),
  taxa,
  keep = TRUE,
  na_keep = FALSE
)

Arguments

object

A microbiome_dataset object.

taxonomic_rank

A taxonomy rank in variable_info.

taxa

Character vector of taxa labels used for filtering.

keep

Should the provided taxa be kept? Defaults to TRUE.

na_keep

Should taxa with missing rank be kept? Defaults to FALSE.

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:120])
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’
x <- filter_tree_by_rank(
  x,
  taxonomic_rank = "Phylum",
  taxa = c("Bacteroidetes", "Firmicutes")
)
class(x@taxa_tree)
#> [1] "NULL"