From 589c36b57de8e47acf218745393bbfe129216d18 Mon Sep 17 00:00:00 2001 From: LTLA Date: Tue, 7 Jan 2025 10:25:25 -0800 Subject: [PATCH] Minor clean-up to the marker testing code. --- tests/testthat/test-train.R | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-train.R b/tests/testthat/test-train.R index 477b0a0..52dab3e 100644 --- a/tests/testthat/test-train.R +++ b/tests/testthat/test-train.R @@ -68,21 +68,27 @@ test_that("trainSingleR works correctly for other DE testing methods", { effects <- scrapper::scoreMarkers(logcounts(training), training$label, all.pairwise=TRUE) VERIFY <- function(ref.markers, effect.sizes, hard.limit, extra) { - expect_identical(sort(names(ref.markers)), sort(unique(training$label))) + sulabels <- sort(unique(training$label)) + expect_identical(sort(names(ref.markers)), sulabels) for (n in names(ref.markers)) { current.markers <- ref.markers[[n]] - expect_identical(sort(names(current.markers)), sort(unique(training$label))) - expect_identical(current.markers[[n]], character(0)) - - for (n2 in setdiff(names(current.markers), n)) { - my.effects <- effect.sizes[n2, n,] - is.chosen <- rownames(training) %in% current.markers[[n2]] - expect_gte(min(my.effects[is.chosen]), max(my.effects[!is.chosen])) - expect_gt(min(my.effects[is.chosen]), hard.limit) - - if (!is.null(extra)) { - extra(n, n2, current.markers[[n2]]) + expect_identical(sort(names(current.markers)), sulabels) + + for (n2 in names(current.markers)) { + my.markers <- current.markers[[n2]] + if (n == n2) { + expect_identical(length(my.markers), 0L) + } else { + expect_gt(length(my.markers), 0L) + my.effects <- effect.sizes[n2, n,] + is.chosen <- rownames(training) %in% current.markers[[n2]] + min.chosen <- min(my.effects[is.chosen]) + expect_gte(min.chosen, max(my.effects[!is.chosen])) + expect_gt(min.chosen, hard.limit) + if (!is.null(extra)) { + extra(n, n2, my.markers) + } } } }