Skip to contents

This function generates a comprehensive report for microbial ecology analysis, including alpha diversity, beta diversity, and taxonomic feature analyses. The function is designed to perform analysis on cross-sectional data, a single time point from longitudinal or paired data.

Usage

mStat_generate_report_single(
  data.obj,
  group.var,
  vis.adj.vars = NULL,
  test.adj.vars = NULL,
  strata.var = NULL,
  subject.var,
  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,
  ...
)

Arguments

data.obj

A list object in a format specific to MicrobiomeStat, which can include components such as feature.tab (matrix), feature.ann (matrix), meta.dat (data.frame), tree, and feature.agg.list (list). The data.obj can be converted from other formats using several functions from the MicrobiomeStat package, including: 'mStat_convert_DGEList_to_data_obj', 'mStat_convert_DESeqDataSet_to_data_obj', 'mStat_convert_phyloseq_to_data_obj', 'mStat_convert_SummarizedExperiment_to_data_obj', 'mStat_import_qiime2_as_data_obj', 'mStat_import_mothur_as_data_obj', 'mStat_import_dada2_as_data_obj', and 'mStat_import_biom_as_data_obj'. Alternatively, users can construct their own data.obj. Note that not all components of data.obj may be required for all functions in the MicrobiomeStat package.

group.var

Variable name used for grouping samples.

vis.adj.vars

Character vector, names of columns in the metadata containing covariates to visualize in plots, in addition to the primary variables of interest such as groups. For example, if sex is provided in vis.adj.vars, plots will display facets or colors for different sex groups. This allows visualization of effects across multiple covariates. Default is NULL, which indicates only the primary variables of interest will be visualized without additional covariates.

test.adj.vars

Character vector, names of columns in the metadata containing covariates to be adjusted for in statistical tests and models, such as linear mixed effects models for longitudinal data analysis. This allows the user to account for the effects of additional variables in assessing the effects of primary variables of interest such as time and groups. Default is NULL, which indicates no covariates are adjusted for in statistical testing.

strata.var

Variable to stratify the analysis by (optional).

subject.var

Variable name used for subject identification.

time.var

Variable name used for time points.

t.level

Character string specifying the time level/value to subset data to, if a time variable is provided. Default NULL does not subset data.

alpha.obj

An optional list containing pre-calculated alpha diversity indices. If NULL (default), alpha diversity indices will be calculated using mStat_calculate_alpha_diversity function from MicrobiomeStat package.

alpha.name

The alpha diversity index to be plotted. Supported indices include "shannon", "simpson", "observed_species", "chao1", "ace", and "pielou".

depth

An integer specifying the sequencing depth for the "Rarefy" and "Rarefy-TSS" methods. If NULL, no rarefaction is performed.

dist.obj

Distance matrix between samples, usually calculated using mStat_calculate_beta_diversity function. If NULL, beta diversity will be automatically computed from data.obj using mStat_calculate_beta_diversity.

dist.name

A character vector specifying which beta diversity indices to calculate. Supported indices are "BC" (Bray-Curtis), "Jaccard", "UniFrac" (unweighted UniFrac), "GUniFrac" (generalized UniFrac), "WUniFrac" (weighted UniFrac), and "JS" (Jensen-Shannon divergence). If a name is provided but the corresponding object does not exist within dist.obj, it will be computed internally. If the specific index is not supported, an error message will be returned. Default is c('BC', 'Jaccard').

pc.obj

A list containing the results of dimension reduction/Principal Component Analysis. This should be the output from functions like mStat_calculate_PC, containing the PC coordinates and other metadata. If NULL (default), dimension reduction will be automatically performed using metric multidimensional scaling (MDS) via mStat_calculate_PC. The pc.obj list structure should contain:

points

A matrix with samples as rows and PCs as columns containing the coordinates.

eig

Eigenvalues for each PC dimension.

vectors

Loadings vectors for features onto each PC.

Other metadata

like method, dist.name, etc.

See mStat_calculate_PC function for details on output format.

prev.filter

Numeric value specifying the minimum prevalence threshold for filtering taxa before analysis. Taxa with prevalence below this value will be removed. Prevalence is calculated as the proportion of samples where the taxon is present. Default 0 removes no taxa by prevalence filtering.

abund.filter

Numeric value specifying the minimum abundance threshold for filtering taxa before analysis. Taxa with mean abundance below this value will be removed. Abundance refers to counts or proportions depending on feature.dat.type. Default 0 removes no taxa by abundance filtering.

bar.area.feature.no

A numeric value indicating the number of top abundant features to retain in both barplot and areaplot. Features with average relative abundance ranked below this number will be grouped into 'Other'. Default 20.

heatmap.feature.no

A numeric value indicating the number of top abundant features to retain in the heatmap. Features with average relative abundance ranked below this number will be grouped into 'Other'. Default 20.

dotplot.feature.no

A numeric value indicating the number of top abundant features to retain in the dotplot. Features with average relative abundance ranked below this number will be grouped into 'Other'. Default 40.

vis.feature.level

A character vector specifying one or more column names in the feature annotation matrix (feature.ann) of data.obj to use for visualization and plotting. This can be a taxonomic level like "Phylum" or "Genus" for microbiome data, a cell type identifier such as "CellType" for single-cell data, or a pathway level such as "Pathway_L1", "Pathway_L2", or "Pathway_L3" for KEGG data. Multiple columns can be provided, and data will be plotted separately for each column. If you want to avoid aggregation, you can set it to "original", and no aggregation will be performed.

