Skip to content

Commit

Permalink
Update pseudocount (microbiome#571)
Browse files Browse the repository at this point in the history
Signed-off-by: Daena Rys <[email protected]>
  • Loading branch information
Daenarys8 authored Jun 6, 2024
1 parent 5ed79ef commit bca93ac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions R/transformCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,11 @@ setMethod("transformAssay", signature = c(x = "SummarizedExperiment"),
stop("The assay contains missing or negative values. ",
"'pseudocount' must be specified manually.", call. = FALSE)
}
# If pseudocount TRUE, set it to non-zero minimum value, else set it to zero
pseudocount <- ifelse(pseudocount, min(mat[mat>0]), 0)
# If pseudocount TRUE, set it to half of non-zero minimum value, else set
# it to zero.
# Get min value
value <- min(mat[mat>0])
pseudocount <- ifelse(pseudocount, value / 2, 0)
# Report pseudocount if positive value
if ( pseudocount > 0 ){
message("A pseudocount of ", pseudocount, " was applied.")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-5transformCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ test_that("transformAssay", {
tse <- transformAssay(tse, method = "relabundance", pseudocount = TRUE, name = "pseudo_true")
tse <- transformAssay(
tse, method = "relabundance", name = "pseudo_min",
pseudocount = min(assay(tse, "counts")[assay(tse, "counts") > 0]),
pseudocount = (min(assay(tse, "counts")[assay(tse, "counts") > 0])) / 2,
)
tse <- transformAssay(tse, method = "relabundance", pseudocount = FALSE, name = "pseudo_false")
tse <- transformAssay(tse, method = "relabundance", pseudocount = 0, name = "pseudo_zero")
Expand Down

0 comments on commit bca93ac

Please sign in to comment.