sccomp icon indicating copy to clipboard operation
sccomp copied to clipboard

Dplyr error "The LHS of `:=` must be a string, not a character vector." while executing sccomp_proportional_fold_change

Open pakiessling opened this issue 10 months ago • 6 comments

I am succesfully running sccomp on my SCE object.

My condition of interest is the column "diagnosis_CK" which has 4 levels.

sccomp_result <-
    obj |>
    sccomp_estimate(
        formula_composition = ~ Donor_Sex + Sample_Prep + diagnosis_CK,
        .sample = Donor,
        .cell_group = harmonized_cell_subtype,
        cores = 12,
        bimodal_mean_variability_association = TRUE
    ) |>
    sccomp_remove_outliers(cores = 12) |>
    sccomp_test()

I can plot this and everything looks reasonable.

When I try to calculate logfoldchanges between two of my four conditions I get an error:

sccomp_result |>
    sccomp_proportional_fold_change(
        formula_composition = ~ Donor_Sex + Sample_Prep + diagnosis_CK,
        from = "control",
        to = "DCM"
    )
Error message

Error in `FUN()`:
! The LHS of `:=` must be a string, not a character vector.
Traceback:

1. sccomp_proportional_fold_change.sccomp_tbl(sccomp_result, formula_composition = ~Donor_Sex + 
 .     Sample_Prep + diagnosis_CK, from = "control", to = "DCM")
2. select(mutate(mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease")), statement = glue("{round(abs(proportion_fold_change),1)}-fold {increase_decrease} (from {round(proportion_from, 4)} to {round(proportion_to, 4)})")), 
 .     !!attr(.data, ".cell_group"), proportion_fold_change, average_uncertainty, 
 .     statement)
3. mutate(mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease")), statement = glue("{round(abs(proportion_fold_change),1)}-fold {increase_decrease} (from {round(proportion_from, 4)} to {round(proportion_to, 4)})"))
4. mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease"))
5. mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2)
6. mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change)
7. mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . }))
8. mutate(mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean))
9. mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean)))
10. mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
  .     ".cell_group")), ratio_mean = map_dbl(data, ~{
  .     x = pull(arrange(.x, sample != !!from), proportion_mean)
  .     x[2]/x[1]
  . }))
11. nest(sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
  .     ".cell_group"))
12. sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor)))
13. sccomp_predict.sccomp_tbl(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor)))
14. replicate_data(fit, formula_composition = formula_composition, 
  .     formula_variability = ~1, new_data = new_data, number_of_draws = number_of_draws, 
  .     mcmc_seed = mcmc_seed)
15. rename(tibble(sample = as.character(c(to, from)), factor = c(to, 
  .     from)), `:=`(!!my_factor, factor))
16. rename.data.frame(tibble(sample = as.character(c(to, from)), 
  .     factor = c(to, from)), `:=`(!!my_factor, factor))
17. tidyselect::eval_rename(expr(c(...)), .data)
18. rename_impl(data, names(data), as_quosure(expr, env), strict = strict, 
  .     name_spec = name_spec, allow_predicates = allow_predicates, 
  .     error_call = error_call)
19. eval_select_impl(x, names, {
  .     {
  .         sel
  .     }
  . }, strict = strict, name_spec = name_spec, type = "rename", allow_predicates = allow_predicates, 
  .     error_call = error_call)
20. with_subscript_errors(out <- vars_select_eval(vars, expr, strict = strict, 
  .     data = x, name_spec = name_spec, uniquely_named = uniquely_named, 
  .     allow_rename = allow_rename, allow_empty = allow_empty, allow_predicates = allow_predicates, 
  .     type = type, error_call = error_call), type = type)
21. withCallingHandlers(expr, vctrs_error_subscript = function(cnd) {
  .     cnd$subscript_action <- subscript_action(type)
  .     cnd$subscript_elt <- "column"
  .     cnd_signal(cnd)
  . })
22. vars_select_eval(vars, expr, strict = strict, data = x, name_spec = name_spec, 
  .     uniquely_named = uniquely_named, allow_rename = allow_rename, 
  .     allow_empty = allow_empty, allow_predicates = allow_predicates, 
  .     type = type, error_call = error_call)
23. walk_data_tree(expr, data_mask, context_mask)
24. eval_c(expr, data_mask, context_mask)
25. call_expand_dots(expr, context_mask$.__current__.)
26. eval_bare(quote(enquos(...)), dots_mask)
27. enquos(...)
28. endots(call = sys.call(), frame_env = parent.frame(), capture_arg = ffi_enquo, 
  .     capture_dots = ffi_quos_interp, named = .named, ignore_empty = .ignore_empty, 
  .     ignore_null = .ignore_null, unquote_names = .unquote_names, 
  .     homonyms = .homonyms, check_assign = .check_assign)
