Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
^README\.Rmd$
^\.github$
^codecov\.yml$
^pkgdown$
^README\.html$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dev
inst/doc
vignettes/*.html
vignettes/*.R
/doc/
/Meta/
19 changes: 14 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ BugReports: https://github.com/microbiome/daa/issues/
biocViews: Software, Microbiome
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Depends:
R (>= 4.5.0)
R (>= 4.5.0),
SummarizedExperiment
Imports:
dplyr
dplyr,
rlang,
rstatix,
SingleCellExperiment,
stats,
tidyr
Suggests:
broom,
limma,
logistf,
mia,
rms,
BiocStyle,
knitr,
RefManageR,
rmarkdown,
sessioninfo,
testthat
Config/testthat/edition: 3
VignetteBuilder: knitr
28 changes: 28 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# Generated by roxygen2: do not edit by hand

export(getAnova)
export(getFirth)
export(getKruskal)
export(getLimma)
export(getLm)
export(getOrm)
export(getTTest)
export(getWilcoxonTest)
importFrom(SummarizedExperiment,assay)
importFrom(SummarizedExperiment,assayNames)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n_distinct)
importFrom(dplyr,ungroup)
importFrom(rlang,"!!")
importFrom(rlang,.data)
importFrom(rlang,sym)
importFrom(rstatix,anova_test)
importFrom(rstatix,kruskal_test)
importFrom(rstatix,t_test)
importFrom(rstatix,wilcox_test)
importFrom(tidyr,pivot_longer)
34 changes: 34 additions & 0 deletions R/getAnova.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @title Perform ANOVA
#'
#' @description
#' Performs ANOVA to compare values between two or more groups.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the variable to test
#' (assay name, colData, or rowData variable) and the RHS specifies the
#' grouping variable, e.g., \code{counts ~ Group}.
#' @param ... Additional arguments passed to \code{rstatix::anova_test}.
#'
#' @return A \code{data.frame} with test results.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' res <- getAnova(tse, counts ~ Geographical_location)
#'
#' @importFrom rstatix anova_test
#' @export
getAnova <- function(tse, formula, ...) {
if (length(all.vars(formula[[3]])) != 1L) {
stop("Formula RHS must specify exactly one grouping variable.",
call. = FALSE
)
}
df <- .get_long_data(tse, formula)
res <- .calculate_rstatix(
df = df, formula = formula,
FUN = rstatix::anova_test, ...
Comment thread
0xMuluh marked this conversation as resolved.
Resolved
)
return(res)
}
34 changes: 34 additions & 0 deletions R/getFirth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @title Fit Firth logistic regression per feature
#'
#' @description
#' Fits Firth logistic regression per feature using wide-format data.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the assay or colData
#' variable (must be binary/presence-absence) and the RHS specifies variables
#' from \code{colData(tse)}, e.g., \code{pa ~ Group + Age}.
#' @param ... Additional arguments (reserved for future use).
#'
#' @return A \code{data.frame} with per-feature model coefficients, p-values,
#' and BH-adjusted q-values.
#'
#' @examples
#' \dontrun{
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' tse <- mia::transformAssay(tse, method = "pa")
#' res <- getFirth(tse, pa ~ Geographical_location)
#' }
#'
#' @export
getFirth <- function(tse, formula, ...) {
data_list <- .get_wide_data(tse, formula)
res <- .train_model_per_feature(
formula = formula,
mat = data_list[["matrix"]],
metadata = data_list[["sample_metadata"]],
FUN = .run_firth
)
return(res)
}
34 changes: 34 additions & 0 deletions R/getKruskal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @title Perform Kruskal-Wallis test
#'
#' @description
#' Performs Kruskal-Wallis test to compare values between two or more groups.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the variable to test
#' (assay name, colData, or rowData variable) and the RHS specifies the
#' grouping variable, e.g., \code{counts ~ Group}.
#' @param ... Additional arguments passed to \code{rstatix::kruskal_test}.
#'
#' @return A \code{data.frame} with test results.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' res <- getKruskal(tse, counts ~ Geographical_location)
#'
#' @importFrom rstatix kruskal_test
#' @export
getKruskal <- function(tse, formula, ...) {
if (length(all.vars(formula[[3]])) != 1L) {
stop("Formula RHS must specify exactly one grouping variable.",
call. = FALSE
)
}
df <- .get_long_data(tse, formula)
res <- .calculate_rstatix(
df = df, formula = formula,
FUN = rstatix::kruskal_test, ...
)
return(res)
}
29 changes: 29 additions & 0 deletions R/getLimma.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' @title Fit limma model
#'
#' @description
#' Fits a limma model using wide-format data and sample metadata.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the assay or colData
#' variable and the RHS specifies variables from \code{colData(tse)},
#' e.g., \code{counts ~ Group}.
#' @param ... Additional arguments (reserved for future use).
#'
#' @return A fitted limma model object (result of \code{limma::eBayes}).
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' fit <- getLimma(tse, counts ~ Geographical_location)
#'
#' @export
getLimma <- function(tse, formula, ...) {
data_list <- .get_wide_data(tse, formula)
res <- .calculate_limma(
formula = formula,
mat = data_list[["matrix"]],
metadata = data_list[["sample_metadata"]]
)
return(res)
}
32 changes: 32 additions & 0 deletions R/getLm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' @title Fit linear model per feature
#'
#' @description
#' Fits a linear model per feature using wide-format data and sample metadata.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the assay or colData
#' variable and the RHS specifies variables from \code{colData(tse)},
#' e.g., \code{rclr ~ Group}.
#' @param ... Additional arguments (reserved for future use).
#'
#' @return A \code{data.frame} with per-feature model coefficients, p-values,
#' and BH-adjusted q-values.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' tse <- mia::transformAssay(tse, method = "rclr")
#' res <- getLm(tse, rclr ~ Geographical_location)
#'
#' @export
getLm <- function(tse, formula, ...) {
data_list <- .get_wide_data(tse, formula)
res <- .train_model_per_feature(
formula = formula,
mat = data_list[["matrix"]],
metadata = data_list[["sample_metadata"]],
FUN = .run_lm
)
return(res)
}
31 changes: 31 additions & 0 deletions R/getOrm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' @title Fit ordinal regression model per feature
#'
#' @description
#' Fits an ordinal regression model (ORM) per feature using wide-format data.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the assay or colData
#' variable and the RHS specifies variables from \code{colData(tse)},
#' e.g., \code{counts ~ Group}.
#' @param ... Additional arguments (reserved for future use).
#'
#' @return A \code{data.frame} with per-feature model coefficients, p-values,
#' and BH-adjusted q-values.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' res <- getOrm(tse, counts ~ Geographical_location)
#'
#' @export
getOrm <- function(tse, formula, ...) {
data_list <- .get_wide_data(tse, formula)
res <- .train_model_per_feature(
formula = formula,
mat = data_list[["matrix"]],
metadata = data_list[["sample_metadata"]],
FUN = .run_orm
)
return(res)
}
36 changes: 36 additions & 0 deletions R/getTTest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' @title Perform t-test
#'
#' @description
#' Performs t-test to compare values between two groups.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the variable to test
#' (assay name, colData, or rowData variable) and the RHS specifies the
#' grouping variable, e.g., \code{counts ~ Group}.
#' @param pair.by \code{Character scalar} or \code{NULL}. Column for pairing
#' samples in paired tests. (Default: \code{NULL})
#' @param ... Additional arguments passed to \code{rstatix::t_test}.
#'
#' @return A \code{data.frame} with test results.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' res <- getTTest(tse, counts ~ Geographical_location)
#'
#' @importFrom rstatix t_test
#' @export
getTTest <- function(tse, formula, pair.by = NULL, ...) {
if (length(all.vars(formula[[3]])) != 1L) {
stop("Formula RHS must specify exactly one grouping variable.",
call. = FALSE
)
}
df <- .get_long_data(tse, formula, pair.by)
res <- .calculate_rstatix(
df = df, formula = formula,
pair.by = pair.by, FUN = rstatix::t_test, ...
)
return(res)
}
37 changes: 37 additions & 0 deletions R/getWilcoxonTest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' @title Perform Wilcoxon rank-sum test
#'
#' @description
#' Performs Wilcoxon rank-sum test (Mann-Whitney U) to compare values between
#' two groups.
#'
#' @param tse A \code{SummarizedExperiment} object.
#' @param formula A formula where the LHS specifies the variable to test
#' (assay name, colData, or rowData variable) and the RHS specifies the
#' grouping variable, e.g., \code{counts ~ Group}.
#' @param pair.by \code{Character scalar} or \code{NULL}. Column for pairing
#' samples in paired tests. (Default: \code{NULL})
#' @param ... Additional arguments passed to \code{rstatix::wilcox_test}.
#'
#' @return A \code{data.frame} with test results.
#'
#' @examples
#' data(peerj13075, package = "mia")
#' tse <- peerj13075
#' tse <- mia::agglomerateByRank(tse, "phylum")
#' res <- getWilcoxonTest(tse, counts ~ Geographical_location)
#'
#' @importFrom rstatix wilcox_test
#' @export
getWilcoxonTest <- function(tse, formula, pair.by = NULL, ...) {
if (length(all.vars(formula[[3]])) != 1L) {
stop("Formula RHS must specify exactly one grouping variable.",
call. = FALSE
)
}
df <- .get_long_data(tse, formula, pair.by)
res <- .calculate_rstatix(
df = df, formula = formula,
pair.by = pair.by, FUN = rstatix::wilcox_test, ...
)
return(res)
}
Loading
Loading