View source: R/collapse_taxa.R
collapse_taxa | R Documentation |
This function takes a phyloseq object and a list of taxon ids to be kept, and discards or merges all other taxa.
collapse_taxa(
ps_obj,
taxa_to_keep,
discard_other = FALSE,
merged_label = "Other"
)
ps_obj |
Phyloseq object |
taxa_to_keep |
taxon ids (taxids) to be kept. These taxon ids need to
be part of |
discard_other |
if |
merged_label |
Label for the new merged taxon |
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.
A phyloseq object
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.