29. map(syms, function(sym) {
  .     if (!is_symbol(sym)) {
  .         abort("Inputs to defuse must be argument names.", call = error_call)
  .     }
  .     if (identical(sym, dots_sym)) {
  .         unclass(dot_call(capture_dots, frame_env = frame_env, 
  .             named = named, ignore_empty = ignore_empty, unquote_names = unquote_names, 
  .             homonyms = homonyms, check_assign = check_assign))
  .     }
  .     else {
  .         list(dot_call(capture_arg, sym, frame_env))
  .     }
  . })
30. lapply(.x, .f, ...)
31. FUN(X[[i]], ...)
32. abort(message = message)
33. signal_abort(cnd, .file)
34. signalCondition(cnd)

Any Idea why? The included test data works fine for finding log fold changes.

Session Info

R version 4.3.3 (2024-02-29) Platform: x86_64-conda-linux-gnu (64-bit) Running under: Rocky Linux 8.10 (Green Obsidian)

Matrix products: default BLAS/LAPACK: /rwthfs/rz/cluster/hpcwork/p0020567/enviroments/sccomp/lib/libopenblasp-r0.3.29.so; LAPACK version 3.12.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: :/etc/localtime tzcode source: system (glibc)

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] dplyr_1.1.4 tibble_3.2.1 anndataR_0.99.0 sccomp_1.99.18

loaded via a namespace (and not attached): [1] tidyselect_1.2.1 IRdisplay_1.1
[3] farver_2.1.2 bitops_1.0-9
[5] fastmap_1.2.0 SingleCellExperiment_1.22.0 [7] RCurl_1.98-1.16 tensorA_0.36.2.1
[9] digest_0.6.37 lifecycle_1.0.4
[11] processx_3.8.6 magrittr_2.0.3
[13] posterior_1.6.1 compiler_4.3.3
[15] rlang_1.1.6 tools_4.3.3
[17] utf8_1.2.4 data.table_1.17.0
[19] S4Arrays_1.0.4 labeling_0.4.3
[21] bit_4.6.0 DelayedArray_0.26.6
[23] repr_1.1.7 RColorBrewer_1.1-3
[25] cmdstanr_0.9.0 abind_1.4-5
[27] pbdZMQ_0.3-14 withr_3.0.2
[29] purrr_1.0.4 BiocGenerics_0.46.0
[31] grid_4.3.3 stats4_4.3.3
[33] colorspace_2.1-1 ggplot2_3.5.2
[35] scales_1.3.0 SummarizedExperiment_1.30.2 [37] cli_3.6.4 crayon_1.5.3
[39] generics_0.1.3 tzdb_0.5.0
[41] stringr_1.5.1 zlibbioc_1.46.0
[43] parallel_4.3.3 XVector_0.40.0
[45] matrixStats_1.5.0 base64enc_0.1-3
[47] vctrs_0.6.5 Matrix_1.6-5
[49] jsonlite_2.0.0 callr_3.7.6
[51] IRanges_2.34.1 hms_1.1.3
[53] patchwork_1.3.0 S4Vectors_0.38.1
[55] bit64_4.6.0-1 ggrepel_0.9.6
[57] hdf5r_1.3.12 tidyr_1.3.1
[59] glue_1.8.0 ps_1.9.1
[61] distributional_0.5.0 stringi_1.8.7
[63] gtable_0.3.6 GenomeInfoDb_1.36.1
[65] GenomicRanges_1.52.0 munsell_0.5.1
[67] instantiate_0.2.3 pillar_1.10.2
[69] htmltools_0.5.8.1 IRkernel_1.3.2
[71] GenomeInfoDbData_1.2.11 R6_2.6.1
[73] evaluate_1.0.3 lattice_0.22-7
[75] Biobase_2.60.0 readr_2.1.5
[77] backports_1.5.0 Rcpp_1.0.14
[79] uuid_1.2-1 checkmate_2.3.2
[81] fs_1.6.6 MatrixGenerics_1.12.2
[83] forcats_1.0.0 pkgconfig_2.0.3

pakiessling avatar May 19 '25 13:05 pakiessling

Can you try

sccomp_result |>
    sccomp_proportional_fold_change(
        formula_composition = ~ diagnosis_CK,
        from = "control",
        to = "DCM"
    )

stemangiola avatar May 19 '25 14:05 stemangiola

Thank you for your reply.

Weirdly for this formula I get:

New error message
Error in .subset(new_data, !!.sample): sccomp says: some of the .column specified do not exist in the input data frame.
Traceback:

1. sccomp_proportional_fold_change.sccomp_tbl(sccomp_result, formula_composition = ~diagnosis_CK, 
 .     from = "control", to = "DCM")
2. select(mutate(mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease")), statement = glue("{round(abs(proportion_fold_change),1)}-fold {increase_decrease} (from {round(proportion_from, 4)} to {round(proportion_to, 4)})")), 
 .     !!attr(.data, ".cell_group"), proportion_fold_change, average_uncertainty, 
 .     statement)
3. mutate(mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease")), statement = glue("{round(abs(proportion_fold_change),1)}-fold {increase_decrease} (from {round(proportion_from, 4)} to {round(proportion_to, 4)})"))
4. mutate(mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2), increase_decrease = if_else(proportion_fold_change > 
 .     0, "increase", "decrease"))
5. mutate(mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change), 
 .     average_uncertainty = (abs(difference_proportion_upper_fold_change) + 
 .         abs(difference_proportion_lower_fold_change))/2)
