Skip to content

Commit

Permalink
microbiome#601 and OMA issue #482 (microbiome#602)
Browse files Browse the repository at this point in the history
Co-authored-by: Tuomas Borman <[email protected]>
Co-authored-by: Leo Lahti <[email protected]>
  • Loading branch information
3 people authored Jul 30, 2024
1 parent 056ad48 commit b75207a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
15 changes: 14 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ Authors@R:
person(given = "Giulio", family = "Benedetti", role=c("ctb")),
person(given = c("Moritz", "Emanuel"), family = "Beber",
email = "[email protected]", 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
Expand Down
23 changes: 20 additions & 3 deletions R/addAlpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ){
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 5 additions & 1 deletion R/runCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions man/mia-package.Rd

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

6 changes: 5 additions & 1 deletion man/runCCA.Rd

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

0 comments on commit b75207a

Please sign in to comment.