relab_phyloseq: Generate a relative abundance matrix with sample metadata and...

View source: R/helper_functions.R

relab_phyloseqR Documentation

Generate a relative abundance matrix with sample metadata and OTU abundances from a phyloseq object.

Description

The R package phyloseq streamlines the storage and analysis of microbiome sequence data. This function takes a phyloseq object and extracts the OTU table and the sample metadata and combines them into one relative abundance matrix with rows corresponding to samples, metadata on the left-hand side, and OTU relative abundances on the right-hand side.

Usage

relab_phyloseq(phyloseq_object)

Arguments

phyloseq_object

A phyloseq object containing both an OTU table (otu_table) and sample metadata (sample_data).

Value

A data frame with rows representing samples and columns representing sample data categories or OTU relative abundances. OTU abundances are automatically normalized so that they sum to 1 for each sample, though a warning will be provided if a renormalization was necessary.

Examples

if (requireNamespace("phyloseq", quietly = TRUE)) {
  data(GlobalPatterns, package = "phyloseq")

# Make a small phyloseq object for demonstration
phyloseq_subset = phyloseq::subset_taxa(phyloseq::subset_samples(GlobalPatterns,
                                                                 X.SampleID %in%
                                                                 c("CL3", "CC1")),
                                        Order == "Cenarchaeales")
  otu_table = relab_phyloseq(phyloseq_subset)
  otu_table[, 1:10]
}

FAVA documentation built on April 4, 2025, 4:47 a.m.