@@ -59,7 +59,6 @@ FindAllMarkers <- function(
59
59
latent.vars = NULL ,
60
60
min.cells.feature = 3 ,
61
61
min.cells.group = 3 ,
62
- pseudocount.use = 1 ,
63
62
mean.fxn = NULL ,
64
63
fc.name = NULL ,
65
64
base = 2 ,
@@ -136,7 +135,6 @@ FindAllMarkers <- function(
136
135
latent.vars = latent.vars ,
137
136
min.cells.feature = min.cells.feature ,
138
137
min.cells.group = min.cells.group ,
139
- pseudocount.use = pseudocount.use ,
140
138
mean.fxn = mean.fxn ,
141
139
fc.name = fc.name ,
142
140
base = base ,
@@ -512,6 +510,7 @@ FindMarkers.default <- function(
512
510
densify = FALSE ,
513
511
...
514
512
) {
513
+ pseudocount.use <- pseudocount.use %|| % 1
515
514
ValidateCellGroups(
516
515
object = object ,
517
516
cells.1 = cells.1 ,
@@ -603,6 +602,9 @@ FindMarkers.default <- function(
603
602
return (de.results )
604
603
}
605
604
605
+ # ' @param norm.method Normalization method for fold change calculation when
606
+ # ' \code{slot} is \dQuote{\code{data}}
607
+ # '
606
608
# ' @rdname FindMarkers
607
609
# ' @concept differential_expression
608
610
# ' @export
@@ -630,8 +632,10 @@ FindMarkers.Assay <- function(
630
632
fc.name = NULL ,
631
633
base = 2 ,
632
634
densify = FALSE ,
635
+ norm.method = NULL ,
633
636
...
634
637
) {
638
+ pseudocount.use <- pseudocount.use %|| % 1
635
639
data.slot <- ifelse(
636
640
test = test.use %in% DEmethods_counts(),
637
641
yes = ' counts' ,
@@ -652,7 +656,8 @@ FindMarkers.Assay <- function(
652
656
pseudocount.use = pseudocount.use ,
653
657
mean.fxn = mean.fxn ,
654
658
fc.name = fc.name ,
655
- base = base
659
+ base = base ,
660
+ norm.method = norm.method
656
661
)
657
662
de.results <- FindMarkers(
658
663
object = data.use ,
@@ -712,6 +717,7 @@ FindMarkers.SCTAssay <- function(
712
717
recorrect_umi = TRUE ,
713
718
...
714
719
) {
720
+ pseudocount.use <- pseudocount.use %|| % 1
715
721
data.slot <- ifelse(
716
722
test = test.use %in% DEmethods_counts(),
717
723
yes = ' counts' ,
@@ -813,6 +819,7 @@ FindMarkers.DimReduc <- function(
813
819
...
814
820
815
821
) {
822
+ pseudocount.use <- pseudocount.use %|| % 1
816
823
if (test.use %in% DEmethods_counts()) {
817
824
stop(" The following tests cannot be used for differential expression on a reduction as they assume a count model: " ,
818
825
paste(DEmethods_counts(), collapse = " , " ))
@@ -927,7 +934,6 @@ FindMarkers.Seurat <- function(
927
934
latent.vars = NULL ,
928
935
min.cells.feature = 3 ,
929
936
min.cells.group = 3 ,
930
- pseudocount.use = 1 ,
931
937
mean.fxn = NULL ,
932
938
fc.name = NULL ,
933
939
base = 2 ,
@@ -971,17 +977,14 @@ FindMarkers.Seurat <- function(
971
977
}
972
978
# check normalization method
973
979
norm.command <- paste0(" NormalizeData." , assay )
974
- if (norm.command %in% Command(object = object ) && is.null(x = reduction )) {
975
- norm.method <- Command(
980
+ norm.method <- if (norm.command %in% Command(object = object ) && is.null(x = reduction )) {
981
+ Command(
976
982
object = object ,
977
983
command = norm.command ,
978
984
value = " normalization.method"
979
985
)
980
- if (norm.method != " LogNormalize" ) {
981
- mean.fxn <- function (x ) {
982
- return (log(x = rowMeans(x = x ) + pseudocount.use , base = base ))
983
- }
984
- }
986
+ } else {
987
+ NULL
985
988
}
986
989
de.results <- FindMarkers(
987
990
object = data.use ,
@@ -1000,11 +1003,11 @@ FindMarkers.Seurat <- function(
1000
1003
latent.vars = latent.vars ,
1001
1004
min.cells.feature = min.cells.feature ,
1002
1005
min.cells.group = min.cells.group ,
1003
- pseudocount.use = pseudocount.use ,
1004
1006
mean.fxn = mean.fxn ,
1005
1007
base = base ,
1006
1008
fc.name = fc.name ,
1007
1009
densify = densify ,
1010
+ norm.method = norm.method ,
1008
1011
...
1009
1012
)
1010
1013
return (de.results )
@@ -1050,7 +1053,9 @@ FoldChange.default <- function(
1050
1053
return (fc.results )
1051
1054
}
1052
1055
1053
-
1056
+ # ' @param norm.method Normalization method for mean function selection
1057
+ # ' when \code{slot} is \dQuote{\code{data}}
1058
+ # '
1054
1059
# ' @importFrom Matrix rowMeans
1055
1060
# ' @rdname FoldChange
1056
1061
# ' @concept differential_expression
@@ -1066,18 +1071,25 @@ FoldChange.Assay <- function(
1066
1071
fc.name = NULL ,
1067
1072
mean.fxn = NULL ,
1068
1073
base = 2 ,
1074
+ norm.method = NULL ,
1069
1075
...
1070
1076
) {
1077
+ pseudocount.use <- pseudocount.use %|| % 1
1071
1078
data <- GetAssayData(object = object , slot = slot )
1079
+ default.mean.fxn <- function (x ) {
1080
+ return (log(x = rowMeans(x = x ) + pseudocount.use , base = base ))
1081
+ }
1072
1082
mean.fxn <- mean.fxn %|| % switch (
1073
1083
EXPR = slot ,
1074
- ' data' = function (x ) {
1075
- return (log(x = rowMeans(x = expm1(x = x )) + pseudocount.use , base = base ))
1076
- },
1084
+ ' data' = switch (
1085
+ EXPR = norm.method %|| % ' ' ,
1086
+ ' LogNormalize' = function (x ) {
1087
+ return (log(x = rowMeans(x = expm1(x = x )) + pseudocount.use , base = base ))
1088
+ },
1089
+ default.mean.fxn
1090
+ ),
1077
1091
' scale.data' = rowMeans ,
1078
- function (x ) {
1079
- return (log(x = rowMeans(x = x ) + pseudocount.use , base = base ))
1080
- }
1092
+ default.mean.fxn
1081
1093
)
1082
1094
# Omit the decimal value of e from the column name if base == exp(1)
1083
1095
base.text <- ifelse(
@@ -1111,11 +1123,12 @@ FoldChange.DimReduc <- function(
1111
1123
cells.2 ,
1112
1124
features = NULL ,
1113
1125
slot = NULL ,
1114
- pseudocount.use = NULL ,
1126
+ pseudocount.use = 1 ,
1115
1127
fc.name = NULL ,
1116
1128
mean.fxn = NULL ,
1117
1129
...
1118
1130
) {
1131
+ pseudocount.use <- pseudocount.use %|| % 1
1119
1132
mean.fxn <- mean.fxn %|| % rowMeans
1120
1133
fc.name <- fc.name %|| % " avg_diff"
1121
1134
data <- t(x = Embeddings(object = object ))
@@ -1143,7 +1156,7 @@ FoldChange.DimReduc <- function(
1143
1156
# ' @param assay Assay to use in fold change calculation
1144
1157
# ' @param slot Slot to pull data from
1145
1158
# ' @param pseudocount.use Pseudocount to add to averaged expression values when
1146
- # ' calculating logFC. 1 by default.
1159
+ # ' calculating logFC.
1147
1160
# ' @param mean.fxn Function to use for fold change or average difference calculation
1148
1161
# ' @param base The base with respect to which logarithms are computed.
1149
1162
# ' @param fc.name Name of the fold change, average difference, or custom function column
@@ -1163,7 +1176,7 @@ FoldChange.Seurat <- function(
1163
1176
slot = ' data' ,
1164
1177
reduction = NULL ,
1165
1178
features = NULL ,
1166
- pseudocount.use = 1 ,
1179
+ pseudocount.use = NULL ,
1167
1180
mean.fxn = NULL ,
1168
1181
base = 2 ,
1169
1182
fc.name = NULL ,
0 commit comments