Skip to content

Commit 18310b1

Browse files
committed
- Added tests to ensure sccomp_boxplot can accept additional ggplot layers, improving flexibility for users.
- Updated vignettes to reflect changes in function usage and added examples for custom ggplot layers.
1 parent b9f6230 commit 18310b1

File tree

7 files changed

+112
-1118
lines changed

7 files changed

+112
-1118
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,3 @@ importFrom(tidyr,unnest)
154154
importFrom(tidyselect,all_of)
155155
importFrom(tidyselect,last_col)
156156
importFrom(utils,data)
157-
importFrom(utils,packageVersion)

R/sccomp_boxplot.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,23 @@ sccomp_boxplot = function(
7171
.data |>
7272

7373
# Otherwise does not work
74-
select(-`factor`) |>
74+
filter(factor == !!factor) |>
75+
select(-`factor`)
76+
77+
data_proportion =
78+
79+
data_proportion |>
7580

7681
pivot_wider(names_from = parameter, values_from = c(contains("c_"), contains("v_"))) |>
7782
left_join(
7883
attr(.data, "count_data") ,
7984
by = quo_name(.cell_group)
8085
) |>
8186
with_groups(!!.sample, ~ mutate(.x, proportion = (!!.count)/sum(!!.count)) ) |>
82-
mutate(is_zero = proportion==0)
87+
mutate(is_zero = proportion==0) |>
88+
89+
# Add columns for plotting expansion
90+
left_join(data_proportion |> select(cell_group, parameter, c_pH0, c_FDR, v_pH0, v_FDR))
8391

8492
if(remove_unwanted_effects){
8593
.data_adjusted =
@@ -236,7 +244,7 @@ plot_boxplot = function(
236244
with_groups(c(!!.cell_group, !!as.symbol(factor_of_interest)), ~ .x %>% summarise(name = paste(name, collapse = ", ")))
237245
}
238246

239-
my_boxplot = ggplot()
247+
my_boxplot = data_proportion |> ggplot()
240248

241249
if("fit" %in% names(attributes(.data))){
242250

R/simulate_data.R

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,33 @@
4545
#' S. Mangiola, A.J. Roth-Schulze, M. Trussart, E. Zozaya-Valdés, M. Ma, Z. Gao, A.F. Rubin, T.P. Speed, H. Shim, & A.T. Papenfuss, sccomp: Robust differential composition and variability analysis for single-cell data, Proc. Natl. Acad. Sci. U.S.A. 120 (33) e2203828120, https://doi.org/10.1073/pnas.2203828120 (2023).
4646
#'
4747
#' @export
48+
#' @noRd
49+
#' @keywords internal
4850
#'
4951
#' @examples
5052
#'
51-
#' print("cmdstanr is needed to run this example.")
53+
#' # print("cmdstanr is needed to run this example.")
5254
#' # Note: Before running the example, ensure that the 'cmdstanr' package is installed:
5355
#' # install.packages("cmdstanr", repos = c("https://stan-dev.r-universe.dev/", getOption("repos")))
5456
#'
55-
#' \donttest{
56-
#' if (instantiate::stan_cmdstan_exists()) {
57-
#' data("counts_obj")
58-
#' library(dplyr)
57+
#' # \donttest{
58+
#' # if (instantiate::stan_cmdstan_exists()) {
59+
#' # data("counts_obj")
60+
#' # library(dplyr)
5961
#'
60-
#' estimate = sccomp_estimate(
61-
#' counts_obj,
62-
#' ~ type, ~1, "sample", "cell_group", "count",
63-
#' cores = 1
64-
#' )
62+
#' # estimate = sccomp_estimate(
63+
#' # counts_obj,
64+
#' # ~ type, ~1, "sample", "cell_group", "count",
65+
#' # cores = 1
66+
#' # )
6567
#'
66-
#' # Set coefficients for cell_groups. In this case all coefficients are 0 for simplicity.
67-
#' counts_obj = counts_obj |> mutate(b_0 = 0, b_1 = 0)
68-
#'
69-
#' # Simulate data
70-
#' simulate_data(counts_obj, estimate, ~type, ~1, sample, cell_group, c(b_0, b_1))
71-
#' }
72-
#' }
68+
#' # # Set coefficients for cell_groups. In this case all coefficients are 0 for simplicity.
69+
#' # counts_obj = counts_obj |> mutate(b_0 = 0, b_1 = 0)
7370
#'
71+
#' # # Simulate data
72+
#' # simulate_data(counts_obj, estimate, ~type, ~1, sample, cell_group, c(b_0, b_1))
73+
#' # }
74+
#' # }
7475
simulate_data <- function(.data,
7576
.estimate_object,
7677
formula_composition,

man/simulate_data.Rd

Lines changed: 0 additions & 98 deletions
This file was deleted.

tests/testthat/test-plot.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library(dplyr)
22
library(tidyr)
33
library(sccomp)
4+
library(ggplot2)
45
data("seurat_obj")
56
data("sce_obj")
67
data("counts_obj")
@@ -325,4 +326,32 @@ test_that("plot_2D_intervals includes regression line from prec_coeff parameters
325326
show_fdr_message = FALSE
326327
)
327328
)
329+
})
330+
331+
test_that("sccomp_boxplot can accept additional ggplot layers", {
332+
skip_cmdstan()
333+
334+
# Test that we can add layers to the boxplot
335+
plot_with_label <- my_estimate |>
336+
sccomp_test() |>
337+
sccomp_boxplot("type", significance_threshold = 0.025) +
338+
geom_label(aes(label = c_FDR), x = 1, y = 0.5)
339+
340+
expect_s3_class(plot_with_label, "ggplot")
341+
342+
# Test with geom_text
343+
plot_with_text <- my_estimate |>
344+
sccomp_test() |>
345+
sccomp_boxplot("type", significance_threshold = 0.025) +
346+
geom_text(aes(label = c_FDR), x = 1, y = 0.3)
347+
348+
expect_s3_class(plot_with_text, "ggplot")
349+
350+
# Test with theme modifications
351+
plot_with_theme <- my_estimate |>
352+
sccomp_test() |>
353+
sccomp_boxplot("type", significance_threshold = 0.025) +
354+
theme(plot.title = element_text(color = "red"))
355+
356+
expect_s3_class(plot_with_theme, "ggplot")
328357
})

0 commit comments

Comments
 (0)