transform_pq: Unified dispatcher for all OTU-table transformations and...

View source: R/normalize_pq.R

transform_pqR Documentation

Unified dispatcher for all OTU-table transformations and normalisations

Description

lifecycle-experimental

Single entry-point for all count-table transformations available in MiscMetabar. Ecological methods ("tss", "hellinger", "clr", "rclr", "log1p", "z", "pa", "rank") are delegated to vegan::decostand(). Library-size normalisation methods ("rarefy", "srs", "gmpr", "css", "tmm", "vst") and the McKnight log-log residual method ("mcknight_residuals") are delegated to their dedicated ⁠*_pq()⁠ functions. All ... arguments are forwarded to the underlying function.

Usage

transform_pq(
  physeq,
  method = c("tss", "hellinger", "clr", "rclr", "log1p", "z", "pa", "rank",
    "normalize_prop", "rarefy", "srs", "gmpr", "css", "tmm", "vst", "mcknight_residuals"),
  pseudocount = 1,
  ...
)

Arguments

physeq

(required) a phyloseq-class object obtained using the phyloseq package.

method

(character, default "tss") transformation to apply. One of:

"tss"

Total Sum Scaling — divide by library size.

"hellinger"

Square-root of proportions. Good for ordination.

"clr"

Centred log-ratio (adds pseudocount to handle zeros).

"rclr"

Robust CLR (adds pseudocount to handle zeros).

"log1p"

\log(1 + x) transformation.

"z"

Per-taxon z-score standardisation.

"pa"

Presence/absence (0/1).

"rank"

Replace counts by within-sample ranks.

"normalize_prop"

TSS × constant + log, via normalize_prop_pq().

"rarefy"

Rarefaction to equal depth, via rarefy_pq().

"srs"

Scaling with Ranked Subsampling, via srs_pq(). Requires the SRS package.

"gmpr"

Geometric Mean of Pairwise Ratios, via gmpr_pq().

"css"

Cumulative Sum Scaling, via css_pq(). Requires the metagenomeSeq package.

"tmm"

Trimmed Mean of M-values, via tmm_pq(). Requires the edgeR package.

"vst"

Variance Stabilising Transformation, via vst_pq(). Requires the DESeq2 package.

"mcknight_residuals"

Log-log depth residuals added to sample_data, via mcknight_residuals_pq().

pseudocount

(numeric, default 1) added before "clr" / "rclr" to avoid non-positive values. Ignored for all other methods.

...

Additional arguments forwarded to the underlying function (vegan::decostand(), rarefy_pq(), srs_pq(), etc.).

Value

A new phyloseq-class object with a transformed otu_table (and augmented sample_data for "mcknight_residuals").

Author(s)

Adrien Taudière

See Also

normalize_prop_pq(), rarefy_pq(), srs_pq(), gmpr_pq(), css_pq(), tmm_pq(), vst_pq(), mcknight_residuals_pq(), as_binary_otu_table(), vegan::decostand()

Examples



data_f_tss <- transform_pq(data_fungi_mini, method = "tss")
sample_sums(data_f_tss)

data_f_hell <- transform_pq(data_fungi_mini, method = "hellinger")
data_f_clr <- transform_pq(data_fungi_mini, method = "clr")
data_f_rclr <- transform_pq(data_fungi_mini, method = "rclr")
data_f_log1p <- transform_pq(data_fungi_mini, method = "log1p")
data_f_z <- transform_pq(data_fungi_mini, method = "z")
data_f_pa <- transform_pq(data_fungi_mini, method = "pa")
data_f_rank <- transform_pq(data_fungi_mini, method = "rank")
data_f_norm_prop_log10 <- transform_pq(data_fungi_mini,
  method = "normalize_prop", base_log = 10
)
data_f_norm_prop_no_log <- transform_pq(data_fungi_mini,
  method = "normalize_prop", base_log = NULL
)
data_f_norm_prop_log2 <- transform_pq(data_fungi_mini,
  method = "normalize_prop", base_log = 2
)
data_f_rarefy <- transform_pq(data_fungi_mini, method = "rarefy", seed = 1)
data_f_srs <- transform_pq(data_fungi_mini, method = "srs", seed = 1)
data_f_gmpr <- transform_pq(data_fungi_mini, method = "gmpr")
data_f_css <- transform_pq(data_fungi_mini, method = "css")
data_f_tmm <- transform_pq(data_fungi_mini, method = "tmm")
data_f_vst <- transform_pq(data_fungi_mini, method = "vst")
data_f_mcknight <- transform_pq(data_fungi_mini, method = "mcknight_residuals")

otu_list <- list(
  hell = unclass(data_f_hell@otu_table),
  clr = unclass(data_f_clr@otu_table),
  rclr = unclass(data_f_rclr@otu_table),
  log1p = unclass(data_f_log1p@otu_table),
  z = unclass(data_f_z@otu_table),
  rarefy = unclass(data_f_rarefy@otu_table)
)
pairs_cor <- sapply(
  otu_list,
  \(x) sapply(otu_list, \(y) cor(as.vector(x), as.vector(y)))
)
pairs_cor

plot(unclass(data_f_mcknight@otu_table), unclass(data_f_css@otu_table))
plot(unclass(data_f_rarefy@otu_table), unclass(data_f_clr@otu_table))



MiscMetabar documentation built on June 8, 2026, 5:07 p.m.