Skip to content

Commit

Permalink
Added switch to sequential processing when cl = 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ludvigla committed Aug 15, 2024
1 parent d6e89ae commit 8190d34
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
13 changes: 7 additions & 6 deletions R/differential_colocalization_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ RunDCA.data.frame <- function(
# Use sequential processing when cl is 1
if (cl == 1) {
chunks <- seq_along(test_groups)
}
# Parallel processing when cl is the number of child processes
if ((length(test_groups) * cl) > (cl * 100)) {
# Cut into even chunks of 100 values in each chunk
chunks <- ceiling(seq_along(test_groups) / 100)
} else {
chunks <- cut(seq_along(test_groups), cl)
# Parallel processing when cl is the number of child processes
if ((length(test_groups) * cl) > (cl * 100)) {
# Cut into even chunks of 100 values in each chunk
chunks <- ceiling(seq_along(test_groups) / 100)
} else {
chunks <- cut(seq_along(test_groups), cl)
}
}
} else {
# Sequential processing when cl is NULL
Expand Down
5 changes: 3 additions & 2 deletions R/differential_polarity_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ RunDPA.data.frame <- function(
# Use sequential processing when cl is 1
if (cl == 1) {
chunks <- seq_along(test_groups)
} else {
# Parallel processing when cl is the number of child processes
chunks <- cut(seq_along(test_groups), cl)
}
# Parallel processing when cl is the number of child processes
chunks <- cut(seq_along(test_groups), cl)
} else {
# Sequential processing when cl is NULL
chunks <- seq_along(test_groups)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-RunDCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ seur_merged <- merge(seur1, seur2, add.cell.ids = c("Sample1", "Sample2"))
seur_merged <- subset(seur_merged, features = c("ACTB", "HLA-ABC"))

test_that("RunDCA works as expected on a data.frame and that ColocalizationHeatmap works on the output", {

expect_no_error(suppressWarnings(dca_markers <- RunDCA(colocalization_table_merged,
contrast_column = "sample",
targets = "Sample1", reference = "Sample2"
Expand Down Expand Up @@ -63,6 +64,13 @@ test_that("RunDCA works as expected on a data.frame and that ColocalizationHeatm

expect_equal(dca_markers[1:2, ], expected_result)

# cl = 1 should witch to sequential processing
expect_no_error(suppressWarnings(dca_markers <- RunDCA(colocalization_table_merged,
contrast_column = "sample",
targets = "Sample1", reference = "Sample2",
cl = 1
)))

# Colocalization heatmap
expect_no_error(p_heatmap <- ColocalizationHeatmap(dca_markers))
expect_s3_class(p_heatmap, "pheatmap")
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-RunDPA.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ seur2$sample <- "Sample2"
seur_merged <- merge(seur1, seur2, add.cell.ids = c("Sample1", "Sample2"))

test_that("RunDPA works as expected on a data.frame", {

# morans_z
expect_no_error(suppressWarnings(dpa_markers <- RunDPA(polarization_table_merged,
contrast_column = "sample",
Expand Down Expand Up @@ -115,6 +116,14 @@ test_that("RunDPA works as expected on a data.frame", {

# Automatic selection of targets
expect_no_error(suppressWarnings(dpa_markers <- RunDPA(seur_merged, contrast_column = "sample", reference = "Sample2")))

# cl = 1 should witch to sequential processing
expect_no_error(suppressWarnings(dpa_markers <- RunDPA(seur_merged,
contrast_column = "sample",
targets = "Sample1", reference = "Sample2",
cl = 1
)))

})

test_that("RunDPA works as expected on a Seurat object", {
Expand Down

0 comments on commit 8190d34

Please sign in to comment.