Skip to content

Commit

Permalink
add informative error message for strictly-negative values in rarefyA…
Browse files Browse the repository at this point in the history
…ssay (microbiome#563)
  • Loading branch information
thpralas authored Jun 5, 2024
1 parent 9198263 commit 5ed79ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mia
Type: Package
Version: 1.13.19
Version: 1.13.20
Authors@R:
c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
email = "felix.gm.ernst@outlook.com",
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ Changes in version 1.13.x
+ Fix bug in mergeFeaturesByPrevalence
+ new aliases calculateDPCoA to getDPCoA, calculateNMDS to getNMDS, calculateRDA to getRDA,
calculateCCA to getCCA
+ add informative error message in rarefyAssay on assays with strictly-negative values
24 changes: 15 additions & 9 deletions R/rarefyAssay.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,47 @@ setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"),
.check_assay_present(assay.type, x)
if(any(assay(x, assay.type) %% 1 != 0)){
warning("assay contains non-integer values. Only counts table ",
"is applicable...")
"is applicable...", call. = FALSE)
}
if(any(assay(x, assay.type) < 0)){
stop("assay contains strictly-negative values. Only counts ",
"table is applicable...", call. = FALSE)
}
if(!is.logical(verbose)){
stop("`verbose` has to be logical i.e. TRUE or FALSE")
stop("`verbose` has to be logical i.e. TRUE or FALSE",
call. = FALSE)
}

if(!is.logical(replace)){
stop("`replace` has to be logical i.e. TRUE or FALSE")
stop("`replace` has to be logical i.e. TRUE or FALSE",
call. = FALSE)
}
# Check name
if(!.is_non_empty_string(name) ||
name == assay.type){
stop("'name' must be a non-empty single character value and be ",
"different from `assay.type`.",
call. = FALSE)
"different from `assay.type`.",
call. = FALSE)
}
#set.seed(seed)
# Make sure min_size is of length 1.
if(length(min_size) > 1){
stop("`min_size` had more than one value. ",
"Specifiy a single integer value.")
"Specify a single integer value.", call. = FALSE)
min_size <- min_size[1]
}
if(!is.numeric(min_size) ||
as.integer(min_size) != min_size && min_size <= 0){
stop("min_size needs to be a positive integer value.")
stop("min_size needs to be a positive integer value.",
call. = FALSE)
}
# get samples with less than min number of reads
if(min(colSums2(assay(x, assay.type))) < min_size){
rmsams <- colnames(x)[colSums2(assay(x, assay.type)) < min_size]
# Return NULL, if no samples were found after subsampling
if( !any(!colnames(x) %in% rmsams) ){
stop("No samples were found after subsampling.",
call. = FALSE)
call. = FALSE)
}
if(verbose){
message(length(rmsams), " samples removed ",
Expand Down Expand Up @@ -168,7 +175,6 @@ setMethod("rarefyAssay", signature = c(x = "SummarizedExperiment"),
}
)


## Modified Sub sampling function from phyloseq internals
.subsample_assay <- function(x, min_size, replace){
# Create replacement species vector
Expand Down

0 comments on commit 5ed79ef

Please sign in to comment.