
Generate Single Time Point Microbiome Analysis Report
Source:R/mStat_generate_report_single.R
mStat_generate_report_single.RdGenerates a comprehensive PDF/HTML report for cross-sectional microbiome analysis including alpha diversity, beta diversity, and taxonomic composition.
Usage
mStat_generate_report_single(
data.obj,
group.var,
vis.adj.vars = NULL,
test.adj.vars = NULL,
strata.var = NULL,
time.var = NULL,
t.level = NULL,
alpha.obj = NULL,
alpha.name = c("shannon", "observed_species"),
depth = NULL,
dist.obj = NULL,
dist.name = c("BC", "Jaccard"),
pc.obj = NULL,
prev.filter = 0.1,
abund.filter = 1e-04,
bar.area.feature.no = 40,
heatmap.feature.no = 40,
dotplot.feature.no = 40,
vis.feature.level = NULL,
test.feature.level = NULL,
feature.dat.type = c("count", "proportion", "other"),
feature.analysis.rarafy = TRUE,
feature.mt.method = c("fdr", "none"),
feature.sig.level = 0.1,
feature.box.axis.transform = c("sqrt"),
base.size = 16,
theme.choice = "bw",
custom.theme = NULL,
palette = NULL,
pdf = TRUE,
file.ann = NULL,
pdf.wid = 11,
pdf.hei = 8.5,
output.file,
output.format = c("pdf", "html"),
...
)Arguments
- data.obj
A MicrobiomeStat data object, which is a list containing at minimum the following components:
feature.tab: A matrix of feature abundances (taxa/genes as rows, samples as columns)meta.dat: A data frame of sample metadata (samples as rows)
Optional components include:
feature.ann: A matrix/data frame of feature annotations (e.g., taxonomy)tree: A phylogenetic tree object (class "phylo")feature.agg.list: Pre-aggregated feature tables by taxonomy
Data objects can be created using converters like
mStat_convert_phyloseq_to_data_objor importers likemStat_import_qiime2_as_data_obj.- group.var
Character string specifying the column name in meta.dat containing the grouping variable (e.g., treatment, condition, phenotype). Used for between-group comparisons.
- vis.adj.vars
Character vector of covariate names to visualize in plots.
- test.adj.vars
Character vector of covariate names for statistical adjustment.
- strata.var
Character string specifying the column name in meta.dat for stratification. When provided, analyses and visualizations will be performed separately within each stratum (e.g., by site, batch, or sex).
- time.var
Character string specifying the column name in meta.dat containing the time variable. Required for longitudinal and paired analyses. Should be a factor or character with meaningful time point labels.
- t.level
Time point to subset data to (if time.var provided). Default NULL uses all data.
- alpha.obj
A list containing pre-calculated alpha diversity indices. If NULL and alpha diversity is needed, it will be calculated automatically. Names should match the alpha.name parameter (e.g., "shannon", "simpson"). See
mStat_calculate_alpha_diversity.- alpha.name
Character vector specifying which alpha diversity indices to analyze. Options include:
"shannon": Shannon diversity index
"simpson": Simpson diversity index
"observed_species": Observed species richness
"chao1": Chao1 richness estimator
"ace": ACE richness estimator
"pielou": Pielou's evenness
- depth
Numeric value or NULL. Rarefaction depth for diversity calculations. If NULL, uses minimum sample depth or no rarefaction.
- dist.obj
A list of pre-calculated distance matrices. If NULL and distances are needed, they will be calculated automatically. List names should match dist.name (e.g., "BC" for Bray-Curtis). See
mStat_calculate_beta_diversity.- dist.name
Character vector specifying which distance metrics to use. Options depend on available methods:
"BC": Bray-Curtis dissimilarity
"Jaccard": Jaccard distance
"UniFrac": Unweighted UniFrac (requires tree)
"GUniFrac": Generalized UniFrac (requires tree)
"WUniFrac": Weighted UniFrac (requires tree)
"JS": Jensen-Shannon divergence
- pc.obj
Pre-calculated PCoA/PCA results from mStat_calculate_PC. If NULL, computed automatically.
- prev.filter
Numeric value between 0 and 1. Features with prevalence (proportion of non-zero samples) below this threshold will be excluded from analysis. Default is usually 0 (no filtering).
- abund.filter
Numeric value. Features with mean abundance below this threshold will be excluded from analysis. Default is usually 0 (no filtering).
- bar.area.feature.no
Number of top features to show in bar/area plots (default 40).
- heatmap.feature.no
Number of top features to show in heatmaps (default 40).
- dotplot.feature.no
Number of top features to show in dotplots (default 40).
- vis.feature.level
Taxonomic level(s) for visualization.
- test.feature.level
Taxonomic level(s) for statistical testing.
- feature.dat.type
Character string specifying the data type of feature.tab. One of:
"count": Raw count data (will be normalized)
"proportion": Relative abundance data (should sum to 1 per sample)
"other": Pre-transformed data (no transformation applied)
- feature.analysis.rarafy
Logical, whether to rarefy data for feature analysis (default TRUE).
- feature.mt.method
Multiple testing correction: "fdr" or "none" (default "fdr").
- feature.sig.level
Significance threshold for highlighting features (default 0.1).
- feature.box.axis.transform
Y-axis transformation for boxplots: "identity", "sqrt", or "log".
- base.size
Numeric value specifying the base font size for plot text elements. Default is typically 16.
- theme.choice
Character string specifying the ggplot2 theme to use. Options include:
"bw": Black and white theme (theme_bw)
"classic": Classic theme (theme_classic)
"minimal": Minimal theme (theme_minimal)
"prism": GraphPad Prism-like theme
"nature": Nature journal style
"light": Light theme (theme_light)
Can also use a custom ggplot2 theme object via custom.theme.
- custom.theme
A custom ggplot2 theme object to override theme.choice. Should be created using ggplot2::theme() or a complete theme function.
- palette
Character vector of colors or a named palette for the plot. If NULL, uses default MicrobiomeStat color scheme. Can be:
A vector of color codes (e.g., c("#E41A1C", "#377EB8"))
A palette name recognized by the plotting function
Logical. If TRUE, saves the plot(s) to PDF file(s) in the current working directory. Default is TRUE.
- file.ann
Character string for additional annotation to append to output filenames. Useful for distinguishing multiple outputs.
- pdf.wid
Numeric value specifying the width of PDF output in inches. Default is typically 11.
- pdf.hei
Numeric value specifying the height of PDF output in inches. Default is typically 8.5.
- output.file
Output report filename (required).
- output.format
Output format: "pdf" or "html".
- ...
Additional arguments passed to internal functions.
Examples
if (FALSE) { # \dontrun{
set.seed(123)
library(aplot)
data(peerj32.obj)
mStat_generate_report_single(
data.obj = peerj32.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "group",
vis.adj.vars = NULL,
test.adj.vars = NULL,
time.var = "time",
alpha.name = c("shannon", "observed_species"),
depth = NULL,
dist.name = c("BC",'Jaccard'),
t.level = "1",
feature.box.axis.transform = "sqrt",
strata.var = NULL,
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = c("Phylum", "Family", "Genus"),
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/peerj32.obj_report.pdf",
output.format = c("pdf")
)
mStat_generate_report_single(
data.obj = peerj32.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "group",
vis.adj.vars = NULL,
test.adj.vars = NULL,
time.var = "time",
alpha.name = c("shannon", "observed_species"),
depth = NULL,
dist.name = c("BC",'Jaccard'),
t.level = "1",
feature.box.axis.transform = "sqrt",
strata.var = NULL,
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = c("Phylum", "Family", "Genus"),
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/peerj32.obj_report.html",
output.format = c("html")
)
data(subset_T2D.obj)
mStat_generate_report_single(
data.obj = subset_T2D.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "subject_race",
vis.adj.vars = "sample_body_site",
test.adj.vars = "sample_body_site",
time.var = "visit_number_num",
alpha.name = c("shannon", "observed_species"),
depth = 2000,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "subject_gender",
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = "Family",
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/subset_T2D.obj_report.pdf"
)
mStat_generate_report_single(
data.obj = subset_T2D.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "subject_race",
vis.adj.vars = "sample_body_site",
test.adj.vars = "sample_body_site",
time.var = "visit_number_num",
alpha.name = c("shannon", "observed_species"),
depth = 2000,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "subject_gender",
vis.feature.level = c("Order", "Family", "Genus"),
test.feature.level = c("Order", "Family", "Genus"),
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/subset_T2D.obj_report.html",
output.format = c("html")
)
mStat_generate_report_single(
data.obj = subset_T2D.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "subject_race",
vis.adj.vars = "sample_body_site",
test.adj.vars = "sample_body_site",
time.var = "visit_number_num",
alpha.name = c("shannon", "observed_species"),
depth = 2000,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "subject_gender",
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = "Family",
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/report.pdf"
)
mStat_generate_report_single(
data.obj = subset_T2D.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "subject_race",
vis.adj.vars = "sample_body_site",
test.adj.vars = "sample_body_site",
time.var = "visit_number_num",
alpha.name = c("shannon", "observed_species"),
depth = 2000,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "subject_gender",
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = "Family",
feature.dat.type = "count",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/report.pdf"
)
data(ecam.obj)
mStat_generate_report_single(
data.obj = ecam.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "delivery",
vis.adj.vars = "diet",
test.adj.vars = "diet",
time.var = "month_num",
alpha.name = c("shannon", "observed_species"),
depth = NULL,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "antiexposedall",
vis.feature.level = c("Phylum", "Family", "Genus"),
test.feature.level = "Family",
feature.dat.type = "proportion",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/ecam.obj_report.pdf"
)
mStat_generate_report_single(
data.obj = ecam.obj,
dist.obj = NULL,
alpha.obj = NULL,
group.var = "delivery",
vis.adj.vars = "diet",
test.adj.vars = "diet",
time.var = "month_num",
alpha.name = c("shannon", "observed_species"),
depth = NULL,
dist.name = c("BC",'Jaccard'),
t.level = 1,
feature.box.axis.transform = "sqrt",
strata.var = "antiexposedall",
vis.feature.level = c("Order", "Family", "Genus"),
test.feature.level = c("Order", "Family", "Genus"),
feature.dat.type = "proportion",
theme.choice = "bw",
base.size = 20,
feature.mt.method = "none",
feature.sig.level = 0.2,
output.file = "/Users/apple/Research/MicrobiomeStat/result/ecam.obj_report.html",
output.format = c("html")
)
} # }