collapse_taxa: Subset a phyloseq object to a set of taxa.

View source: R/collapse_taxa.R

collapse_taxaR Documentation

Subset a phyloseq object to a set of taxa.

Description

This function takes a phyloseq object and a list of taxon ids to be kept, and discards or merges all other taxa.

Usage

collapse_taxa(
  ps_obj,
  taxa_to_keep,
  discard_other = FALSE,
  merged_label = "Other"
)

Arguments

ps_obj

Phyloseq object

taxa_to_keep

taxon ids (taxids) to be kept. These taxon ids need to be part of taxa_names(ps_obj)

discard_other

if TRUE, any taxon not in taxa_to_keep is discard. If FALSE, they are collapsed into a single taxon labeled other_label

merged_label

Label for the new merged taxon

Details

This function is essentially a wrapper around prune_taxa and merge_taxa.

This function, together with top_taxa replaces get_top_taxa. Identical output can be obtained by setting FUN = sum in top_taxa.

Value

A phyloseq object

Examples

data(GlobalPatterns)

# Top 10 most abundant ASVs over all samples, collapse other ASVs into 'Low abundance'
top <- top_taxa(GlobalPatterns, 10)
ps_collapsed <- collapse_taxa(GlobalPatterns,
                              taxa_to_keep = top$top_taxa$taxid,
                              merged_label = "Low abundance")

# Top 10 most abundant ASVs over all samples, discard other taxa
top <- top_taxa(GlobalPatterns, 10)
ps_collapsed <- collapse_taxa(GlobalPatterns, taxa_to_keep = top$taxid,
                              discard_other = TRUE)

# Keep genus Clostridium, collapse all others into Other genera
ps_tmp <- subset_taxa(GlobalPatterns, Genus == "Clostridium")
taxids <- taxa_names(ps_tmp)
ps_collapsed <- collapse_taxa(GlobalPatterns, taxa_to_keep = taxids,
                              merged_label = "Other genera")


gmteunisse/Fantaxtic documentation built on June 7, 2024, 8:47 a.m.