From b75207ad64e5dc73f2e46576cccf4610fd36f9a6 Mon Sep 17 00:00:00 2001 From: ake <40662956+ake123@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:57:10 +0300 Subject: [PATCH] #601 and OMA issue #482 (#602) Co-authored-by: Tuomas Borman <60338854+TuomasBorman@users.noreply.github.com> Co-authored-by: Leo Lahti --- DESCRIPTION | 15 ++++++++++++++- R/addAlpha.R | 23 ++++++++++++++++++++--- R/runCCA.R | 6 +++++- man/mia-package.Rd | 13 +++++++++++++ man/runCCA.Rd | 6 +++++- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3e0114d44..fe74dddde 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,20 @@ Authors@R: person(given = "Giulio", family = "Benedetti", role=c("ctb")), person(given = c("Moritz", "Emanuel"), family = "Beber", email = "moritz.beber@igdore.org", role = c("ctb"), - comment = c(ORCID = "0000-0003-2406-1978"))) + comment = c(ORCID = "0000-0003-2406-1978")), + person(given = "Nitesh", family = "Turaga", role=c("ctb")), + person(given = "Chouaib", family = "Benchraka", role=c("ctb")), + person(given = "Akewak", family = "Jeba", role=c("ctb")), + person(given = "Himmi", family = "Lindgren", role=c("ctb")), + person(given = "Noah", family = "De Gunst", role=c("ctb")), + person(given = "Théotime", family = "Pralas", role=c("ctb")), + person(given = "Shadman", family = "Ishraq", role=c("ctb")), + person(given = "Eineje", family = "Ameh", role=c("ctb")), + person(given = "Artur", family = "Sannikov", role=c("ctb")), + person(given = "Hervé", family = "Pagès", role=c("ctb")), + person(given = "Rajesh", family = "Shigdel", role=c("ctb")), + person(given = "Katariina", family = "Pärnänen", role=c("ctb")), + person(given = "Pande", family = "Erawijantari", role=c("ctb"))) Title: Microbiome analysis Description: mia implements tools for microbiome analysis based on the diff --git a/R/addAlpha.R b/R/addAlpha.R index f4549b605..fa71695bd 100644 --- a/R/addAlpha.R +++ b/R/addAlpha.R @@ -487,7 +487,8 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), } # Check if index exists. For each index input, detect it and get # information (e.g. internal function) to calculate the index. - index <- .get_indices(index, name, x, ...) + index <- .get_indices(index, name, x, assay.type, ...) + ############################ Input check end ########################### # Looping over the vector of indices to be estimated for( i in seq_len(nrow(index)) ){ @@ -512,7 +513,8 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), ################################ HELP FUNCTIONS ################################ # Search alpha diversity index that user wants to calculate. -.get_indices <- function(index, name, x, tree = NULL, ...){ + +.get_indices <- function(index, name, x, assay.type, tree = NULL,...){ # Initialize list for supported indices supported <- list() # Supported diversity indices @@ -523,6 +525,7 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), temp[["measure"]] <- "diversity" temp[["index_long"]] <- paste0(temp[["index"]], "_", temp[["measure"]]) temp[["FUN"]] <- ".estimate_diversity" + temp[["non_neg"]] <- c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) supported[["diversity"]] <- temp # Supported dominance indices temp <- c( @@ -532,6 +535,7 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), temp[["measure"]] <- "dominance" temp[["index_long"]] <- paste0(temp[["index"]], "_", temp[["measure"]]) temp[["FUN"]] <- ".estimate_dominance" + temp[["non_neg"]] <- c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) supported[["dominance"]] <- temp # Supported eveness indices temp <- c( @@ -540,6 +544,7 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), temp[["measure"]] <- "evenness" temp[["index_long"]] <- paste0(temp[["index"]], "_", temp[["measure"]]) temp[["FUN"]] <- ".estimate_evenness" + temp[["non_neg"]] <- c(FALSE, FALSE, FALSE, FALSE, FALSE) supported[["eveness"]] <- temp # Supported richness indices temp <- c( @@ -548,6 +553,7 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), temp[["measure"]] <- "richness" temp[["index_long"]] <- paste0(temp[["index"]], "_", temp[["measure"]]) temp[["FUN"]] <- ".estimate_richness" + temp[["non_neg"]] <- c(FALSE, FALSE, FALSE, FALSE) supported[["richness"]] <- temp # Combine supported <- do.call(rbind, supported) @@ -583,7 +589,18 @@ setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), FUN("'faith' index can be calculated only for TreeSE with rowTree(x) ", "populated or with 'tree' provided separately.", call. = FALSE) } - # Check if there are indices left + # Check for unsupported values (negative values) + if( any(assay(x, assay.type) < 0) ){ + ind <- detected[["non_neg"]] + index_rm <- detected[!ind, "index"] + detected <- detected[ind, ] + if( length(index_rm) > 0 ){ + FUN <- if (nrow(detected) == 0) stop else warning + FUN("The following indices cannot be calculated due to unsupported + values (negative values): ", paste(index_rm, collapse = ", "), + call. = FALSE) + } + } return(detected) } diff --git a/R/runCCA.R b/R/runCCA.R index eb979148d..152cc61c5 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -58,7 +58,9 @@ #' the significance test used to analyse \code{vegan::betadisper} results. #' Options include 'permanova' (\code{vegan::permutest}), 'anova' #' (\code{stats::anova}) and 'tukeyhsd' (\code{stats::TukeyHSD}). -#' (Default: \code{"permanova"})} +#' (By default: \code{homogeneity.test="permanova"})} +#' \item{\code{permutations} a numeric value specifying the number of permutations +#' for significance testing in \code{vegan::anova.cca}. (By default: \code{permutations=999})} #' } #' #' @details @@ -120,6 +122,8 @@ #' # can be returned. #' tse <- addRDA( #' tse, data ~ SampleType, homogeneity.test = "anova", full = TRUE) +#' # Example showing how to pass extra parameters, such as 'permutations', to anova.cca +#' tse <- addRDA(tse, data ~ SampleType, permutations = 500) #' NULL diff --git a/man/mia-package.Rd b/man/mia-package.Rd index 3f8774038..36cd6fdbf 100644 --- a/man/mia-package.Rd +++ b/man/mia-package.Rd @@ -39,6 +39,19 @@ Other contributors: \item Muluh Muluh [contributor] \item Giulio Benedetti [contributor] \item Moritz Emanuel Beber \email{moritz.beber@igdore.org} (\href{https://orcid.org/0000-0003-2406-1978}{ORCID}) [contributor] + \item Nitesh Turaga [contributor] + \item Chouaib Benchraka [contributor] + \item Akewak Jeba [contributor] + \item Himmi Lindgren [contributor] + \item Noah De Gunst [contributor] + \item Théotime Pralas [contributor] + \item Shadman Ishraq [contributor] + \item Eineje Ameh [contributor] + \item Artur Sannikov [contributor] + \item Hervé Pagès [contributor] + \item Rajesh Shigdel [contributor] + \item Katariina Pärnänen [contributor] + \item Pande Erawijantari [contributor] } } diff --git a/man/runCCA.Rd b/man/runCCA.Rd index 965609e24..e91bb2ffd 100644 --- a/man/runCCA.Rd +++ b/man/runCCA.Rd @@ -85,7 +85,9 @@ summary tables are returned. (Default: \code{FALSE})} the significance test used to analyse \code{vegan::betadisper} results. Options include 'permanova' (\code{vegan::permutest}), 'anova' (\code{stats::anova}) and 'tukeyhsd' (\code{stats::TukeyHSD}). -(Default: \code{"permanova"})} +(By default: \code{homogeneity.test="permanova"})} +\item{\code{permutations} a numeric value specifying the number of permutations +for significance testing in \code{vegan::anova.cca}. (By default: \code{permutations=999})} }} \item{formula}{If \code{x} is a @@ -190,6 +192,8 @@ plotReducedDim(tse,"rda_scaled", colour_by = "SampleType") # can be returned. tse <- addRDA( tse, data ~ SampleType, homogeneity.test = "anova", full = TRUE) +# Example showing how to pass extra parameters, such as 'permutations', to anova.cca +tse <- addRDA(tse, data ~ SampleType, permutations = 500) } \seealso{