From 694f19827c7709ece5b54b81c715cc2bfc2d006e Mon Sep 17 00:00:00 2001 From: lepriolc Date: Mon, 3 Apr 2023 18:07:02 +0200 Subject: [PATCH] Fix mean.fxn setting in FindMarkers.SCTAssay function --- R/differential_expression.R | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/R/differential_expression.R b/R/differential_expression.R index c96e3fea4..c0ec5973f 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -752,12 +752,17 @@ FindMarkers.SCTAssay <- function( 'scale.data' = GetAssayData(object = object, slot = "counts"), numeric() ) - if (is.null(x = mean.fxn)){ - mean.fxn <- function(x) { - return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base)) - - } + default.mean.fxn <- function(x) { + return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base)) } + mean.fxn <- mean.fxn %||% switch( + EXPR = slot, + 'counts' = function(x) { + return(log(x = rowMeans(x = x) + pseudocount.use, base = base)) + }, + 'scale.data' = rowMeans, + default.mean.fxn + ) fc.results <- FoldChange( object = object, slot = data.slot,