Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman committed Nov 5, 2024
1 parent 5be0081 commit 1151994
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
13 changes: 10 additions & 3 deletions R/getPERMANOVA.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#' @param name \code{Character scalar}. A name for the results that will be
#' stored to metadata. (Default: \code{"permanova"})
#'
#' @param method \code{Character scalar}. A dissimilarity metric used in
#' PERMANOVA and group dispersion calculation. (Default: \code{"bray"})
#'
#' @param test.homogeneity \code{Logical scalar}. Should the homogeneity of
#' group dispersions be evaluated? (Default: \code{TRUE})
#'
Expand Down Expand Up @@ -143,7 +146,7 @@ setMethod("getPERMANOVA", "SummarizedExperiment",
#' @export
#' @rdname getPERMANOVA
setMethod("getPERMANOVA", "ANY", function(
x, formula, data, test.homogeneity = TRUE, ...){
x, formula, data, method = "bray", test.homogeneity = TRUE, ...){
if( !is.matrix(x) ){
stop("'x' must be matrix.", call. = FALSE)
}
Expand All @@ -157,14 +160,18 @@ setMethod("getPERMANOVA", "ANY", function(
stop("Number of columns in 'x' should match with number of rows in ",
"'data'.", call. = FALSE)
}
if( !.is_a_string(method) ){
stop("'method' must be a single character value.", call. = FALSE)
}
if( !.is_a_bool(test.homogeneity) ){
stop("'test.homogeneity' must be TRUE or FALSE.", call. = FALSE)
}
# Calculate PERMANOVA
res <- .calculate_permanova(x, formula = formula, data = data, ...)
res <- .calculate_permanova(
x, formula = formula, data = data, method = method, ...)
# Test homogeneity
if( test.homogeneity ){
homogeneity <- .calculate_homogeneity(x, data, ...)
homogeneity <- .calculate_homogeneity(x, data, method = method, ...)
res <- list(permanova = res, homogeneity = homogeneity)
}
return(res)
Expand Down
11 changes: 5 additions & 6 deletions R/runCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#' other internal functions.
#' \itemize{
#' \item \code{method} a dissimilarity measure to be applied in dbRDA and
#' possible following homogeneity test. (Default: \code{"bray"})
#' possible following homogeneity test. (Default: \code{"euclidean"})
#'
#' \item \code{scale}: \code{Logical scalar}. Should the expression values be
#' standardized? \code{scale} is disabled when using \code{*RDA} functions.
Expand Down Expand Up @@ -69,7 +69,7 @@
#'
#' @details
#' *CCA functions utilize \code{vegan:cca} and *RDA functions
#' \code{vegan:dbRDA}.dbRDA performed with euclidean distances
#' \code{vegan:dbRDA}. By default, dbRDA is done with euclidean distances, which
#' is equivalent to RDA. \code{col.var} and \code{formula} can be missing,
#' which turns the CCA analysis into a CA analysis and dbRDA into PCoA/MDS.
#'
Expand Down Expand Up @@ -473,7 +473,7 @@ setMethod("addRDA", "SingleCellExperiment",
#' @importFrom vegan cca dbrda sppscores<- eigenvals scores
.calculate_rda <- function(
x, formula, data, scores, scale = TRUE, na.action = na.fail,
method = distance, distance = "bray", ord.method = "CCA", ...){
method = distance, distance = "euclidean", ord.method = "CCA", ...){
# input check
if(!.is_a_bool(scale)){
stop("'scale' must be TRUE or FALSE.", call. = FALSE)
Expand Down Expand Up @@ -598,8 +598,7 @@ setMethod("addRDA", "SingleCellExperiment",
permanova_tab[ , "Total variance"]

# Perform homogeneity analysis
homogeneity <- .calculate_homogeneity(
mat, variables, method, full = full, ...)
homogeneity <- .calculate_homogeneity(mat, variables, full = full, ...)

# Return whole data or just a tables
permanova_res <- permanova_tab
Expand All @@ -615,7 +614,7 @@ setMethod("addRDA", "SingleCellExperiment",

#' @importFrom vegan vegdist betadisper
.calculate_homogeneity <- function(
mat, variables, method = distance, distance = "bray",
mat, variables, method = distance, distance = "euclidean",
homogeneity.test = "permanova", full = FALSE, ...){
# Check homogeneity.test
if( !(.is_a_string(homogeneity.test) &&
Expand Down
5 changes: 4 additions & 1 deletion man/getPERMANOVA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/runCCA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1151994

Please sign in to comment.