7 Create psExtra Objects

After the creation of phyloseq objects, we proceed to create psExtra objects using functionalities provided by the microViz package. The psExtra objects extend the capabilities of phyloseq objects by incorporating additional metadata, experimental conditions, or statistical results, enhancing the depth and breadth of analyses performed using microbiome data.

7.1 Prerequisite

Before creating psExtra objects, it’s essential to have pre-existing phyloseq objects containing microbiome data and associated metadata. These phyloseq objects serve as the input data for creating psExtra objects. For example, pre-existing phyloseq objects such as ps_dietswap, ps_GlobalPatterns, ps_caporaso, and ps_kostic_crc prepared in the previous sections should be available.

7.2 Load pre-existing phyloseq objects

load("data/phyloseq_objects.rda", verbose = TRUE)
Loading objects:
  ps_GlobalPatterns
  ps_dietswap
  ps_caporaso
  ps_kostic_crc

7.3 Aggregate taxonomic data

# Load required packages
library(phyloseq) # For handling microbiome data
library(microViz) # For advanced microbiome visualization

# Assuming ps_dietswap is already loaded or available

# Aggregate taxonomic data
psextra_clr_dietswap <- tax_agg(
  ps = ps_dietswap,
  rank = "Genus") %>% 
  tax_transform(trans = "clr")

# Display a subset of the transformed data
cat("\nCentered log Ratio (CLR) Transformation\n")

Centered log Ratio (CLR) Transformation
psextra_clr_dietswap %>% 
  otu_get() %>%
  .[1:4, 1:3]
OTU Table:          [3 taxa and 4 samples]
                     taxa are columns
         Phascolarctobacterium faecium et rel. Actinomycetaceae
Sample-1                            -0.2120560        -3.555474
Sample-2                            -0.6717570        -2.040486
Sample-3                             0.1808535        -3.114983
Sample-4                            -0.7078750        -1.943474
         Eubacterium hallii et rel.
Sample-1                  0.6828174
Sample-2                  2.2768872
Sample-3                  1.2544645
Sample-4                  1.2914479

# Aggregate taxonomic data
psextra_id_dietswap <- tax_agg(
  ps = ps_dietswap,
  rank = "Genus") %>% 
  tax_transform(trans = "identity")

# Display a subset of the transformed data
cat("\nIdentity Transformation\n")

Identity Transformation
psextra_id_dietswap %>% 
  otu_get() %>%
  .[1:4, 1:3]
OTU Table:          [3 taxa and 4 samples]
                     taxa are columns
         Phascolarctobacterium faecium et rel. Actinomycetaceae
Sample-1                                     4                0
Sample-2                                     5                1
Sample-3                                    13                0
Sample-4                                     4                1
         Eubacterium hallii et rel.
Sample-1                         10
Sample-2                        102
Sample-3                         39
Sample-4                         31

# Aggregate taxonomic data
psextra_log10p_dietswap <- tax_agg(
  ps = ps_dietswap,
  rank = "Genus") %>% 
  tax_transform(trans = "log10p")

# Display a subset of the transformed data
cat("\nLog10p Transformation\n")

Log10p Transformation
psextra_log10p_dietswap %>% 
  otu_get() %>%
  .[1:4, 1:3]
OTU Table:          [3 taxa and 4 samples]
                     taxa are columns
         Phascolarctobacterium faecium et rel. Actinomycetaceae
Sample-1                             0.6989700          0.00000
Sample-2                             0.7781513          0.30103
Sample-3                             1.1461280          0.00000
Sample-4                             0.6989700          0.30103
         Eubacterium hallii et rel.
Sample-1                   1.041393
Sample-2                   2.012837
Sample-3                   1.602060
Sample-4                   1.505150

7.4 Confirm the psExtra class

summary(psextra_clr_dietswap)
 Length   Class    Mode 
      1 psExtra      S4 
summary(psextra_id_dietswap)
 Length   Class    Mode 
      1 psExtra      S4 
summary(psextra_log10p_dietswap)
 Length   Class    Mode 
      1 psExtra      S4 

7.5 Save psExtra to R object

save(psextra_clr_dietswap, psextra_id_dietswap, psextra_log10p_dietswap, file = "data/phyloseq_extra_objects.rda")