Skip to content

Commit

Permalink
Merge pull request #650 from satijalab/feat/foldchange
Browse files Browse the repository at this point in the history
Tweaks for pseudocount.use and normalization methods for FindMarkers and FoldChange
  • Loading branch information
AustinHartman authored Sep 21, 2022
2 parents 144421c + 731ec7c commit 38af263
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Collate:
'tree.R'
'utilities.R'
'zzz.R'
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
Encoding: UTF-8
Suggests:
ape,
Expand Down
45 changes: 26 additions & 19 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ FindAllMarkers <- function(
latent.vars = NULL,
min.cells.feature = 3,
min.cells.group = 3,
pseudocount.use = NULL,
mean.fxn = NULL,
fc.name = NULL,
base = 2,
Expand Down Expand Up @@ -136,7 +135,6 @@ FindAllMarkers <- function(
latent.vars = latent.vars,
min.cells.feature = min.cells.feature,
min.cells.group = min.cells.group,
pseudocount.use = pseudocount.use,
mean.fxn = mean.fxn,
fc.name = fc.name,
base = base,
Expand Down Expand Up @@ -604,6 +602,9 @@ FindMarkers.default <- function(
return(de.results)
}

#' @param norm.method Normalization method for fold change calculation when
#' \code{slot} is \dQuote{\code{data}}
#'
#' @rdname FindMarkers
#' @concept differential_expression
#' @export
Expand Down Expand Up @@ -631,6 +632,7 @@ FindMarkers.Assay <- function(
fc.name = NULL,
base = 2,
densify = FALSE,
norm.method = NULL,
...
) {
pseudocount.use <- pseudocount.use %||% 1
Expand All @@ -654,7 +656,8 @@ FindMarkers.Assay <- function(
pseudocount.use = pseudocount.use,
mean.fxn = mean.fxn,
fc.name = fc.name,
base = base
base = base,
norm.method = norm.method
)
de.results <- FindMarkers(
object = data.use,
Expand Down Expand Up @@ -931,7 +934,6 @@ FindMarkers.Seurat <- function(
latent.vars = NULL,
min.cells.feature = 3,
min.cells.group = 3,
pseudocount.use = NULL,
mean.fxn = NULL,
fc.name = NULL,
base = 2,
Expand Down Expand Up @@ -975,17 +977,14 @@ FindMarkers.Seurat <- function(
}
# check normalization method
norm.command <- paste0("NormalizeData.", assay)
if (norm.command %in% Command(object = object) && is.null(x = reduction)) {
norm.method <- Command(
norm.method <- if (norm.command %in% Command(object = object) && is.null(x = reduction)) {
Command(
object = object,
command = norm.command,
value = "normalization.method"
)
if (norm.method != "LogNormalize") {
mean.fxn <- function(x) {
return(log(x = rowMeans(x = x) + pseudocount.use, base = base))
}
}
} else {
NULL
}
de.results <- FindMarkers(
object = data.use,
Expand All @@ -1004,11 +1003,11 @@ FindMarkers.Seurat <- function(
latent.vars = latent.vars,
min.cells.feature = min.cells.feature,
min.cells.group = min.cells.group,
pseudocount.use = pseudocount.use,
mean.fxn = mean.fxn,
base = base,
fc.name = fc.name,
densify = densify,
norm.method = norm.method,
...
)
return(de.results)
Expand Down Expand Up @@ -1054,7 +1053,9 @@ FoldChange.default <- function(
return(fc.results)
}


#' @param norm.method Normalization method for mean function selection
#' when \code{slot} is \dQuote{\code{data}}
#'
#' @importFrom Matrix rowMeans
#' @rdname FoldChange
#' @concept differential_expression
Expand All @@ -1070,19 +1071,25 @@ FoldChange.Assay <- function(
fc.name = NULL,
mean.fxn = NULL,
base = 2,
norm.method = NULL,
...
) {
pseudocount.use <- pseudocount.use %||% 1
data <- GetAssayData(object = object, slot = slot)
default.mean.fxn <- function(x) {
return(log(x = rowMeans(x = x) + pseudocount.use, base = base))
}
mean.fxn <- mean.fxn %||% switch(
EXPR = slot,
'data' = function(x) {
return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base))
},
'data' = switch(
EXPR = norm.method %||% '',
'LogNormalize' = function(x) {
return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base))
},
default.mean.fxn
),
'scale.data' = rowMeans,
function(x) {
return(log(x = rowMeans(x = x) + pseudocount.use, base = base))
}
default.mean.fxn
)
# Omit the decimal value of e from the column name if base == exp(1)
base.text <- ifelse(
Expand Down
8 changes: 6 additions & 2 deletions man/FeaturePlot.Rd

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

4 changes: 0 additions & 4 deletions man/FindAllMarkers.Rd

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

5 changes: 4 additions & 1 deletion man/FindMarkers.Rd

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

4 changes: 4 additions & 0 deletions man/FoldChange.Rd

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

6 changes: 4 additions & 2 deletions man/IntegrateData.Rd

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

6 changes: 4 additions & 2 deletions man/IntegrateEmbeddings.Rd

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

5 changes: 1 addition & 4 deletions man/PolyFeaturePlot.Rd

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

2 changes: 1 addition & 1 deletion man/Seurat-package.Rd

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

2 changes: 1 addition & 1 deletion man/reexports.Rd

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

Loading

0 comments on commit 38af263

Please sign in to comment.