test.feature.level

A character vector specifying one or more column names in the feature annotation matrix (feature.ann) of data.obj to use for testing or analytical purposes. This can be a taxonomic level like "Phylum" or "Genus" for microbiome data, a cell type identifier such as "CellType" for single-cell data, or a pathway level such as "Pathway_L1", "Pathway_L2", or "Pathway_L3" for KEGG data. Multiple columns can be provided, and data will be analyzed separately for each column. If you want to avoid aggregation, you can set it to "original", and no aggregation will be performed.

feature.dat.type

The type of the feature data, which determines how the data is handled in downstream analyses. Should be one of: - "count": Raw count data, will be normalized by the function. - "proportion": Data that has already been normalized to proportions/percentages. - "other": Custom abundance data that has unknown scaling. No normalization applied. The choice affects preprocessing steps as well as plot axis labels. Default is "count", which assumes raw OTU table input.

feature.analysis.rarafy

Logical, indicating whether to rarefy the data at the feature-level for analysis. If TRUE, the feature data will be rarefied before analysis. Default is TRUE.

feature.mt.method

A character specifying the multiple testing method for features. This is specifically used for volcano plot visualization. The options are "fdr" for false discovery rate or "none" for no multiple testing correction. The default is "fdr".

feature.sig.level

A numeric value specifying the significance level cutoff for highlighting features in the volcano plot. The default is 0.1.

feature.box.axis.transform

A string indicating the transformation to apply to the data before plotting. Options are: "identity" for no transformation (default), "sqrt" for square root transformation, and "log" for logarithmic transformation. In the function `mStat_generate_report_single`, this parameter is only used in `generate_taxa_boxplot_single` and `generate_taxa_indiv_boxplot_single`. In other functions, it is also used solely to adjust boxplots related to feature functions.

base.size

Base font size for the generated plots.

theme.choice

Plot theme choice. Specifies the visual style of the plot. Can be one of the following pre-defined themes: - "prism": Utilizes the ggprism::theme_prism() function from the ggprism package, offering a polished and visually appealing style. - "classic": Applies theme_classic() from ggplot2, providing a clean and traditional look with minimal styling. - "gray": Uses theme_gray() from ggplot2, which offers a simple and modern look with a light gray background. - "bw": Employs theme_bw() from ggplot2, creating a classic black and white plot, ideal for formal publications and situations where color is best minimized. - "light": Implements theme_light() from ggplot2, featuring a light theme with subtle grey lines and axes, suitable for a fresh, modern look. - "dark": Uses theme_dark() from ggplot2, offering a dark background, ideal for presentations or situations where a high-contrast theme is desired. - "minimal": Applies theme_minimal() from ggplot2, providing a minimalist theme with the least amount of background annotations and colors. - "void": Employs theme_void() from ggplot2, creating a blank canvas with no axes, gridlines, or background, ideal for custom, creative plots. Each theme option adjusts various elements like background color, grid lines, and font styles to match the specified aesthetic. Default is "bw", offering a universally compatible black and white theme suitable for a wide range of applications.

custom.theme

A custom ggplot theme provided as a ggplot2 theme object. This allows users to override the default theme and provide their own theme for plotting. Custom themes are useful for creating publication-ready figures with specific formatting requirements.

To use a custom theme, create a theme object with ggplot2::theme(), including any desired customizations. Common customizations for publication-ready figures might include adjusting text size for readability, altering line sizes for clarity, and repositioning or formatting the legend. For example:

“`r my_theme <- ggplot2::theme( axis.title = ggplot2::element_text(size=14, face="bold"), # Bold axis titles with larger font axis.text = ggplot2::element_text(size=12), # Slightly larger axis text legend.position = "top", # Move legend to the top legend.background = ggplot2::element_rect(fill="lightgray"), # Light gray background for legend panel.background = ggplot2::element_rect(fill="white", colour="black"), # White panel background with black border panel.grid.major = ggplot2::element_line(colour = "grey90"), # Lighter color for major grid lines panel.grid.minor = ggplot2::element_blank(), # Remove minor grid lines plot.title = ggplot2::element_text(size=16, hjust=0.5) # Centered plot title with larger font ) “`

Then pass `my_theme` to `custom.theme`. If `custom.theme` is NULL (the default), the theme is determined by `theme.choice`. This flexibility allows for both easy theme selection for general use and detailed customization for specific presentation or publication needs.

palette

An optional parameter specifying the color palette to be used for the plot. It can be either a character string specifying the name of a predefined palette or a vector of color codes in a format accepted by ggplot2 (e.g., hexadecimal color codes). Available predefined palettes include 'npg', 'aaas', 'nejm', 'lancet', 'jama', 'jco', and 'ucscgb', inspired by various scientific publications and the `ggsci` package. If `palette` is not provided or an unrecognized palette name is given, a default color palette will be used. Ensure the number of colors in the palette is at least as large as the number of groups being plotted.

pdf

Logical indicating whether to save plots as PDF files (default: TRUE).

file.ann

Annotation text for the PDF file names.

pdf.wid

Width of the PDF plots.

pdf.hei

Height of the PDF plots.

output.file

A character string specifying the output file name for the report. This will also determine the title of the generated report. For example, if you set it to "path_to_your_location/report.pdf", the title of the report will be "report".

...

Additional arguments passed to internal functions.

Value

A report file containing the microbial ecology analysis results.

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,
  subject.var = "subject",
  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"
)
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",
  subject.var = "subject_id",
  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",
  subject.var = "subject.id",
  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"
)
} # }