Skip to content

Commit

Permalink
Improved Function Compatibility and Dependency Updates
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
cafferychen777 committed Oct 13, 2023
1 parent dea61d6 commit 23c0b9f
Show file tree
Hide file tree
Showing 54 changed files with 368 additions and 109 deletions.
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ Depends:
Imports:
ggplot2,
matrixStats,
parallel,
ggrepel,
lmerTest,
foreach,
modeest,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions R/generate_alpha_boxplot_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
5 changes: 5 additions & 0 deletions R/generate_alpha_boxplot_single.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions R/generate_alpha_change_boxplot_pair.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
63 changes: 32 additions & 31 deletions R/generate_alpha_change_test_pair.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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 <-
Expand Down
4 changes: 4 additions & 0 deletions R/generate_alpha_spaghettiplot_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
22 changes: 16 additions & 6 deletions R/generate_alpha_test_pair.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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 %>%
Expand All @@ -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
Expand Down
29 changes: 24 additions & 5 deletions R/generate_alpha_test_single.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <-
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions R/generate_alpha_trend_test_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 13 additions & 3 deletions R/generate_alpha_volatility_test_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions R/generate_beta_change_boxplot_pair.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down
5 changes: 5 additions & 0 deletions R/generate_beta_change_spaghettiplot_long.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading

0 comments on commit 23c0b9f

Please sign in to comment.