Skip to contents

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]
}
#> Warning: Some of the sample abundances do not sum to exactly 1. Rounding the sum of each sample to 1 by dividing all entries by the sum of the sample.
#>     X.SampleID  Primer Final_Barcode Barcode_truncated_plus_T
#> CL3        CL3 ILBC_01        AACGCA                   TGCGTT
#> CC1        CC1 ILBC_02        AACTCG                   CGAGTT
#>     Barcode_full_length SampleType                              Description
#> CL3         CTAGCGTGCGT       Soil Calhoun South Carolina Pine soil, pH 4.9
#> CC1         CATCGACGAGT       Soil Cedar Creek Minnesota, grassland, pH 6.1
#>        215972      31759     30678
#> CL3 0.0000000 0.00000000 0.0000000
#> CC1 0.1578947 0.05263158 0.1578947