6 Reviewing Phyloseq Objects
In this section, we demonstrate basic functions for reviewing and exploring the contents of phyloseq objects. By familiarizing ourselves with these functions, we gain insights into the structure, composition, and metadata associated with phyloseq objects, facilitating effective analysis and interpretation of microbiome data.
library(phyloseq)
library(ape)
ps <- ps_dietswap
ps
phyloseq-class experiment-level object
otu_table() OTU Table: [ 130 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 130 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 130 tips and 129 internal nodes ]
6.3 Split by taxon name, e.g. Firmicutes
library(metagMisc) # foe phyloseq_sep_tax()
taxa_stats <- phyloseq_sep_tax(ps, TaxRank = "Phylum", drop_NA = FALSE)
cat("\n")
taxa_stats$Firmicutes
phyloseq-class experiment-level object
otu_table() OTU Table: [ 76 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 76 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 76 tips and 75 internal nodes ]
cat("\n")
taxa_stats$Bacteroidetes
phyloseq-class experiment-level object
otu_table() OTU Table: [ 16 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 16 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 16 tips and 15 internal nodes ]
cat("\n")
taxa_stats$Actinobacteria
phyloseq-class experiment-level object
otu_table() OTU Table: [ 8 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 8 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 8 tips and 7 internal nodes ]
6.7 Abundance table
otu_table(ps)[1:5, 1:5]
OTU Table: [5 taxa and 5 samples]
taxa are rows
Sample-1 Sample-2 Sample-3 Sample-4
Phascolarctobacterium faecium et rel. 4 5 13 4
Actinomycetaceae 0 1 0 1
Eubacterium hallii et rel. 10 102 39 31
Clostridium stercorarium et rel. 6 3 9 8
Clostridium symbiosum et rel. 220 247 214 111
Sample-5
Phascolarctobacterium faecium et rel. 33
Actinomycetaceae 0
Eubacterium hallii et rel. 28
Clostridium stercorarium et rel. 3
Clostridium symbiosum et rel. 155
6.8 Taxonomy table
tax_table(ps)[1:5, ]
Taxonomy Table: [5 taxa by 3 taxonomic ranks]:
Phylum
Phascolarctobacterium faecium et rel. "Firmicutes"
Actinomycetaceae "Actinobacteria"
Eubacterium hallii et rel. "Firmicutes"
Clostridium stercorarium et rel. "Firmicutes"
Clostridium symbiosum et rel. "Firmicutes"
Family
Phascolarctobacterium faecium et rel. "Clostridium cluster IX"
Actinomycetaceae "Actinobacteria"
Eubacterium hallii et rel. "Clostridium cluster XIVa"
Clostridium stercorarium et rel. "Clostridium cluster III"
Clostridium symbiosum et rel. "Clostridium cluster XIVa"
Genus
Phascolarctobacterium faecium et rel. "Phascolarctobacterium faecium et rel."
Actinomycetaceae "Actinomycetaceae"
Eubacterium hallii et rel. "Eubacterium hallii et rel."
Clostridium stercorarium et rel. "Clostridium stercorarium et rel."
Clostridium symbiosum et rel. "Clostridium symbiosum et rel."
6.10 Taxa names
taxa_names(ps)[1:10]
[1] "Phascolarctobacterium faecium et rel."
[2] "Actinomycetaceae"
[3] "Eubacterium hallii et rel."
[4] "Clostridium stercorarium et rel."
[5] "Clostridium symbiosum et rel."
[6] "Wissella et rel."
[7] "Peptostreptococcus anaerobius et rel."
[8] "Ruminococcus bromii et rel."
[9] "Prevotella ruminicola et rel."
[10] "Yersinia et rel."
6.11 Summarize Phyloseq Object
microbiome::summarize_phyloseq(ps)
[[1]]
[1] "1] Min. number of reads = 1776"
[[2]]
[1] "2] Max. number of reads = 28883"
[[3]]
[1] "3] Total number of reads = 2949085"
[[4]]
[1] "4] Average number of reads = 13284.1666666667"
[[5]]
[1] "5] Median number of reads = 13255"
[[6]]
[1] "7] Sparsity = 0.205647955647956"
[[7]]
[1] "6] Any OTU sum to 1 or less? YES"
[[8]]
[1] "8] Number of singletons = 10"
[[9]]
[1] "9] Percent of OTUs that are singletons \n (i.e. exactly one read detected across all samples)2.30769230769231"
[[10]]
[1] "10] Number of sample variables are: 8"
[[11]]
[1] "subject" "sex" "nationality"
[4] "group" "sample" "timepoint"
[7] "timepoint.within.group" "bmi_group"
6.12 Sort Samples in ascending and descending
cat("In ascending order\n")
In ascending order
head(sort(phyloseq::sample_sums(ps), decreasing = F))
Sample-56 Sample-195 Sample-196 Sample-42 Sample-164 Sample-147
1776 4477 4606 5006 5541 5624
cat("\nIn descending order\n")
In descending order
head(sort(phyloseq::sample_sums(ps), decreasing = T))
Sample-3 Sample-11 Sample-12 Sample-54 Sample-208 Sample-20
28883 26895 25238 23529 23131 22413
6.13 Drop Samples Below a Threshold
ps1perc0 <- phyloseq::subset_samples(ps, phyloseq::sample_sums(ps) > 1)
ps1perc0
phyloseq-class experiment-level object
otu_table() OTU Table: [ 130 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 130 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 130 tips and 129 internal nodes ]
6.14 Drop Taxa Below a Threshold
pstaxa01 <- phyloseq::prune_taxa(phyloseq::taxa_sums(ps) > 1, ps)
pstaxa01
phyloseq-class experiment-level object
otu_table() OTU Table: [ 120 taxa and 222 samples ]
sample_data() Sample Data: [ 222 samples by 8 sample variables ]
tax_table() Taxonomy Table: [ 120 taxa by 3 taxonomic ranks ]
phy_tree() Phylogenetic Tree: [ 120 tips and 119 internal nodes ]