| Title: | LegATo: Longitudinal mEtaGenomic Analysis Toolkit |
|---|---|
| Description: | LegATo is a suite of open-source software tools for longitudinal microbiome analysis. It is extendable to several different study forms with optimal ease-of-use for researchers. Microbiome time-series data presents distinct challenges including complex covariate dependencies and variety of longitudinal study designs. This toolkit will allow researchers to determine which microbial taxa are affected over time by perturbations such as onset of disease or lifestyle choices, and to predict the effects of these perturbations over time, including changes in composition or stability of commensal bacteria. |
| Authors: | Aubrey Odom [aut, cre] (ORCID: <https://orcid.org/0000-0001-7113-7598>), Yilong Zhang [ctb] (Author of NMIT functions), Jared Pincus [csl] (ORCID: <https://orcid.org/0000-0001-6708-5262>, other: Naming consultant of package), Jordan Pincus [art] (Artist of LegATo icon) |
| Maintainer: | Aubrey Odom <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.7.0 |
| Built: | 2026-10-10 10:47:35 UTC |
| Source: | https://github.com/bioc/LegATo |
This functional is an optional method for fixing up taxon names in a
MultiAssayExperiment to be run before filter_MAE.
Specifically, it removes brackets from species names, replaces species labeled
as "others" with "sp." and finally replaces underscores with spaces.
clean_MAE(dat, which_experiment = NULL, which_assay = NULL)clean_MAE(dat, which_experiment = NULL, which_assay = NULL)
dat |
A |
which_experiment |
Character string. If |
which_assay |
Character string. Regardless of whether
|
An animalcules-formatted MultiAssayExperiment object with
cleaned-up taxonomy nomenclature.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() clean_MAE(in_dat)in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() clean_MAE(in_dat)
This function takes either a counts_dat, tax_dat, and metadata_dat input OR a TreeSummarizedExperiment input and creates a specifically-formatted MAE object that is compatible for use with LegATo and animalcules. Checks are performed on inputs to ensure that they can be integrated properly.
create_formatted_MAE( counts_dat = NULL, tax_dat = NULL, metadata_dat = NULL, tree_SE = NULL )create_formatted_MAE( counts_dat = NULL, tax_dat = NULL, metadata_dat = NULL, tree_SE = NULL )
counts_dat |
A matrix, data.table, or data.frame consisting of microbial
raw counts data. The |
tax_dat |
A matrix, data.table, or data.frame of hierarchical taxonomic
data. Should have columns such as "family", "genus", "species" with each
row uniquely delineating a different taxon. The rows should be in the same
order as the rows of |
metadata_dat |
A metadata table with |
tree_SE |
A TreeSummarizedExperiment object with counts, taxonomy, and metadata. |
A MultiAssayExperiment object.
nsample <- ntaxa <- 3 counts_dat <- data.frame( "X123" = runif(ntaxa, 0, 500), "X456" = runif(ntaxa, 0, 500), "X789" = runif(ntaxa, 0, 500) ) tax_dat <- data.frame( "class" = c("rand1", "rand2", "rand3"), "species" = c("rand4", "rand5", "rand6") ) |> as.data.frame() # Set rownames as lowest unique taxonomic level rownames(tax_dat) <- tax_dat$species rownames(counts_dat) <- tax_dat$species metadata <- data.frame( Sample = c("X123", "X456", "X789"), Group = c("A", "B", "A"), Var = rnorm(nsample) ) rownames(metadata) <- metadata$Sample out_MAE <- create_formatted_MAE(counts_dat, tax_dat, metadata) # TreeSummarizedExperiment tse <- TreeSummarizedExperiment::TreeSummarizedExperiment( assays = list(counts = counts_dat), colData = metadata, rowData = tax_dat ) out_MAE_2 <- create_formatted_MAE(tree_SE = tse) out_MAE_2nsample <- ntaxa <- 3 counts_dat <- data.frame( "X123" = runif(ntaxa, 0, 500), "X456" = runif(ntaxa, 0, 500), "X789" = runif(ntaxa, 0, 500) ) tax_dat <- data.frame( "class" = c("rand1", "rand2", "rand3"), "species" = c("rand4", "rand5", "rand6") ) |> as.data.frame() # Set rownames as lowest unique taxonomic level rownames(tax_dat) <- tax_dat$species rownames(counts_dat) <- tax_dat$species metadata <- data.frame( Sample = c("X123", "X456", "X789"), Group = c("A", "B", "A"), Var = rnorm(nsample) ) rownames(metadata) <- metadata$Sample out_MAE <- create_formatted_MAE(counts_dat, tax_dat, metadata) # TreeSummarizedExperiment tse <- TreeSummarizedExperiment::TreeSummarizedExperiment( assays = list(counts = counts_dat), colData = metadata, rowData = tax_dat ) out_MAE_2 <- create_formatted_MAE(tree_SE = tse) out_MAE_2
Create a distinct palette for coloring different heatmap clusters. The
function returns colors for input into ComplexHeatmap:Heatmap().
The "grDevices" package is required to use this function.
distinctColors( n, hues = c("red", "cyan", "orange", "blue", "yellow", "purple", "green", "magenta"), saturation.range = c(0.7, 1), value.range = c(0.7, 1) )distinctColors( n, hues = c("red", "cyan", "orange", "blue", "yellow", "purple", "green", "magenta"), saturation.range = c(0.7, 1), value.range = c(0.7, 1) )
n |
an integer describing the number of colors to generate. Required. |
hues |
a vector of character strings indicating the R colors available
from the |
saturation.range |
a numeric vector of length 2 with values between 0
and 1 giving the range of saturation. The default is |
value.range |
a numeric vector of length 2 with values between 0 and 1
giving the range of values. The default is |
A vector of distinct colors that have been converted to HEX from HSV.
distinctColors(10)distinctColors(10)
This function takes an animalcules-formatted MultiAssayExperiment
(MAE) object and identifies all taxa at the "genus" level that represent
<filter_prop average relative abundance across all samples in the MAE.
After identification at the genus level, taxa across the genus and species
levels are then consolidated into the category "Other".
filter_animalcules_MAE(dat, filter_prop = 0.001)filter_animalcules_MAE(dat, filter_prop = 0.001)
dat |
A |
filter_prop |
A double strictly between 0 and 1, representing the proportion of relative abundance at which to filter. Default is 0.001. |
An animalcules-formatted MultiAssayExperiment object with
appropriate filtration.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() filter_animalcules_MAE(in_dat, 0.01)in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() filter_animalcules_MAE(in_dat, 0.01)
This function takes an animalcules-formatted MultiAssayExperiment (MAE)
object and identifies all taxa at the OTU level of choice that exhibit a
relative abundance greater than or equal to a relative abundance percent
threshold, relabu_threshold, in at least occur_pct_cutoff% of
the total samples. After filtration, taxa across the specified OTU level and
all downstream levels are then consolidated into the category "Other".
filter_MAE( dat, relabu_threshold = 3, occur_pct_cutoff = 5, taxon_level = "genus" )filter_MAE( dat, relabu_threshold = 3, occur_pct_cutoff = 5, taxon_level = "genus" )
dat |
A |
relabu_threshold |
A double(percentage) between 0 and 100, representing the relative abundance criterion that all OTUs should meet to be retained. The smaller the threshold, the fewer the OTUs will be retained. Default is 3%. |
occur_pct_cutoff |
A double (percentage) between 0 and 100
representing the percent cutoff for how many OTUs must meet the
|
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
An animalcules-formatted MultiAssayExperiment object
with major OTUs retained.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() filter_MAE(in_dat, relabu_threshold = 3, occur_pct_cutoff = 5, taxon_level = "genus")in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() filter_MAE(in_dat, relabu_threshold = 3, occur_pct_cutoff = 5, taxon_level = "genus")
This function takes a MultiAssayExperiment object and a specified
taxon level of interest and creates a long data.frame that can be used
more easily for plotting counts data.
get_long_data(dat, taxon_level, log = FALSE, counts_to_CPM = FALSE)get_long_data(dat, taxon_level, log = FALSE, counts_to_CPM = FALSE)
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
log |
logical. Indicate whether an assay returned should be the log of
whichever assay is specified in |
counts_to_CPM |
logical. This argument only applies if the
|
A data.frame consisting of the counts data, taxa, and
metadata.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_long_data(in_dat, "genus", log = TRUE, counts_to_CPM = TRUE) head(out)in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_long_data(in_dat, "genus", log = TRUE, counts_to_CPM = TRUE) head(out)
This function takes a MultiAssayExperiment object and a specified
taxon level of interest and creates a long data.frame that can be used
more easily for plotting counts data in a stacked bar plot or a stacked area
chart. The function groups taxa and computes relative abundance within taxa strata.
get_stacked_data(dat, taxon_level = "genus", covariate_1, covariate_time)get_stacked_data(dat, taxon_level = "genus", covariate_1, covariate_time)
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
covariate_1 |
Character string, the name of the covariate in 'dat'
by which to color and group samples. Default is |
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
A data.frame consisting of the counts data, taxa, and metadata.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() get_stacked_data(in_dat, "genus", covariate_1 = "Sex", covariate_time = "Month")in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() get_stacked_data(in_dat, "genus", covariate_1 = "Sex", covariate_time = "Month")
This function takes a MultiAssayExperiment of microbial read counts
and aggregates them by one or more grouping vars within a unit.
get_summary_table(dat, group_vars = NULL)get_summary_table(dat, group_vars = NULL)
dat |
A |
group_vars |
A character string or character vector of covariates
found in |
A data.frame of the grouping columns, mean_reads, sd_reads,
min_reads, max_reads and num_total.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_summary_table(in_dat, c("Group", "Subject")) head(out)in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_summary_table(in_dat, c("Group", "Subject")) head(out)
This function takes a MultiAssayExperiment object and returns a
data.frame of the present taxa at a user-supplied taxonomy level,
and outputs the average abundances of the taxa.
get_top_taxa(dat, taxon_level = "genus")get_top_taxa(dat, taxon_level = "genus")
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
A data.frame
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_top_taxa(in_dat, "genus") outin_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- get_top_taxa(in_dat, "genus") out
An R-based implementation of the NMIT, a multivariate distance-based test for
group comparisons of microbial temporal interdependence. The NMIT test
provides a comprehensive way to evaluate the association between key
phenotypic variables and microbial interdependence. This function is
recommended for use after a filtering step using
filter_MAE. Note, the "ComplexHeatmap" package is required to
use the plotting features of the function. The function requires the
"vegan" package.
NMIT( dat, unit_var, fixed_cov, covariate_time, method = "kendall", dist_type = "F", heatmap = TRUE, classify = FALSE, fill_na = 0, ... )NMIT( dat, unit_var, fixed_cov, covariate_time, method = "kendall", dist_type = "F", heatmap = TRUE, classify = FALSE, fill_na = 0, ... )
dat |
A |
unit_var |
a numeric vector of subject. |
fixed_cov |
A character vector of the names of covariates of interest found in
|
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
method |
an option of the correlation method ("pearson", "kendall", "spearman"). The default method is "kendall". |
dist_type |
A character string specifying the type of matrix norm to be
computed. The default is |
heatmap |
A logical value indicating whether to draw heatmap. The
default is |
classify |
A logical value indicating whether to draw a classifier tree.
The default is |
fill_na |
A number between 0 and 1 to fill |
... |
Additional arguments to be passed to |
This function returns an analysis of variance (ANOVA) table showing sources of variation, degrees of freedom, sequential sums of squares, mean squares, F statistics, partial R-squared and P values, based on 999 permutations.
Yilong Zhang, Huilin Li, Aubrey Odom
dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() NMIT(dat, unit_var = "Subject", fixed_cov = "Group", covariate_time = "Month")dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() NMIT(dat, unit_var = "Subject", fixed_cov = "Group", covariate_time = "Month")
This function takes an animalcules-formatted MultiAssayExperiment
object and parses it to extract a named assay alongside the taxonomy and
metadata.
parse_MAE_SE(dat, which_experiment = NULL, which_assay = NULL, type = "MAE")parse_MAE_SE(dat, which_experiment = NULL, which_assay = NULL, type = "MAE")
dat |
Either a |
which_experiment |
Character string. If |
which_assay |
Character string. Regardless of whether
|
type |
One of "MAE" denoting a |
Returns a list of 3 named data.frame elements, 'counts', 'sam', and 'tax' denoting the counts data, sample metadata table, and taxonomy table, respectively.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- parse_MAE_SE(in_dat) head(out$tax) head(out$sam) head(out$counts) out2 <- parse_MAE_SE(in_dat[["MicrobeGenetics"]], which_assay = "MGX", type = "SE")in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- parse_MAE_SE(in_dat) head(out$tax) head(out$sam) head(out$counts) out2 <- parse_MAE_SE(in_dat[["MicrobeGenetics"]], which_assay = "MGX", type = "SE")
This function takes a MultiAssayExperiment object and returns a
alluvial diagram of microbe relative abundances. The function takes a single
covariate as an optional variable by which to create a grid of multiple
plots. Note, the ggalluvial package is required to use this function.
plot_alluvial( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )plot_alluvial( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
covariate_1 |
Character string giving the name of a column in
|
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
palette_input |
A character vector of colors that is at minimum the same
length of the number of taxa (specified with |
title |
A character string providing the plot title. |
subtitle |
A character string providing the plot subtitle. The default
is |
If further manipulation of specific parameters is desired, users can add
ggplot2 function calls to the output of the function.
A ggplot2 plot.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_alluvial(in_dat, taxon_level = "family", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_alluvial(in_dat, taxon_level = "family", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))
This function takes an arbitrary dataset as an input and returns a
ComplexHeatmap plot of samples based on similarity of microbial
abundances. The function takes arguments listed here as well
as any others to be passed on to ComplexHeatmap::Heatmap(). Note, the
"circlize" and "ComplexHeatmap" packages are required to use this function.
plot_heatmap( inputData, annotationData = NULL, plot_title = NULL, name = "Input data", plottingColNames, annotationColNames = NULL, colList = list(), scale = FALSE, showColumnNames = TRUE, showRowNames = TRUE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", annotationplotting = NULL, column_order = NULL, ... )plot_heatmap( inputData, annotationData = NULL, plot_title = NULL, name = "Input data", plottingColNames, annotationColNames = NULL, colList = list(), scale = FALSE, showColumnNames = TRUE, showRowNames = TRUE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", annotationplotting = NULL, column_order = NULL, ... )
inputData |
an input data object. It should either be of the class
|
annotationData |
a |
plot_title |
a character string with the plot title of the heatmap. The
default is |
name |
a character string with the name of the data to be displayed.
Default is |
plottingColNames |
a vector of the column names in |
annotationColNames |
a vector of the column names in |
colList |
a named |
scale |
logical. Setting |
showColumnNames |
logical. Setting |
showRowNames |
logical. Setting |
colorSets |
a vector of names listing the color sets in the order
that they should be used in creating the heatmap. By default, this function
will use the color sets in the order listed in |
choose_color |
a vector of color names to be interpolated for the
heatmap gradient, or a |
split_heatmap |
a character string either giving the column title of
|
annotationplotting |
a |
column_order |
a vector of character strings indicating the order in
which to manually arrange the heatmap columns. Default is |
... |
Additional arguments to be passed to
|
If both annotationData = NULL and annotationColNames = NULL,
no annotation bar will be drawn on the heatmap.
Code was adapted from the TBSignatureprofiler R package.
A ComplexHeatmap plot.
David Jenkins, Aubrey Odom
library(SummarizedExperiment) # Example with a Summarized Experiment data object dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() input_SE <- dat[["MicrobeGenetics"]] ## Creating a continuous color ramp annot col list Hairrange <- range(colData(input_SE)[, "HairLength"]) color2 <- circlize::colorRamp2(c(Hairrange[1], Hairrange[2]), c("blue", "red")) color.list <- list("HairLength" = color2) ## Create plot plot_heatmap( inputData = input_SE, name = "Microbe abundances", plot_title = "Example Heatmap", plottingColNames = colnames(input_SE), annotationColNames = "HairLength", colList = color.list, scale = TRUE, showColumnNames = TRUE, showRowNames = FALSE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", column_order = NULL ) # Artificial data example - matrix input mat_testdata <- rbind(matrix(c(rnorm(80), rnorm(80) + 5), 16, 10, dimnames = list(paste0("Taxon", seq_len(16)), paste0("sample", seq_len(10)))), matrix(rnorm(1000), 100, 10, dimnames = list(paste0("Taxon0", seq_len(100)), paste0("sample", seq_len(10))))) cov_mat <- data.frame(sample = c(rep("down", 5), rep("up", 5))) |> magrittr::set_rownames(paste0("sample", seq_len(10))) # Example using custom colors for the annotation information color2 <- stats::setNames(c("purple", "black"), c("down", "up")) color.list <- list("sample" = color2) plot_heatmap( inputData = mat_testdata, annotationData = cov_mat, name = "Data", plot_title = "Example", plottingColNames = NULL, annotationColNames = NULL, colList = color.list, scale = FALSE, showColumnNames = TRUE, showRowNames = FALSE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", column_order = NULL )library(SummarizedExperiment) # Example with a Summarized Experiment data object dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() input_SE <- dat[["MicrobeGenetics"]] ## Creating a continuous color ramp annot col list Hairrange <- range(colData(input_SE)[, "HairLength"]) color2 <- circlize::colorRamp2(c(Hairrange[1], Hairrange[2]), c("blue", "red")) color.list <- list("HairLength" = color2) ## Create plot plot_heatmap( inputData = input_SE, name = "Microbe abundances", plot_title = "Example Heatmap", plottingColNames = colnames(input_SE), annotationColNames = "HairLength", colList = color.list, scale = TRUE, showColumnNames = TRUE, showRowNames = FALSE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", column_order = NULL ) # Artificial data example - matrix input mat_testdata <- rbind(matrix(c(rnorm(80), rnorm(80) + 5), 16, 10, dimnames = list(paste0("Taxon", seq_len(16)), paste0("sample", seq_len(10)))), matrix(rnorm(1000), 100, 10, dimnames = list(paste0("Taxon0", seq_len(100)), paste0("sample", seq_len(10))))) cov_mat <- data.frame(sample = c(rep("down", 5), rep("up", 5))) |> magrittr::set_rownames(paste0("sample", seq_len(10))) # Example using custom colors for the annotation information color2 <- stats::setNames(c("purple", "black"), c("down", "up")) color.list <- list("sample" = color2) plot_heatmap( inputData = mat_testdata, annotationData = cov_mat, name = "Data", plot_title = "Example", plottingColNames = NULL, annotationColNames = NULL, colList = color.list, scale = FALSE, showColumnNames = TRUE, showRowNames = FALSE, colorSets = c("Set1", "Set2", "Set3", "Pastel1", "Pastel2", "Accent", "Dark2", "Paired"), choose_color = c("blue", "gray95", "red"), split_heatmap = "none", column_order = NULL )
This function takes a MultiAssayExperiment object and returns a
spaghetti plot of microbial abundance delineated by a unit, such as
a subject.
plot_spaghetti( dat, covariate_time, covariate_1 = NULL, unit_var, taxon_level, which_taxon, palette_input = NULL, title = "Spaghetti Plot", subtitle = NULL )plot_spaghetti( dat, covariate_time, covariate_1 = NULL, unit_var, taxon_level, which_taxon, palette_input = NULL, title = "Spaghetti Plot", subtitle = NULL )
dat |
A |
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
covariate_1 |
Character string, the name of the covariate in 'dat'
by which to color and group samples. Default is |
unit_var |
Character string, the name of the column delineating the unit on which the microbial abundances are changing over time. This is likely something akin to a subject that repeated measurements are made on. |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
which_taxon |
Character string, the name of the taxon to plot at the specified taxon level. |
palette_input |
A character vector of colors that is at minimum the same
length of the number of taxa (specified with |
title |
A character string providing the plot title. |
subtitle |
A character string providing the plot subtitle. The default
is |
If further manipulation of specific parameters is desired, users can add
ggplot2 function calls to the output of the function.
A ggplot2 plot.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() all_taxa <- get_top_taxa(in_dat, "phylum") plot_spaghetti(in_dat, taxon_level = "phylum", covariate_1 = "Group", covariate_time = "Month", unit_var = "Subject", which_taxon = all_taxa$taxon[1], palette_input = rainbow(25))in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() all_taxa <- get_top_taxa(in_dat, "phylum") plot_spaghetti(in_dat, taxon_level = "phylum", covariate_1 = "Group", covariate_time = "Month", unit_var = "Subject", which_taxon = all_taxa$taxon[1], palette_input = rainbow(25))
This function takes a MultiAssayExperiment object and returns a
stacked area chart of microbe relative abundances. The function takes a single
covariate as an optional variable by which to create a grid of multiple
plots.
plot_stacked_area( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )plot_stacked_area( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
covariate_1 |
Character string giving the name of a column in
|
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
palette_input |
A character vector of colors that is at minimum the same
length of the number of taxa (specified with |
title |
A character string providing the plot title. |
subtitle |
A character string providing the plot subtitle. The default
is |
If further manipulation of specific parameters is desired, users can add
ggplot2 function calls to the output of the function.
A ggplot2 plot.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_stacked_area(in_dat, taxon_level = "phylum", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_stacked_area(in_dat, taxon_level = "phylum", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))
This function takes a MultiAssayExperiment object and returns a
stacked bar plot of microbe relative abundances. The function takes a single
covariate as an optional variable by which to create multiple gridded plots.
plot_stacked_bar( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )plot_stacked_bar( dat, taxon_level, covariate_1 = NULL, covariate_time, palette_input = NULL, title = paste("Relative abundance at", taxon_level, "level"), subtitle = NULL )
dat |
A |
taxon_level |
Character string indicating the level of taxonomy to
aggregate the counts data. Must be the name of a column in
|
covariate_1 |
Character string giving the name of a column in
|
covariate_time |
Character string giving the name of the discrete time-based covariate in the metadata to group abundances by. |
palette_input |
A character vector of colors that is at minimum the same
length of the number of taxa (specified with |
title |
A character string providing the plot title. |
subtitle |
A character string providing the plot subtitle. The default
is |
If further manipulation of specific parameters is desired, users can add
ggplot2 function calls to the output of the function.
A ggplot2 plot.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_stacked_bar(in_dat, taxon_level = "family", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() plot_stacked_bar(in_dat, taxon_level = "family", covariate_1 = "Group", covariate_time = "Month", palette_input = rainbow(25))
This function takes an animalcules-formatted MultiAssayExperiment and
runs an independent GEE model for each taxon. The model predicts taxon log
CPM abundance as a product of fixed-effects covariates conditional on a
grouping ID variable, usually the unit on which repeated measurements were
taken. This modeling approach works best with small datasets that multiple
samples across many (>40) clusters/units. Note, the "broom", "ggeffects",
"broom.mixed", "geepack", "emmeans" packages are required to use this
function; all can be installed via CRAN.
run_gee_model( dat, taxon_level = "genus", unit_var, fixed_cov, corstr = "ar1", p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )run_gee_model( dat, taxon_level = "genus", unit_var, fixed_cov, corstr = "ar1", p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )
dat |
A MultiAssayExperiment object specially formatted as an animalcules output. |
taxon_level |
Character string, default is |
unit_var |
A character string identifying the unit variable for which there are multiple observations. Required. |
fixed_cov |
A character vector naming covariates to be tested. |
corstr |
A character string specifying the correlation structure. The following are permitted: '"independence"', '"exchangeable"', '"ar1"', '"unstructured"'. |
p_adj_method |
A character string specifying the correction method. Can
be abbreviated. See details. Default is |
plot_out |
Logical indicating whether plots should be output alongside
the model results. Default is |
plotsave_loc |
A character string giving the folder path to save plot outputs. This defaults to the current working directory. |
plot_terms |
Character vector. Which terms should be examined in the
plot output? Can overlap with the |
... |
Further arguments passed to |
P-values are adjusted for the model coefficients within each taxon. The
following methods are permitted: c("holm", "hochberg", "hommel",
"bonferroni", "BH", "BY", "fdr", "none")
A data.frame of modeling results.
in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- run_gee_model(in_dat, taxon_level = "genus", unit_var = "Subject", fixed_cov = c("HairLength", "Age", "Group", "Sex"), corstr = "ar1") head(out)in_dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() out <- run_gee_model(in_dat, taxon_level = "genus", unit_var = "Subject", fixed_cov = c("HairLength", "Age", "Group", "Sex"), corstr = "ar1") head(out)
This function takes an animalcules-formatted MultiAssayExperiment and
runs an independent linear model for each taxon. The model predicts taxon log
CPM abundance as a product of user-specified covariates. This model can
be used for general microbiome analyses without repeated measures data.
Note, the "broom", and
"broom.mixed" packages are required to use the testing functionality of this
package; both can be installed via CRAN.
run_lm_model( dat, taxon_level = "genus", fixed_cov, p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )run_lm_model( dat, taxon_level = "genus", fixed_cov, p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )
dat |
A MultiAssayExperiment object specially formatted as an animalcules output. |
taxon_level |
Character string, default is |
fixed_cov |
A character vector naming covariates to be tested. |
p_adj_method |
A character string specifying the correction method. Can
be abbreviated. See details. Default is |
plot_out |
Logical indicating whether plots should be output alongside
the model results. Default is |
plotsave_loc |
A character string giving the folder path to save plot outputs. This defaults to the current working directory. |
plot_terms |
Character vector. Which terms should be examined in the
plot output? Can overlap with the |
... |
Further arguments passed to |
P-values are adjusted for the model coefficients within each taxon. The
following methods are permitted: c("holm", "hochberg", "hommel",
"bonferroni", "BH", "BY", "fdr", "none")
A data.frame of modeling results.
dat <- system.file("extdata/MAE.RDS", package = "LegATo") |> readRDS() |> filter_MAE() out <- run_lm_model(dat, fixed_cov = c("timepoint", "HIVStatus"), plot_out = FALSE) head(out)dat <- system.file("extdata/MAE.RDS", package = "LegATo") |> readRDS() |> filter_MAE() out <- run_lm_model(dat, fixed_cov = c("timepoint", "HIVStatus"), plot_out = FALSE) head(out)
This function takes an animalcules-formatted MultiAssayExperiment and
runs an independent LMM model for each taxon. The model predicts taxon log
CPM abundance as a product of fixed-effects covariates with a random effect,
usually the unit on which repeated measurements were taken. Note, the 'broom',
'lmerTest', and 'broom.mixed' packages are required to use this function; they can
be downloaded from CRAN.
run_lmm_model( dat, taxon_level = "genus", unit_var, fixed_cov, p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )run_lmm_model( dat, taxon_level = "genus", unit_var, fixed_cov, p_adj_method = "fdr", plot_out = FALSE, plotsave_loc = ".", plot_terms = NULL, ... )
dat |
A MultiAssayExperiment object specially formatted as an animalcules output. |
taxon_level |
Character string, default is |
unit_var |
A character string identifying the unit variable for which there are multiple observations. Required. |
fixed_cov |
A character vector naming covariates to be tested. |
p_adj_method |
A character string specifying the correction method. Can
be abbreviated. See details. Default is |
plot_out |
Logical indicating whether plots should be output alongside
the model results. Default is |
plotsave_loc |
A character string giving the folder path to save plot outputs. This defaults to the current working directory. |
plot_terms |
Character vector. Which terms should be examined in the
plot output? Can overlap with the |
... |
Further arguments passed to |
P-values are adjusted for the model coefficients within each taxon. The
following methods are permitted: c("holm", "hochberg", "hommel",
"bonferroni", "BH", "BY", "fdr", "none")
A data.frame of modeling results.
dat <- system.file("extdata/MAE.RDS", package = "LegATo") |> readRDS() |> filter_MAE() out <- run_lmm_model(dat, taxon_level = "genus", unit_var = "Subject", fixed_cov = c("HIVStatus", "timepoint")) head(out)dat <- system.file("extdata/MAE.RDS", package = "LegATo") |> readRDS() |> filter_MAE() out <- run_lmm_model(dat, taxon_level = "genus", unit_var = "Subject", fixed_cov = c("HIVStatus", "timepoint")) head(out)
This function takes an animalcules-formatted MultiAssayExperiment
object and runs a multivariate Hotelling's T-squared test. The test expects
a comparison of two distinct groups, and compares the abundances of the top microbes at a
given taxon level between the groups. This function allows both paired and unpaired
tests. Both test the null hypothesis that the population
mean vectors are equal, with the alternative being that they are unequal.
test_hotelling_t2( dat, test_index = NULL, taxon_level = "genus", num_taxa, grouping_var, paired = FALSE, pairing_var = NULL, unit_var = NULL, save_table_loc = "." )test_hotelling_t2( dat, test_index = NULL, taxon_level = "genus", num_taxa, grouping_var, paired = FALSE, pairing_var = NULL, unit_var = NULL, save_table_loc = "." )
dat |
A MultiAssayExperiment object specially formatted as an animalcules output. |
test_index |
Any argument used for subsetting the input |
taxon_level |
Character string, default is |
num_taxa |
The number of most abundant taxa to test. If unpaired, this should be no larger than the total number of subjects in both groups - 2, or (n1 + n2 -2). If paired, this should be no larger than the total number of pairs - 1, or n - 1. Required. |
grouping_var |
Character string, the name of a DICHOTOMOUS grouping variable in the
metadata of |
paired |
Logical indicating whether a paired test should be conducted.
Default is |
pairing_var |
Character string giving the variable containing pairing information.
The variable should be in integer form. Must be supplied if |
unit_var |
Character string giving the variable containing the identifiers
for the unit on which multiple measurements were conducted, e.g. subjects. Default is
|
save_table_loc |
A character string giving the folder path to save t.test results. Note that these are only conducted if the Hotelling's T-test value is <0.05. Defaults to the current working directory. |
The Hotelling's t-squared statistic (t2) is a generalization of Student's t-statistic that is used in multivariate hypothesis testing to test the means of different populations.
Note that any entries or pairs with missing values are excluded.
Referenced articles in the implementation of tests:
https://online.stat.psu.edu/stat505/lesson/7/7.1/7.1.14
https://online.stat.psu.edu/stat505/lesson/7/7.1/7.1.15
https://online.stat.psu.edu/stat505/lesson/7/7.1/7.1.4
https://online.stat.psu.edu/stat505/lesson/7/7.1/7.1.9
A list of the elements "df1", "df2", "crit_F", "F_stat" and "pvalue" giving the results of the test.
dat <- system.file("extdata", "MAE.RDS", package = "LegATo") |> readRDS() dat_0.05 <- filter_MAE(dat, 0.001, 10, "species") out1 <- test_hotelling_t2(dat = dat_0.05, test_index = which(dat_0.05$MothChild == "Infant" & dat_0.05$timepoint == 0), taxon_level = "genus", # Total number of pairs - 1 num_taxa = 9, paired = TRUE, grouping_var = "HIVStatus", pairing_var = "pairing") out1 out <- test_hotelling_t2(dat = dat_0.05, test_index = which(dat_0.05$MothChild == "Mother" & dat_0.05$timepoint == 6), taxon_level = "genus", # Max is Total number of subjects - 2 # Here we use a much smaller number num_taxa = 6, grouping_var = "HIVStatus", unit_var = "Subject", paired = FALSE) outdat <- system.file("extdata", "MAE.RDS", package = "LegATo") |> readRDS() dat_0.05 <- filter_MAE(dat, 0.001, 10, "species") out1 <- test_hotelling_t2(dat = dat_0.05, test_index = which(dat_0.05$MothChild == "Infant" & dat_0.05$timepoint == 0), taxon_level = "genus", # Total number of pairs - 1 num_taxa = 9, paired = TRUE, grouping_var = "HIVStatus", pairing_var = "pairing") out1 out <- test_hotelling_t2(dat = dat_0.05, test_index = which(dat_0.05$MothChild == "Mother" & dat_0.05$timepoint == 6), taxon_level = "genus", # Max is Total number of subjects - 2 # Here we use a much smaller number num_taxa = 6, grouping_var = "HIVStatus", unit_var = "Subject", paired = FALSE) out
This function takes a MultiAssayExperiment and outputs an array of
temporal intra-subject correlation matrices.
tscor(dat, unit_var, method = "kendall", fill_na = 0)tscor(dat, unit_var, method = "kendall", fill_na = 0)
dat |
A |
unit_var |
a numeric vector of subject. |
method |
an option of the correlation method ("pearson", "kendall", "spearman"). The default method is "kendall". |
fill_na |
a number between 0 and 1 to fill the missing value. The default value is 0. |
An three-dimensional array of temporal correlation matrices for each subject.
Yilong Zhang, Huilin Li, Aubrey Odom
dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() output <- tscor(dat, unit_var = "Subject", method = "spearman") head(output)dat <- system.file("extdata/MAE_small.RDS", package = "LegATo") |> readRDS() output <- tscor(dat, unit_var = "Subject", method = "spearman") head(output)