From 23c0b9fb9edf46467cf4b8d56697984a2aac5efd Mon Sep 17 00:00:00 2001 From: Caffery Yang Date: Fri, 13 Oct 2023 21:11:49 +0800 Subject: [PATCH] Improved Function Compatibility and Dependency Updates - Enhanced compatibility of the `report` function for cases when `alpha.name = NULL` and `dist.name = NULL`. - Reduced package dependencies. Removed dependency on packages like `broom`. - Updated package dependencies as follows: **Depends:** - R (>= 3.5.0) - rlang - tibble **Imports:** - ggplot2 - matrixStats - lmerTest - foreach - modeest - vegan - dplyr - pheatmap - tidyr - ggh4x - ape - GUniFrac - scales - stringr - rmarkdown - knitr - pander - tinytex **Suggests:** - ggrepel - parallel - ggprism - aplot - philentropy - forcats - yaml - biomformat - Biostrings --- DESCRIPTION | 11 ++-- NAMESPACE | 1 - R/generate_alpha_boxplot_long.R | 5 ++ R/generate_alpha_boxplot_single.R | 5 ++ R/generate_alpha_change_boxplot_pair.R | 5 ++ R/generate_alpha_change_test_pair.R | 63 ++++++++++---------- R/generate_alpha_spaghettiplot_long.R | 4 ++ R/generate_alpha_test_pair.R | 22 +++++-- R/generate_alpha_test_single.R | 29 +++++++-- R/generate_alpha_trend_test_long.R | 4 ++ R/generate_alpha_volatility_test_long.R | 16 ++++- R/generate_beta_change_boxplot_pair.R | 4 ++ R/generate_beta_change_spaghettiplot_long.R | 5 ++ R/generate_beta_change_test_pair.R | 27 +++++++-- R/generate_beta_ordination_long.R | 4 ++ R/generate_beta_ordination_pair.R | 5 ++ R/generate_beta_ordination_single.R | 5 ++ R/generate_beta_pc_boxplot_long.R | 5 ++ R/generate_beta_pc_change_boxplot_pair.R | 4 ++ R/generate_beta_pc_spaghettiplot_long.R | 5 ++ R/generate_beta_pc_trend_test_long.R | 5 ++ R/generate_beta_pc_volatility_test_long.R | 15 ++++- R/generate_beta_test_pair.R | 4 ++ R/generate_beta_test_single.R | 4 ++ R/generate_beta_trend_test_long.R | 4 ++ R/generate_beta_volatility_test_long.R | 15 ++++- R/generate_taxa_barplot_single.R | 5 ++ R/generate_taxa_change_test_pair.R | 15 +++-- R/generate_taxa_volatility_test_long.R | 16 +++-- R/linda.R | 5 +- R/mStat_calculate_PC.R | 4 ++ R/mStat_calculate_adjusted_distance.R | 5 ++ R/mStat_calculate_alpha_diversity.R | 4 ++ R/mStat_calculate_beta_diversity.R | 8 +++ R/mStat_generate_report_long.R | 35 ++++++++++- R/mStat_generate_report_pair.R | 2 +- R/mStat_generate_report_single.R | 37 ++++++++++-- R/mStat_import_qiime2_as_data_obj.R | 3 + R/mStat_normalize_data.R | 20 +++++-- R/mStat_rarefy_data.R | 6 +- man/generate_alpha_change_test_pair.Rd | 8 +-- man/generate_alpha_test_pair.Rd | 2 +- man/generate_alpha_volatility_test_long.Rd | 2 +- man/generate_beta_change_test_pair.Rd | 2 +- man/generate_beta_ordination_single.Rd | 1 + man/generate_beta_pc_volatility_test_long.Rd | 2 +- man/generate_beta_volatility_test_long.Rd | 2 + man/generate_taxa_change_test_pair.Rd | 6 +- man/generate_taxa_volatility_test_long.Rd | 4 +- man/linda.Rd | 1 + man/linda.plot.Rd | 1 + man/mStat_generate_report_single.Rd | 1 + man/mStat_import_mothur_as_data_obj.Rd | 1 + man/mStat_import_qiime2_as_data_obj.Rd | 3 + 54 files changed, 368 insertions(+), 109 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 389aeed..9fd4cc6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,8 +23,6 @@ Depends: Imports: ggplot2, matrixStats, - parallel, - ggrepel, lmerTest, foreach, modeest, @@ -37,16 +35,17 @@ Imports: GUniFrac, scales, stringr, - broom -Suggests: rmarkdown, knitr, + pander, + tinytex +Suggests: + ggrepel, + parallel, ggprism, aplot, philentropy, forcats, - pander, - tinytex, yaml, biomformat, Biostrings diff --git a/NAMESPACE b/NAMESPACE index a64dd43..2d1419a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -97,7 +97,6 @@ export(mStat_update_sample_name) export(mStat_validate_data) import(foreach) import(ggplot2) -import(ggrepel) import(parallel) import(rlang) import(tibble) diff --git a/R/generate_alpha_boxplot_long.R b/R/generate_alpha_boxplot_long.R index df753b9..0bbb999 100644 --- a/R/generate_alpha_boxplot_long.R +++ b/R/generate_alpha_boxplot_long.R @@ -102,6 +102,11 @@ generate_alpha_boxplot_long <- function (data.obj, pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(alpha.name)){ + return() + } + if (!is.null(alpha.obj) && !is(alpha.obj, "list")) stop("`alpha.obj` should be a list or NULL.") diff --git a/R/generate_alpha_boxplot_single.R b/R/generate_alpha_boxplot_single.R index 3c38af0..89901f6 100644 --- a/R/generate_alpha_boxplot_single.R +++ b/R/generate_alpha_boxplot_single.R @@ -160,6 +160,11 @@ generate_alpha_boxplot_single <- function (data.obj, pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( diff --git a/R/generate_alpha_change_boxplot_pair.R b/R/generate_alpha_change_boxplot_pair.R index 500679d..2010ddf 100644 --- a/R/generate_alpha_change_boxplot_pair.R +++ b/R/generate_alpha_change_boxplot_pair.R @@ -112,6 +112,11 @@ generate_alpha_change_boxplot_pair <- pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( diff --git a/R/generate_alpha_change_test_pair.R b/R/generate_alpha_change_test_pair.R index 43cba72..b2131fb 100644 --- a/R/generate_alpha_change_test_pair.R +++ b/R/generate_alpha_change_test_pair.R @@ -84,10 +84,10 @@ #' time.var = "time", #' alpha.name = c("shannon"), #' subject.var = "subject", -#' group.var = "group", -#' adj.vars = "sex", -#' change.base = "1", -#' alpha.change.func = "absolute change" +#' group.var = "sex", +#' adj.vars = "group", +#' change.base = "2", +#' alpha.change.func = "log fold change" #' ) #' } #' @export @@ -103,6 +103,10 @@ generate_alpha_change_test_pair <- change.base, alpha.change.func = "log fold change") { + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( @@ -201,40 +205,37 @@ generate_alpha_change_test_pair <- # Run lm and create a coefficient table lm.model <- lm(formula, data = combined_alpha) - coef.tab <- broom::tidy(summary(lm.model)) - - # Rearrange the table - coef.tab <- - coef.tab %>% dplyr::select( - Term = term, - Estimate = estimate, - Std.Error = std.error, - Statistic = statistic, - P.Value = p.value - ) + summary <- summary(lm.model) + coef.tab <- summary$coefficients %>% + as.data.frame() %>% + tibble::rownames_to_column(var = "term") %>% + rename( + term = "Term", + `Std. Error` = "Std.Error", + `t value` = "Statistic", + `Pr(>|t|)` = "P.Value" + ) %>% as_tibble() # Run ANOVA on the model if group.var is multi-categorical if (length(unique(combined_alpha[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(lm.model)) - - # Rearrange the table and add missing columns - anova.tab <- anova.tab %>% - dplyr::select( - Term = term, - Statistic = statistic, - df = df, - P.Value = p.value - ) %>% - dplyr::mutate(Estimate = NA, Std.Error = NA) + anova <- anova(lm.model) + anova.tab <- as.data.frame(anova) %>% + rownames_to_column("Term") %>% + rename(`Sum Sq` = "sumsq", + `Df` = "df", + `F value` = "Statistic", + `Pr(>F)` = "P.Value") %>% + dplyr::mutate(Estimate = NA, Std.Error = NA) %>% + as_tibble() # Reorder the columns to match coef.tab anova.tab <- anova.tab %>% dplyr::select( - Term = term, - Estimate = Estimate, - Std.Error = Std.Error, - Statistic = Statistic, - P.Value = P.Value + Term, + Estimate, + Std.Error, + Statistic, + P.Value ) coef.tab <- diff --git a/R/generate_alpha_spaghettiplot_long.R b/R/generate_alpha_spaghettiplot_long.R index 7b5cdee..d2c7757 100644 --- a/R/generate_alpha_spaghettiplot_long.R +++ b/R/generate_alpha_spaghettiplot_long.R @@ -91,6 +91,10 @@ generate_alpha_spaghettiplot_long <- pdf.wid = 11, pdf.hei = 8.5, ...) { + if (is.null(alpha.name)){ + return() + } + # Data validation if (!is(data.obj, "list")) stop("`data.obj` should be a list.") diff --git a/R/generate_alpha_test_pair.R b/R/generate_alpha_test_pair.R index 26792d4..cdc253b 100644 --- a/R/generate_alpha_test_pair.R +++ b/R/generate_alpha_test_pair.R @@ -87,7 +87,7 @@ extract_coef <- function(model) { #' alpha.name = c("shannon"), #' subject.var = "subject", #' group.var = "group", -#' adj.vars = "sex" +#' adj.vars = NULL #' ) #' #' @export @@ -100,6 +100,11 @@ generate_alpha_test_pair <- subject.var, group.var, adj.vars) { + + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( @@ -187,7 +192,12 @@ generate_alpha_test_pair <- if(!is.null(group.var)){ # Run ANOVA on the model if group.var is multi-categorical if (group.levels > 2) { - anova.tab <- broom::tidy(anova(lme.model)) + anova.tab <- anova(lme.model) %>% + as.data.frame() %>% + rownames_to_column("Term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% @@ -196,13 +206,13 @@ generate_alpha_test_pair <- # Reorder the columns to match coef.tab anova.tab <- anova.tab %>% dplyr::select( - Term = term, - Estimate = Estimate, - Std.Error = Std.Error, + Term, + Estimate, + Std.Error, Statistic = statistic, P.Value = p.value ) %>% - dplyr::filter(Term %in% c(group.var, paste0(time.var, ":", group.var))) + dplyr::filter(Term %in% c(group.var, paste0(group.var, ":", time.var))) coef.tab <- rbind(coef.tab, anova.tab) # Append the anova.tab to the coef.tab diff --git a/R/generate_alpha_test_single.R b/R/generate_alpha_test_single.R index 3781cf7..a0572d4 100644 --- a/R/generate_alpha_test_single.R +++ b/R/generate_alpha_test_single.R @@ -50,6 +50,11 @@ generate_alpha_test_single <- t.level = NULL, group.var, adj.vars) { + + if (is.null(alpha.name)){ + return() + } + if (!is.null(time.var) & !is.null(t.level)) { condition <- paste(time.var, "== '", t.level, "'", sep = "") data.obj <- mStat_subset_data(data.obj, condition = condition) @@ -85,7 +90,17 @@ generate_alpha_test_single <- # Run lm and create a coefficient table lm.model <- lm(formula, data = merged_df) - coef.tab <- broom::tidy(summary(lm.model)) + summary <- summary(lm.model) + coef.tab <- summary$coefficients %>% + as.data.frame() %>% + rownames_to_column("term") %>% + rename( + Estimate = "estimate", + `Std. Error` = "std.error", + `t value` = "statistic", + `Pr(>|t|)` = "p.value" + ) %>% + as_tibble() # Rearrange the table coef.tab <- @@ -99,14 +114,18 @@ generate_alpha_test_single <- # Run ANOVA on the model if group.var is multi-categorical if (length(na.omit(unique(merged_df[[group.var]]))) > 2) { - anova.tab <- broom::tidy(anova(lm.model)) + anova <- anova(lm.model) + anova.tab <- anova %>% + as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") # Rearrange the table and add missing columns anova.tab <- anova.tab %>% dplyr::select( - term = term, + term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) @@ -125,7 +144,7 @@ generate_alpha_test_single <- ) coef.tab <- - rbind(coef.tab, anova.tab) # Append the anova.tab to the coef.tab + rbind(coef.tab, anova.tab) } return(coef.tab) diff --git a/R/generate_alpha_trend_test_long.R b/R/generate_alpha_trend_test_long.R index 9a7321b..452ef22 100644 --- a/R/generate_alpha_trend_test_long.R +++ b/R/generate_alpha_trend_test_long.R @@ -76,6 +76,10 @@ generate_alpha_trend_test_long <- function(data.obj, group.var = NULL, adj.vars = NULL) { + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( diff --git a/R/generate_alpha_volatility_test_long.R b/R/generate_alpha_volatility_test_long.R index 7ef6a3b..4a1ea01 100644 --- a/R/generate_alpha_volatility_test_long.R +++ b/R/generate_alpha_volatility_test_long.R @@ -41,7 +41,7 @@ #' time.var = "visit_number_num", #' subject.var = "subject_id", #' group.var = "subject_race", -#' adj.vars = "sample_body_site" +#' adj.vars = NULL #' ) #' } #' @export @@ -53,6 +53,11 @@ generate_alpha_volatility_test_long <- function(data.obj, subject.var, group.var, adj.vars = NULL) { + + if (is.null(alpha.name)){ + return() + } + if (is.null(alpha.obj)) { if (!is_rarefied(data.obj)) { message( @@ -162,14 +167,19 @@ generate_alpha_volatility_test_long <- function(data.obj, # Run ANOVA on the model if group.var is multi-categorical if (length(unique(alpha_df[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(test_result)) + anova <- anova(test_result) + anova.tab <- anova %>% + as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% dplyr::select( term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) diff --git a/R/generate_beta_change_boxplot_pair.R b/R/generate_beta_change_boxplot_pair.R index 334f544..8958e5a 100644 --- a/R/generate_beta_change_boxplot_pair.R +++ b/R/generate_beta_change_boxplot_pair.R @@ -107,6 +107,10 @@ generate_beta_change_boxplot_pair <- pdf.hei = 8.5, ...) { + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { meta_tab <- data.obj$meta.dat %>% dplyr::select(all_of(c(subject.var, time.var, group.var, strata.var, adj.vars))) dist.obj <- diff --git a/R/generate_beta_change_spaghettiplot_long.R b/R/generate_beta_change_spaghettiplot_long.R index 87235c0..3257299 100644 --- a/R/generate_beta_change_spaghettiplot_long.R +++ b/R/generate_beta_change_spaghettiplot_long.R @@ -94,6 +94,11 @@ generate_beta_change_spaghettiplot_long <- ...) { # Data validation mStat_validate_data(data.obj) + + if (is.null(dist.name)){ + return() + } + if (!is.character(subject.var)) stop("`subject.var` should be a character string.") if (!is.character(time.var)) diff --git a/R/generate_beta_change_test_pair.R b/R/generate_beta_change_test_pair.R index cee59a0..8640023 100644 --- a/R/generate_beta_change_test_pair.R +++ b/R/generate_beta_change_test_pair.R @@ -48,7 +48,7 @@ #' time.var = "time", #' subject.var = "subject", #' group.var = "group", -#' adj.vars = c("sex"), +#' adj.vars = "sex", #' change.base = "1", #' dist.name = c('BC', 'Jaccard') #' ) @@ -77,6 +77,10 @@ generate_beta_change_test_pair <- change.base = NULL, dist.name = c('BC', 'Jaccard', 'UniFrac', 'GUniFrac', 'WUniFrac', 'JS')) { + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)&!is.null(data.obj)) { dist.obj <- mStat_calculate_beta_diversity(data.obj = data.obj, dist.name = dist.name) @@ -124,7 +128,14 @@ generate_beta_change_test_pair <- # Run lm and create a coefficient table lm.model <- lm(formula, data = long.df) - coef.tab <- broom::tidy(summary(lm.model)) + summary <- summary(lm.model) + coef.tab <- summary$coefficients %>% as.data.frame() %>% + rownames_to_column("term") %>% + rename(Estimate = "estimate", + `Std. Error` = "std.error", + `t value` = "statistic", + `Pr(>|t|)` = "p.value") %>% + as_tibble() # Rearrange the table coef.tab <- @@ -137,15 +148,19 @@ generate_beta_change_test_pair <- ) # Run ANOVA on the model if group.var is multi-categorical - if (length(unique(metadata[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(lm.model)) + if (length(unique(metadata[[group.var]])) > 1) { + anova <- anova(lm.model) + anova.tab <- anova %>% as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% dplyr::select( Term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) @@ -153,7 +168,7 @@ generate_beta_change_test_pair <- # Reorder the columns to match coef.tab anova.tab <- anova.tab %>% dplyr::select( - Term = term, + Term, Estimate = Estimate, Std.Error = Std.Error, Statistic = Statistic, diff --git a/R/generate_beta_ordination_long.R b/R/generate_beta_ordination_long.R index f64b1e7..6904502 100644 --- a/R/generate_beta_ordination_long.R +++ b/R/generate_beta_ordination_long.R @@ -143,6 +143,10 @@ generate_beta_ordination_long <- pdf.hei = 8.5, ...) { + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { data.obj <- mStat_process_time_variable(data.obj, time.var, t0.level, ts.levels) diff --git a/R/generate_beta_ordination_pair.R b/R/generate_beta_ordination_pair.R index 75abefc..ba02b14 100644 --- a/R/generate_beta_ordination_pair.R +++ b/R/generate_beta_ordination_pair.R @@ -104,6 +104,11 @@ generate_beta_ordination_pair <- pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { dist.obj <- mStat_calculate_beta_diversity(data.obj = data.obj, dist.name = dist.name) diff --git a/R/generate_beta_ordination_single.R b/R/generate_beta_ordination_single.R index d7cbe48..a4bb5c5 100644 --- a/R/generate_beta_ordination_single.R +++ b/R/generate_beta_ordination_single.R @@ -62,6 +62,7 @@ #' #' @examples #' \dontrun{ +#' library(aplot) #' data(peerj32.obj) #' dist.obj <- mStat_calculate_beta_diversity(peerj32.obj, dist.name = c('BC', 'Jaccard')) #' pc.obj <- mStat_calculate_PC(dist.obj, method = c('mds'), k = 2, dist.name = c('BC','Jaccard')) @@ -132,6 +133,10 @@ generate_beta_ordination_single <- pdf.hei = 8.5, ...) { + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { if (!is.null(time.var)){ if (!is.null(t.level)){ diff --git a/R/generate_beta_pc_boxplot_long.R b/R/generate_beta_pc_boxplot_long.R index 23e5e41..a9ff14c 100644 --- a/R/generate_beta_pc_boxplot_long.R +++ b/R/generate_beta_pc_boxplot_long.R @@ -127,6 +127,11 @@ generate_beta_pc_boxplot_long <- function(data.obj = NULL, pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { data.obj <- mStat_process_time_variable(data.obj, time.var, t0.level, ts.levels) diff --git a/R/generate_beta_pc_change_boxplot_pair.R b/R/generate_beta_pc_change_boxplot_pair.R index 00d7f88..7cf10db 100644 --- a/R/generate_beta_pc_change_boxplot_pair.R +++ b/R/generate_beta_pc_change_boxplot_pair.R @@ -142,6 +142,10 @@ generate_beta_pc_change_boxplot_pair <- pdf.hei = 8.5, ...) { + if (is.null(dist.name)){ + return() + } + if (is.null(data.obj) & is.null(dist.obj)) { stop("Both data.obj and dist.obj cannot be NULL. Please provide at least one.") } diff --git a/R/generate_beta_pc_spaghettiplot_long.R b/R/generate_beta_pc_spaghettiplot_long.R index 3945bc7..06b4365 100644 --- a/R/generate_beta_pc_spaghettiplot_long.R +++ b/R/generate_beta_pc_spaghettiplot_long.R @@ -131,6 +131,11 @@ generate_beta_pc_spaghettiplot_long <- function(data.obj = NULL, pdf.wid = 11, pdf.hei = 8.5, ...) { + + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { data.obj <- mStat_process_time_variable(data.obj, time.var, t0.level, ts.levels) diff --git a/R/generate_beta_pc_trend_test_long.R b/R/generate_beta_pc_trend_test_long.R index b839791..e52b823 100644 --- a/R/generate_beta_pc_trend_test_long.R +++ b/R/generate_beta_pc_trend_test_long.R @@ -106,6 +106,11 @@ generate_beta_pc_trend_test_long <- function(data.obj = NULL, adj.vars = NULL, dist.name = c("BC"), ...) { + + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { meta_tab <- data.obj$meta.dat %>% select(all_of(c( diff --git a/R/generate_beta_pc_volatility_test_long.R b/R/generate_beta_pc_volatility_test_long.R index be0fbf8..d76b285 100644 --- a/R/generate_beta_pc_volatility_test_long.R +++ b/R/generate_beta_pc_volatility_test_long.R @@ -49,7 +49,7 @@ #' subject.var = "studyid", #' time.var = "month", #' group.var = "diet", -#' adj.vars = "delivery", +#' adj.vars = NULL, #' dist.name = c('BC') #' ) #' } @@ -64,6 +64,11 @@ generate_beta_pc_volatility_test_long <- function(data.obj, adj.vars = NULL, dist.name = c("BC"), ...) { + + if (is.null(dist.name)){ + return() + } + if (is.null(dist.obj)) { meta_tab <- data.obj$meta.dat %>% select(all_of(c( @@ -167,14 +172,18 @@ generate_beta_pc_volatility_test_long <- function(data.obj, # Run ANOVA on the model if group.var is multi-categorical if (length(unique(test_df[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(test_result)) + anova <- anova(test_result) + anova.tab <- anova %>% as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% select( term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) diff --git a/R/generate_beta_test_pair.R b/R/generate_beta_test_pair.R index 28161d1..19d5c65 100644 --- a/R/generate_beta_test_pair.R +++ b/R/generate_beta_test_pair.R @@ -48,6 +48,10 @@ generate_beta_test_pair <- function(data.obj, adj.vars = NULL, dist.name = c('BC', 'Jaccard', 'UniFrac', 'GUniFrac', 'WUniFrac', 'JS')) { + if (is.null(dist.name)){ + return() + } + # Calculate beta diversity indices if not provided if (is.null(dist.obj)) { dist.obj <- mStat_calculate_beta_diversity(data.obj, dist.name) diff --git a/R/generate_beta_test_single.R b/R/generate_beta_test_single.R index 776fbf3..e51eb89 100644 --- a/R/generate_beta_test_single.R +++ b/R/generate_beta_test_single.R @@ -54,6 +54,10 @@ generate_beta_test_single <- function(data.obj, adj.vars = NULL, dist.name = c('BC', 'Jaccard', 'UniFrac', 'GUniFrac', 'WUniFrac', 'JS')) { + if (is.null(dist.name)){ + return() + } + # Calculate beta diversity indices if not provided if (is.null(dist.obj)) { if (!is.null(time.var) & !is.null(t.level)) { diff --git a/R/generate_beta_trend_test_long.R b/R/generate_beta_trend_test_long.R index a93db8c..bc53132 100644 --- a/R/generate_beta_trend_test_long.R +++ b/R/generate_beta_trend_test_long.R @@ -92,6 +92,10 @@ generate_beta_trend_test_long <- dist.name = c("BC"), ...) { + if (is.null(dist.name)){ + return() + } + mStat_validate_data(data.obj) message( diff --git a/R/generate_beta_volatility_test_long.R b/R/generate_beta_volatility_test_long.R index 847cbd1..af0db74 100644 --- a/R/generate_beta_volatility_test_long.R +++ b/R/generate_beta_volatility_test_long.R @@ -36,6 +36,7 @@ #' mStat_calculate_beta_diversity, mStat_calculate_adjusted_distance #' #' @examples +#' \dontrun{ #' data(ecam.obj) #' generate_beta_volatility_test_long( #' data.obj = ecam.obj, @@ -61,6 +62,7 @@ #' adj.vars = NULL, #' dist.name = c("BC", "Jaccard") #' ) +#' } #' @export generate_beta_volatility_test_long <- function(data.obj, @@ -72,6 +74,10 @@ generate_beta_volatility_test_long <- dist.name = c("BC"), ...) { + if (is.null(dist.name)){ + return() + } + mStat_validate_data(data.obj) message( @@ -159,15 +165,18 @@ generate_beta_volatility_test_long <- coef.tab <- extract_coef(test_result) # Run ANOVA on the model if group.var is multi-categorical - if (length(unique(test_df[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(test_result)) + if (length(unique(test_df[[group.var]])) > 1) { + anova <- anova(test_result) + anova.tab <- anova %>% as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") # Rearrange the table and add missing columns anova.tab <- anova.tab %>% select( term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) diff --git a/R/generate_taxa_barplot_single.R b/R/generate_taxa_barplot_single.R index eb0ac5a..a915ef1 100644 --- a/R/generate_taxa_barplot_single.R +++ b/R/generate_taxa_barplot_single.R @@ -122,6 +122,9 @@ generate_taxa_barplot_single <- feature.dat.type <- match.arg(feature.dat.type) + pander::add.blank.lines(NULL) + tinytex::check_installed(NULL) + # Extract data mStat_validate_data(data.obj) @@ -191,6 +194,8 @@ generate_taxa_barplot_single <- "Your data is in raw format ('Raw'). Normalization is crucial for further analyses. Now, 'mStat_normalize_data' function is automatically applying 'TSS' transformation." ) data.obj <- mStat_normalize_data(data.obj, method = "Rarefy-TSS")$data.obj.norm + } else if (feature.dat.type == "proportion"){ + } else if (feature.dat.type == "other"){ stop("The 'other' type is suitable for situations where the user has analyzed the data using a method not provided in 'mStat_normalize_data' method, and the 'areaplot' is only applicable to raw data that has not undergone any processing or proportion data that adds up to 1. If you believe your data falls into these two categories, please modify 'feature.dat.type'.") } diff --git a/R/generate_taxa_change_test_pair.R b/R/generate_taxa_change_test_pair.R index ec839ea..af79828 100644 --- a/R/generate_taxa_change_test_pair.R +++ b/R/generate_taxa_change_test_pair.R @@ -84,15 +84,13 @@ is_categorical <- function(x) { #' subject.var = "subject", #' time.var = "time", #' group.var = "group", -#' adj.vars = NULL, +#' adj.vars = "sex", #' change.base = "1", #' feature.change.func = "log fold change", #' feature.level = c("Genus"), #' prev.filter = 0.1, #' abund.filter = 1e-4, -#' feature.dat.type = "count", -#' feature.mt.method = "none", -#' feature.sig.level = 0.1 +#' feature.dat.type = "count" #' ) #' } #' @@ -314,14 +312,19 @@ generate_taxa_change_test_pair <- # Run ANOVA on the model if group.var is multi-categorical if (length(unique(test_df[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(test_result)) + anova <- anova(test_result) + anova.tab <- anova %>% + as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% select( term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) diff --git a/R/generate_taxa_volatility_test_long.R b/R/generate_taxa_volatility_test_long.R index fd04a91..0bab230 100644 --- a/R/generate_taxa_volatility_test_long.R +++ b/R/generate_taxa_volatility_test_long.R @@ -64,9 +64,7 @@ #' adj.vars = "sample_body_site", #' prev.filter = 0.1, #' abund.filter = 0.0001, -#' feature.mt.method = "fdr", -#' feature.sig.level = 0.1, -#' feature.level = c("Genus", "Family", "Species"), +#' feature.level = c("Genus"), #' feature.dat.type = "count", #' transform = "CLR" #' ) @@ -186,8 +184,10 @@ generate_taxa_volatility_test_long <- function(data.obj, rownames_to_column(feature.level) %>% tidyr::gather(key = "sample", value = "value",-feature.level) + taxa.levels <- otu_tax_agg_clr_long %>% select(all_of(feature.level)) %>% pull() %>% unique() + sub_test.list <- - lapply(otu_tax_agg_clr_long %>% select(all_of(feature.level)) %>% pull() %>% unique(), function(taxon) { + lapply(taxa.levels, function(taxon) { taxa_df <- otu_tax_agg_clr_long %>% dplyr::filter(!!sym(feature.level) == taxon) %>% @@ -219,14 +219,18 @@ generate_taxa_volatility_test_long <- function(data.obj, # Run ANOVA on the model if group.var is multi-categorical if (length(unique(taxa_df[[group.var]])) > 2) { - anova.tab <- broom::tidy(anova(test_result)) + anova <- anova(test_result) + anova.tab <- anova %>% as.data.frame() %>% + rownames_to_column("term") %>% + rename(`F value` = "statistic", + `Pr(>F)` = "p.value") %>% + as_tibble() # Rearrange the table and add missing columns anova.tab <- anova.tab %>% select( term = term, Statistic = statistic, - df = df, P.Value = p.value ) %>% dplyr::mutate(Estimate = NA, Std.Error = NA) diff --git a/R/linda.R b/R/linda.R index e77c091..7470519 100644 --- a/R/linda.R +++ b/R/linda.R @@ -118,6 +118,7 @@ winsor.fun <- function(Y, quan, feature.dat.type) { #' @import parallel #' @examples #' \dontrun{ +#' library(ggrepel) #' data(smokers) #' ind <- smokers$meta$AIRWAYSITE == "Throat" #' otu.tab <- as.data.frame(smokers$otu[, ind]) @@ -418,9 +419,9 @@ linda <- function(feature.dat, meta.dat, phyloseq.obj = NULL, formula, feature.d #' @references Huijuan Zhou, Kejun He, Jun Chen, and Xianyang Zhang. LinDA: Linear Models for Differential Abundance #' Analysis of Microbiome Compositional Data. #' @import ggplot2 -#' @import ggrepel #' @examples #' \dontrun{ +#' library(ggrepel) #' data(smokers) #' ind <- smokers$meta$AIRWAYSITE == "Throat" #' otu.tab <- as.data.frame(smokers$otu[, ind]) @@ -575,7 +576,7 @@ linda.plot <- function(linda.obj, variables.plot, titles = NULL, alpha = 0.05, l ) plot.volcano.i <- ggplot(data.volcano, aes(x = Log2FoldChange, y = Log10Padj)) + geom_point(aes(color = leg), size = 2) + - geom_text_repel(aes(label = taxa), max.overlaps = Inf) + + ggrepel::geom_text_repel(aes(label = taxa), max.overlaps = Inf) + scale_colour_manual(values = c("darkgray", color[c(2, 3, 1)])) + geom_hline(aes(yintercept = -log10(alpha)), color = "gray", linetype = "dashed") + geom_vline(aes(xintercept = -lfc.cut), color = "gray", linetype = "dashed") + diff --git a/R/mStat_calculate_PC.R b/R/mStat_calculate_PC.R index d2bdff5..cc1586e 100644 --- a/R/mStat_calculate_PC.R +++ b/R/mStat_calculate_PC.R @@ -30,6 +30,10 @@ #' @export mStat_calculate_PC <- function(dist.obj, method = c('mds'), k = 2, dist.name = NULL) { + if (is.null(dist.name)){ + return() + } + calculate_single_method <- function(m, dist_matrix, k, perplexity = NULL) { if (m == 'mds') { message("Calculating MDS...") diff --git a/R/mStat_calculate_adjusted_distance.R b/R/mStat_calculate_adjusted_distance.R index a86a131..be16de8 100644 --- a/R/mStat_calculate_adjusted_distance.R +++ b/R/mStat_calculate_adjusted_distance.R @@ -49,6 +49,11 @@ mStat_calculate_adjusted_distance <- function (data.obj, dist.obj, adj.vars, dist.name) { + + if (is.null(dist.name)){ + return() + } + # Message to inform the user message( "Calculating adjusted distances using the provided adjustment variables and distance matrices..." diff --git a/R/mStat_calculate_alpha_diversity.R b/R/mStat_calculate_alpha_diversity.R index 501c1ea..513410a 100644 --- a/R/mStat_calculate_alpha_diversity.R +++ b/R/mStat_calculate_alpha_diversity.R @@ -19,6 +19,10 @@ #' @export mStat_calculate_alpha_diversity <- function(x, alpha.name) { + if (is.null(alpha.name)){ + return() + } + x_transpose <- t(x) alpha.obj <- lapply(alpha.name, function(index) { diff --git a/R/mStat_calculate_beta_diversity.R b/R/mStat_calculate_beta_diversity.R index e816c3c..465643a 100644 --- a/R/mStat_calculate_beta_diversity.R +++ b/R/mStat_calculate_beta_diversity.R @@ -36,6 +36,10 @@ mStat_calculate_beta_diversity <- function(data.obj, dist.name = c('BC', 'Jaccard', 'UniFrac', 'GUniFrac', 'WUniFrac', 'JS')) { + if (is.null(dist.name)){ + return() + } + otu_tab <- data.obj$feature.tab tax_tab <- data.obj$feature.ann meta_tab <- data.obj$meta.dat @@ -89,6 +93,10 @@ mStat_calculate_beta_diversity <- function(data.obj, } if ('JS' %in% dist.name) { + if (!"philentropy" %in% utils::installed.packages()) { + message("The 'philentropy' package is required for Jensen-Shannon divergence calculation. Please install it using install.packages('philentropy').") + return() + } message("Calculating Jensen-Shannon divergence...") jsd <- philentropy::JSD(as.matrix(t(otu_tab))) rownames(jsd) <- colnames(otu_tab) diff --git a/R/mStat_generate_report_long.R b/R/mStat_generate_report_long.R index fe08317..8370944 100644 --- a/R/mStat_generate_report_long.R +++ b/R/mStat_generate_report_long.R @@ -171,7 +171,7 @@ #' #' @examples #' \dontrun{ -#' #' data(subset_T2D.obj) +#' data(subset_T2D.obj) #' mStat_generate_report_long( #' data.obj = subset_T2D.obj, #' group.var = "subject_race", @@ -202,6 +202,37 @@ #' base.size = 20, #' output.file = "/Users/apple/MicrobiomeStat/report.pdf" #' ) +#' data(ecam.obj) +#' mStat_generate_report_long( +#' data.obj = ecam.obj, +#' group.var = "antiexposedall", +#' strata.var = "diet", +#' test.adj.vars = "delivery", +#' vis.adj.vars = "delivery", +#' subject.var = "subject.id", +#' time.var = "month_num", +#' t0.level = NULL, +#' ts.levels = NULL, +#' alpha.obj = NULL, +#' alpha.name = c("shannon","observed_species"), +#' dist.obj = NULL, +#' dist.name = c("BC",'Jaccard'), +#' pc.obj = NULL, +#' feature.mt.method = "none", +#' feature.sig.level = 0.3, +#' vis.feature.level = c("Family","Genus"), +#' test.feature.level = c("Family"), +#' feature.change.func = "relative change", +#' feature.dat.type = "proportion", +#' prev.filter = 0.1, +#' abund.filter = 1e-4, +#' bar.area.feature.no = 40, +#' heatmap.feature.no = 40, +#' feature.box.axis.transform = "sqrt", +#' theme.choice = "bw", +#' base.size = 20, +#' output.file = "/Users/apple/MicrobiomeStat/ecam_obj_report_long.pdf" +#' ) #' } #' @export mStat_generate_report_long <- function(data.obj, @@ -377,7 +408,7 @@ if (!all(unique_levels %in% names(data.obj$feature.agg.list))) { } if (is.null(depth)){ - depth <- min(colSums(data.obj$feature.tab)) + depth <- round(min(colSums(data.obj$feature.tab))) cat(sprintf('No rarefaction depth is specified. The minimum depth, %d, is used as the rarefaction depth. ', depth)) } diff --git a/R/mStat_generate_report_pair.R b/R/mStat_generate_report_pair.R index 6d735c3..4efc280 100644 --- a/R/mStat_generate_report_pair.R +++ b/R/mStat_generate_report_pair.R @@ -352,7 +352,7 @@ original.data.obj <- data.obj rarefy.data.obj <- mStat_normalize_data(data.obj = data.obj, method = 'Rarefy', depth = depth)$data.obj.norm if (is.null(depth)){ - depth <- min(colSums(data.obj$feature.tab)) + depth <- round(min(colSums(data.obj$feature.tab))) cat(sprintf('No rarefaction depth is specified. The minimum depth, %d, is used as the rarefaction depth. ', depth)) } diff --git a/R/mStat_generate_report_single.R b/R/mStat_generate_report_single.R index 15df9a0..024b4b4 100644 --- a/R/mStat_generate_report_single.R +++ b/R/mStat_generate_report_single.R @@ -105,6 +105,7 @@ #' #' @examples #' \dontrun{ +#' library(aplot) #' data(peerj32.obj) #' mStat_generate_report_single( #' data.obj = peerj32.obj, @@ -155,6 +156,31 @@ #' feature.sig.level = 0.2, #' output.file = "/Users/apple/MicrobiomeStat/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/MicrobiomeStat/ecam.obj_report.pdf" +#' ) #' } #' @export mStat_generate_report_single <- function(data.obj, @@ -330,7 +356,7 @@ if (!all(unique_levels %in% names(data.obj$feature.agg.list))) { } if (is.null(depth)){ - depth <- min(colSums(data.obj$feature.tab)) + depth <- round(min(colSums(data.obj$feature.tab))) cat(sprintf('No rarefaction depth is specified. The minimum depth, %d, is used as the rarefaction depth. ', depth)) } @@ -761,8 +787,7 @@ taxa_test_results <- generate_taxa_test_single(data.obj = data.obj, feature.level = test.feature.level, feature.dat.type = feature.dat.type, feature.sig.level = feature.sig.level, - feature.mt.method = feature.mt.method, - ...) + feature.mt.method = feature.mt.method) ``` ```{r taxa-test-results-display, echo=FALSE, message=FALSE, results='asis', warning = FALSE, fig.align='center', fig.width = 10, fig.height = 8} @@ -834,7 +859,7 @@ cat(sprintf('\n\nThe differential abundance test results for features have been ``` -```{r extract_significant_taxa, echo=FALSE, results='hide'} +```{r extract_significant_taxa, echo=FALSE, results='hide', warning = FALSE} # Extract Variables based on the provided condition extract_significant_variables <- function(data_frame, p_value_column) { filtered_df <- data_frame %>% @@ -871,7 +896,7 @@ significant_vars <- as.vector(significant_vars) ### 4.2.1 Significant features boxplot -```{r taxa-significant-boxplot-generation, message=FALSE, fig.align='center', fig.width = 15, fig.height = 15, results='asis'} +```{r taxa-significant-boxplot-generation, message=FALSE, fig.align='center', fig.width = 15, fig.height = 15, results='asis', warning = FALSE} taxa_boxplot_results <- generate_taxa_boxplot_single( data.obj = data.obj, @@ -924,7 +949,7 @@ taxa_indiv_boxplot_results <- generate_taxa_indiv_boxplot_single( ``` -```{r taxa-indiv-boxplot-pdf-name, echo=FALSE, message=FALSE, results='asis'} +```{r taxa-indiv-boxplot-pdf-name, echo=FALSE, message=FALSE, results='asis', warning = FALSE} pdf_name <- paste0( 'taxa_indiv_boxplot_single', '_', diff --git a/R/mStat_import_qiime2_as_data_obj.R b/R/mStat_import_qiime2_as_data_obj.R index a9d2129..dc5cfb3 100644 --- a/R/mStat_import_qiime2_as_data_obj.R +++ b/R/mStat_import_qiime2_as_data_obj.R @@ -14,6 +14,9 @@ #' #' @examples #' \dontrun{ +#' # This function requires the `Biostrings` and `yaml` packages. +#' # If you encounter issues when running the example code, +#' # please ensure that you have installed and loaded these packages. #' # library(Biostrings) #' # library(yaml) #' data_obj <- mStat_import_qiime2_as_data_obj(otu_qza = "path_to_otu.qza", diff --git a/R/mStat_normalize_data.R b/R/mStat_normalize_data.R index c7ece25..5442fad 100644 --- a/R/mStat_normalize_data.R +++ b/R/mStat_normalize_data.R @@ -35,9 +35,9 @@ is_count_data <- function(data_mat) { #' @examples #' \dontrun{ #' data(peerj32.obj) -#' peerj32.obj <- mStat_aggregate_by_taxonomy(peerj32.obj, method = "TSS") +#' peerj32.obj <- mStat_normalize_data(peerj32.obj, method = "TSS") #' # library(edgeR) -#' # peerj32.obj <- mStat_aggregate_by_taxonomy(peerj32.obj, method = "TMM") +#' # peerj32.obj <- mStat_normalize_data(peerj32.obj, method = "TMM") #' } #' #' @details @@ -68,8 +68,12 @@ mStat_normalize_data <- } rarefy_depth <- ifelse(is.null(depth), min(colSums(otu_tab)), depth) - rarefied_otu_tab <- - t(vegan::rrarefy(t(otu_tab), sample = rarefy_depth)) + if (all(round(colSums(otu_tab),5) ==1)){ + rarefied_otu_tab <- as.matrix(otu_tab) + } else { + rarefied_otu_tab <- + t(vegan::rrarefy(t(otu_tab), sample = rarefy_depth)) + } rarefied_otu_tab <- rarefied_otu_tab / rarefy_depth scale_factor <- rarefy_depth } else if (method == "Rarefy") { @@ -80,8 +84,12 @@ mStat_normalize_data <- } rarefy_depth <- ifelse(is.null(depth), min(colSums(otu_tab)), depth) - rarefied_otu_tab <- - t(vegan::rrarefy(t(otu_tab), sample = rarefy_depth)) + if (all(round(colSums(otu_tab),5) ==1)){ + rarefied_otu_tab <- as.matrix(otu_tab) + } else { + rarefied_otu_tab <- + t(vegan::rrarefy(t(otu_tab), sample = rarefy_depth)) + } scale_factor <- rarefy_depth } else if (method == "TSS") { scale_factor <- colSums(otu_tab) diff --git a/R/mStat_rarefy_data.R b/R/mStat_rarefy_data.R index 5151445..8b21a35 100644 --- a/R/mStat_rarefy_data.R +++ b/R/mStat_rarefy_data.R @@ -43,7 +43,11 @@ mStat_rarefy_data <- function(data.obj, depth = NULL) { } # Rarefy the data - rarefied_otu_tab <- t(vegan::rrarefy(t(otu_tab), sample = depth)) + if (all(round(colSums(otu_tab),5) ==1)){ + rarefied_otu_tab <- as.matrix(otu_tab) + } else { + rarefied_otu_tab <- t(vegan::rrarefy(t(otu_tab), sample = depth)) + } # Identify all-zero rows zero_row_indices <- which(rowSums(rarefied_otu_tab) == 0) diff --git a/man/generate_alpha_change_test_pair.Rd b/man/generate_alpha_change_test_pair.Rd index 2e7a7f1..7c9463f 100644 --- a/man/generate_alpha_change_test_pair.Rd +++ b/man/generate_alpha_change_test_pair.Rd @@ -115,10 +115,10 @@ alpha.obj = NULL, time.var = "time", alpha.name = c("shannon"), subject.var = "subject", -group.var = "group", -adj.vars = "sex", -change.base = "1", -alpha.change.func = "absolute change" +group.var = "sex", +adj.vars = "group", +change.base = "2", +alpha.change.func = "log fold change" ) } } diff --git a/man/generate_alpha_test_pair.Rd b/man/generate_alpha_test_pair.Rd index 2546406..80a27d2 100644 --- a/man/generate_alpha_test_pair.Rd +++ b/man/generate_alpha_test_pair.Rd @@ -66,7 +66,7 @@ time.var = "time", alpha.name = c("shannon"), subject.var = "subject", group.var = "group", -adj.vars = "sex" +adj.vars = NULL ) } diff --git a/man/generate_alpha_volatility_test_long.Rd b/man/generate_alpha_volatility_test_long.Rd index 42f5bf5..7423f0b 100644 --- a/man/generate_alpha_volatility_test_long.Rd +++ b/man/generate_alpha_volatility_test_long.Rd @@ -68,7 +68,7 @@ alpha.name = c("shannon","observed_species"), time.var = "visit_number_num", subject.var = "subject_id", group.var = "subject_race", -adj.vars = "sample_body_site" +adj.vars = NULL ) } } diff --git a/man/generate_beta_change_test_pair.Rd b/man/generate_beta_change_test_pair.Rd index 175e472..f9c92fd 100644 --- a/man/generate_beta_change_test_pair.Rd +++ b/man/generate_beta_change_test_pair.Rd @@ -82,7 +82,7 @@ generate_beta_change_test_pair( time.var = "time", subject.var = "subject", group.var = "group", - adj.vars = c("sex"), + adj.vars = "sex", change.base = "1", dist.name = c('BC', 'Jaccard') ) diff --git a/man/generate_beta_ordination_single.Rd b/man/generate_beta_ordination_single.Rd index a65913d..125905d 100644 --- a/man/generate_beta_ordination_single.Rd +++ b/man/generate_beta_ordination_single.Rd @@ -106,6 +106,7 @@ The function is flexible and allows for various modifications, including the cho } \examples{ \dontrun{ +library(aplot) data(peerj32.obj) dist.obj <- mStat_calculate_beta_diversity(peerj32.obj, dist.name = c('BC', 'Jaccard')) pc.obj <- mStat_calculate_PC(dist.obj, method = c('mds'), k = 2, dist.name = c('BC','Jaccard')) diff --git a/man/generate_beta_pc_volatility_test_long.Rd b/man/generate_beta_pc_volatility_test_long.Rd index 4642e0d..6ef41d1 100644 --- a/man/generate_beta_pc_volatility_test_long.Rd +++ b/man/generate_beta_pc_volatility_test_long.Rd @@ -79,7 +79,7 @@ generate_beta_pc_volatility_test_long( subject.var = "studyid", time.var = "month", group.var = "diet", - adj.vars = "delivery", + adj.vars = NULL, dist.name = c('BC') ) } diff --git a/man/generate_beta_volatility_test_long.Rd b/man/generate_beta_volatility_test_long.Rd index 8de0ba8..2fba697 100644 --- a/man/generate_beta_volatility_test_long.Rd +++ b/man/generate_beta_volatility_test_long.Rd @@ -58,6 +58,7 @@ A warning message will be displayed to ensure that the time variable is coded as Non-numeric coding may lead to issues in the volatility test computation. } \examples{ +\dontrun{ data(ecam.obj) generate_beta_volatility_test_long( data.obj = ecam.obj, @@ -84,6 +85,7 @@ generate_beta_volatility_test_long( dist.name = c("BC", "Jaccard") ) } +} \seealso{ mStat_calculate_beta_diversity, mStat_calculate_adjusted_distance } diff --git a/man/generate_taxa_change_test_pair.Rd b/man/generate_taxa_change_test_pair.Rd index 7f26ef7..9e90d3b 100644 --- a/man/generate_taxa_change_test_pair.Rd +++ b/man/generate_taxa_change_test_pair.Rd @@ -95,15 +95,13 @@ generate_taxa_change_test_pair( subject.var = "subject", time.var = "time", group.var = "group", - adj.vars = NULL, + adj.vars = "sex", change.base = "1", feature.change.func = "log fold change", feature.level = c("Genus"), prev.filter = 0.1, abund.filter = 1e-4, - feature.dat.type = "count", - feature.mt.method = "none", - feature.sig.level = 0.1 + feature.dat.type = "count" ) } diff --git a/man/generate_taxa_volatility_test_long.Rd b/man/generate_taxa_volatility_test_long.Rd index 2b12965..91353d3 100644 --- a/man/generate_taxa_volatility_test_long.Rd +++ b/man/generate_taxa_volatility_test_long.Rd @@ -101,9 +101,7 @@ group.var = "subject_race", adj.vars = "sample_body_site", prev.filter = 0.1, abund.filter = 0.0001, -feature.mt.method = "fdr", -feature.sig.level = 0.1, -feature.level = c("Genus", "Family", "Species"), +feature.level = c("Genus"), feature.dat.type = "count", transform = "CLR" ) diff --git a/man/linda.Rd b/man/linda.Rd index 550a2bc..659d059 100644 --- a/man/linda.Rd +++ b/man/linda.Rd @@ -107,6 +107,7 @@ Note that linda is developed separately from other MicrobiomeStat functions, so } \examples{ \dontrun{ +library(ggrepel) data(smokers) ind <- smokers$meta$AIRWAYSITE == "Throat" otu.tab <- as.data.frame(smokers$otu[, ind]) diff --git a/man/linda.plot.Rd b/man/linda.plot.Rd index 8717c70..943480b 100644 --- a/man/linda.plot.Rd +++ b/man/linda.plot.Rd @@ -47,6 +47,7 @@ The function plots the effect size plot and volcano plot based on the output fro } \examples{ \dontrun{ +library(ggrepel) data(smokers) ind <- smokers$meta$AIRWAYSITE == "Throat" otu.tab <- as.data.frame(smokers$otu[, ind]) diff --git a/man/mStat_generate_report_single.Rd b/man/mStat_generate_report_single.Rd index f3ff0f3..4c42e55 100644 --- a/man/mStat_generate_report_single.Rd +++ b/man/mStat_generate_report_single.Rd @@ -186,6 +186,7 @@ to perform analysis on cross-sectional data, a single time point from longitudin } \examples{ \dontrun{ +library(aplot) data(peerj32.obj) mStat_generate_report_single( data.obj = peerj32.obj, diff --git a/man/mStat_import_mothur_as_data_obj.Rd b/man/mStat_import_mothur_as_data_obj.Rd index 4344573..d20f6b2 100644 --- a/man/mStat_import_mothur_as_data_obj.Rd +++ b/man/mStat_import_mothur_as_data_obj.Rd @@ -40,6 +40,7 @@ MicrobiomeStat is a comprehensive and user-friendly tool designed for robust mic } \examples{ \dontrun{ +# Make sure to load the plyr package # library(plyr) # path_to_list_file <- "/Users/apple/Downloads/esophagus/Esophagus/esophagus.fn.list" # path_to_group_file <- "/Users/apple/Downloads/esophagus/Esophagus/esophagus.good.groups" diff --git a/man/mStat_import_qiime2_as_data_obj.Rd b/man/mStat_import_qiime2_as_data_obj.Rd index 57d5a53..0dcf8c0 100644 --- a/man/mStat_import_qiime2_as_data_obj.Rd +++ b/man/mStat_import_qiime2_as_data_obj.Rd @@ -34,6 +34,9 @@ MicrobiomeStat is a comprehensive and user-friendly tool designed for robust mic } \examples{ \dontrun{ +# This function requires the `Biostrings` and `yaml` packages. +# If you encounter issues when running the example code, +# please ensure that you have installed and loaded these packages. # library(Biostrings) # library(yaml) data_obj <- mStat_import_qiime2_as_data_obj(otu_qza = "path_to_otu.qza",