Skip to content

Commit

Permalink
Drop graph when only 1 cell is left in sample as the graph is meaning…
Browse files Browse the repository at this point in the history
…less, #58
  • Loading branch information
lambdamoses committed Nov 20, 2024
1 parent 65f5b8e commit be522f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ setMethod(
)
for (s in which(samples_subset)) {
j_sample <- old_sample_compare[[s]] %in% new_sample_colnames[[s]]
if (sum(j_sample) == 1) {
message("Only 1 column left in sample ", sample_ids[[s]],
", graphs are meaningless, dropping graphs.")
graphs_sub[[s]] <- list(row = NULL, col = NULL, annot = NULL)
next
}
for (m in seq_len(2)) { # Not subsetting annotGraphs
# Not sure what to do differently with rowGraphs yet
for (g in seq_along(graphs_sub[[s]][[m]])) {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ test_that("Subset the graph when distance-based edge weights are used", {
)
})

test_that("When only one cell/spot is left in a sample after subsetting", {
expect_message(sfe1 <- sfe_visium[,1:6], "graphs are meaningless, dropping graphs")
expect_null(colGraphNames(sfe1, sample_id = "sample02"))
})

test_that("When only one cell is left, option reconstruct", {
withr::local_options(SFE_graph_subset = FALSE)
expect_message(sfe1 <- sfe_visium[,1:6], "graphs are meaningless, dropping graphs")
expect_null(colGraphNames(sfe1, sample_id = "sample02"))
})

test_that("Warning message and dropping graphs when reconstruction info is unavailable", {
withr::local_options(SFE_graph_subset = FALSE)
# Remove one item from sample02
Expand Down

0 comments on commit be522f7

Please sign in to comment.