Skip to content

Commit 2d17ea2

Browse files
committed
Fix a bug where Z-score-based combination of continuous features was computed incorrectly (but seemed to only have subtle differences from the correct value in most cases)
1 parent 27db42d commit 2d17ea2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

R/multi_gene_z_score.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ multi_gene_z_score <- function(cont_mat) {
3232
cont_mat <- cont_mat[, good_indices, drop = FALSE]
3333

3434
# For each spot, average Z-scores across all features
35-
cont_z <- (cont_mat - colMeans(cont_mat, na.rm = TRUE)) /
36-
colSds(cont_mat, na.rm = TRUE)
35+
cont_z <- (cont_mat - rep(colMeans(cont_mat, na.rm = TRUE), each = nrow(cont_mat))) /
36+
rep(colSds(cont_mat, na.rm = TRUE), each = nrow(cont_mat))
3737
z_vec <- rowMeans(cont_z, na.rm = TRUE)
3838

3939
return(z_vec)

tests/testthat/test-multi_gene_z_score.R

+4
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ test_that(
4040
multi_gene_z_score(cont_mat),
4141
"^After dropping features with no expression variation"
4242
)
43+
44+
# Now actually verify the Z-score-based calculation is correct
45+
cont_mat = matrix(c(1, 2, 3, -3, 0, 3, 7.5, 9, 10.5), nrow = 3)
46+
expect_equal(multi_gene_z_score(cont_mat), c(-1, 0, 1))
4347
}
4448
)

0 commit comments

Comments
 (0)