6. mutate(mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, 
 .     formula_composition = formula_composition, new_data = rename(tibble(sample = as.character(c(to, 
 .         from)), factor = c(to, from)), `:=`(!!my_factor, factor))), 
 .     data = -!!attr(.data, ".cell_group")), ratio_mean = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_mean)
 .         x[2]/x[1]
 .     })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . })), difference_proportion_upper_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_upper), ratio_upper) - proportion_fold_change, 
 .     difference_proportion_lower_fold_change = if_else(ratio_mean < 
 .         1, (-1/ratio_lower), ratio_lower) - proportion_fold_change)
7. mutate(mutate(mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean)), ratio_upper = map_dbl(data, 
 .     ~{
 .         x = pull(arrange(.x, sample != !!from), proportion_upper)
 .         x[2]/x[1]
 .     }), ratio_lower = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_lower)
 .     x[2]/x[1]
 . }))
8. mutate(mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean))), proportion_fold_change = if_else(ratio_mean < 
 .     1, (-1/ratio_mean), ratio_mean))
9. mutate(mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
 .     new_data = rename(tibble(sample = as.character(c(to, from)), 
 .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
 .     ".cell_group")), ratio_mean = map_dbl(data, ~{
 .     x = pull(arrange(.x, sample != !!from), proportion_mean)
 .     x[2]/x[1]
 . })), proportion_from = map_dbl(data, ~pull(filter(.x, sample == 
 .     from), proportion_mean)), proportion_to = map_dbl(data, ~pull(filter(.x, 
 .     sample != from), proportion_mean)))
10. mutate(nest(sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
  .     ".cell_group")), ratio_mean = map_dbl(data, ~{
  .     x = pull(arrange(.x, sample != !!from), proportion_mean)
  .     x[2]/x[1]
  . }))
11. nest(sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor))), data = -!!attr(.data, 
  .     ".cell_group"))
12. sccomp_predict(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor)))
13. sccomp_predict.sccomp_tbl(.data, formula_composition = formula_composition, 
  .     new_data = rename(tibble(sample = as.character(c(to, from)), 
  .         factor = c(to, from)), `:=`(!!my_factor, factor)))
14. replicate_data(fit, formula_composition = formula_composition, 
  .     formula_variability = ~1, new_data = new_data, number_of_draws = number_of_draws, 
  .     mcmc_seed = mcmc_seed)
15. .subset(new_data, !!.sample)
16. stop("sccomp says: some of the .column specified do not exist in the input data frame.")
17. .handleSimpleError(function (cnd) 
  . {
  .     watcher$capture_plot_and_output()
  .     cnd <- sanitize_call(cnd)
  .     watcher$push(cnd)
  .     switch(on_error, continue = invokeRestart("eval_continue"), 
  .         stop = invokeRestart("eval_stop"), error = NULL)
  . }, "sccomp says: some of the .column specified do not exist in the input data frame.", 
  .     base::quote(.subset(new_data, !!.sample)))

This seems to indicate that control or DCM do not exist. But:

"control" %in% sccomp_result$count_data[[1]]$diagnosis_CK
> TRUE
"DCM" %in% sccomp_result$count_data[[1]]$diagnosis_CK
> TRUE

pakiessling avatar May 19 '25 15:05 pakiessling

have a look what the intercepts are (you can set intercept sorting the factors with fct_reorder). All non-intercept parameters are in the parameter column in the estimated object.

stemangiola avatar May 19 '25 16:05 stemangiola

DCM does not appear in unique(sccomp_result$parameter). I can get it to appear by doing obj$diagnosis_CK <- relevel(obj$diagnosis_CK, ref = "ICM") before the fit. Then I see:

unique(sccomp_result$parameter)
>'(Intercept)''Donor_SexM''Sample_PrepFFPE''diagnosis_CKDCM''diagnosis_CKICM_AMI''diagnosis_CKcontrol'

But I still get:

sccomp_result |>
    sccomp_proportional_fold_change(
        formula_composition = ~diagnosis_CK,
        from = "control",
        to = "DCM"
    )
>Error in .subset(new_data, !!.sample): sccomp says: some of the .column specified do not exist in the input data frame.

I don‘t get it :(

pakiessling avatar May 20 '25 09:05 pakiessling

Hello sorry for the delay. If you manage to send a count dataset, I can replicate your error, and I might manage to fix this possible bug.

stemangiola avatar Jun 23 '25 15:06 stemangiola

Hello is the error persisting when you update sccomp to the latest Github version?

If this is resolved, could you please close the issue?

stemangiola avatar Oct 09 '25 22:10 stemangiola