phyloseq_validate: Check for (and fix) common problems with phyloseq objects

View source: R/phyloseq_validate.R

phyloseq_validateR Documentation

Check for (and fix) common problems with phyloseq objects

Description

  • It checks for, and messages about, common uninformative entries in the tax_table, which often cause unwanted results

  • If there is no sample_data, it creates a sample_data dataframe with the sample_names (as "SAMPLE" variable)

  • If there is no tax_table, it creates a 1-column tax_table matrix with the taxa_names, and calls the rank "unique"

  • If remove_undetected = TRUE, it removes taxa where phyloseq::taxa_sums() is equal to zero, with a warning

Usage

phyloseq_validate(
  ps,
  remove_undetected = FALSE,
  min_tax_length = 4,
  verbose = TRUE
)

Arguments

ps

phyloseq object

remove_undetected

if TRUE, removes taxa that sum to zero across all samples

min_tax_length

minimum number of characters to not consider a tax_table entry suspiciously short

verbose

print informative messages if true

Value

possibly modified phyloseq object

Examples

data(dietswap, package = "microbiome")

# expect warning about taxa summing to zero
phyloseq_validate(dietswap, remove_undetected = TRUE, verbose = TRUE)

# verbose = FALSE will suppress messages and warnings but still:
# replace NULL sample_data and remove taxa that sum to 0 across all samples
# (if remove_undetected = TRUE)
phyloseq_validate(dietswap, verbose = FALSE)

# Sometimes you might have a phyloseq with no sample_data
# This isn't compatible with some microViz functions, like comp_barplot
# So some functions internally use phyloseq_validate to fix this
dietswap@sam_data <- NULL
phyloseq_validate(dietswap)

# Sometimes you might have a phyloseq with no tax_table
# This isn't compatible with some microViz functions, like tax_top,
# so this is another reason to start your analyses with phyloseq_validate!
data("soilrep", package = "phyloseq")
soilrep # has NULL tax_table
phyloseq_validate(soilrep)

# If no messages or warnings are emitted,
# this means no problems were detected, and nothing was changed
# (but only if verbose = TRUE)

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.