Skip to content

Commit e2209e2

Browse files
authored
Merge pull request #189 from MangiolaLaboratory/pass_fit_method_across_steps
track fit method in the attributes
2 parents 505abc2 + d7893fa commit e2209e2

6 files changed

+42
-11
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: sccomp
22
Title: Tests differences in cell-type proportion for single-cell data, robust to outliers
3-
Version: 1.99.15
3+
Version: 1.99.16
44
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
55
role = c("aut", "cre"))
66
)

R/functions_multi_beta_binomial.R

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ sccomp_glm_data_frame_counts = function(.data,
329329
add_attr(formula_composition |> drop_environment(), "formula_composition") |>
330330
add_attr(formula_variability |> drop_environment(), "formula_variability") |>
331331
add_attr(parse_formula(formula_composition), "factors" ) |>
332+
add_attr(inference_method, "inference_method" ) |>
332333

333334
# Add class to the tbl
334335
add_class("sccomp_tbl") |>

R/methods.R

+7-4
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ sccomp_estimate.data.frame <- function(.data,
609609
sccomp_remove_outliers <- function(.estimate,
610610
percent_false_positive = 5,
611611
cores = detectCores(),
612-
inference_method = "pathfinder",
612+
inference_method = .estimate |> attr("inference_method"),
613613
output_directory = "sccomp_draws_files",
614614
verbose = TRUE,
615615
mcmc_seed = sample(1e5, 1),
@@ -639,7 +639,7 @@ sccomp_remove_outliers <- function(.estimate,
639639
sccomp_remove_outliers.sccomp_tbl = function(.estimate,
640640
percent_false_positive = 5,
641641
cores = detectCores(),
642-
inference_method = "pathfinder",
642+
inference_method = .estimate |> attr("inference_method"),
643643
output_directory = "sccomp_draws_files",
644644
verbose = TRUE,
645645
mcmc_seed = sample(1e5, 1),
@@ -959,6 +959,7 @@ sccomp_remove_outliers.sccomp_tbl = function(.estimate,
959959
add_attr(formula_composition, "formula_composition") |>
960960
add_attr(formula_variability, "formula_variability") |>
961961
add_attr(parse_formula(formula_composition), "factors" ) |>
962+
add_attr(inference_method, "inference_method" ) |>
962963

963964
# Add class to the tbl
964965
add_class("sccomp_tbl") |>
@@ -1057,7 +1058,8 @@ sccomp_test.sccomp_tbl = function(.data,
10571058
.count = .data |> attr(".count")
10581059
model_input = .data |> attr("model_input")
10591060
truncation_df2 = .data |> attr("truncation_df2")
1060-
1061+
inference_method = .data |> attr("inference_method")
1062+
10611063
# Abundance
10621064
abundance_CI =
10631065
get_abundance_contrast_draws(.data, contrasts)
@@ -1164,7 +1166,8 @@ sccomp_test.sccomp_tbl = function(.data,
11641166

11651167
add_attr(.data |> attr("formula_composition"), "formula_composition") |>
11661168
add_attr(.data |> attr("formula_variability"), "formula_variability") |>
1167-
1169+
add_attr(inference_method, "inference_method" ) |>
1170+
11681171
# Add class to the tbl
11691172
add_class("sccomp_tbl")
11701173
}

R/utilities.R

+27-3
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ get_FDR = function(x){
18201820
#' This function creates a series of 1D interval plots for cell-group effects, highlighting significant differences based on a given significance threshold.
18211821
#'
18221822
#' @param .data Data frame containing the main data.
1823-
#' @param significance_threshold Numeric value specifying the significance threshold for highlighting differences. Default is 0.025.
1823+
#' @param significance_threshold Numeric value specifying the significance threshold for highlighting differences.
18241824
#' @param test_composition_above_logit_fold_change A positive integer. It is the effect threshold used for the hypothesis test. A value of 0.2 correspond to a change in cell proportion of 10% for a cell type with baseline proportion of 50%. That is, a cell type goes from 45% to 50%. When the baseline proportion is closer to 0 or 1 this effect thrshold has consistent value in the logit uncontrained scale.
18251825
#' @importFrom patchwork wrap_plots
18261826
#' @importFrom forcats fct_reorder
@@ -1830,10 +1830,34 @@ get_FDR = function(x){
18301830
#'
18311831
#' @return A combined plot of 1D interval plots.
18321832
#' @examples
1833-
#' # Example usage:
1834-
#' # plot_1D_intervals(.data, "cell_group", 0.025, theme_minimal())
1833+
#'
1834+
#' \donttest{
1835+
#' if (instantiate::stan_cmdstan_exists()) {
1836+
#' data("counts_obj")
1837+
#'
1838+
#' estimate <- sccomp_estimate(
1839+
#' counts_obj,
1840+
#' ~ type,
1841+
#' ~1,
1842+
#' sample,
1843+
#' cell_group,
1844+
#' count,
1845+
#' cores = 1
1846+
#' ) |>
1847+
#' sccomp_test()
1848+
#'
1849+
#' # Example usage:
1850+
#' my_plot = plot_1D_intervals(estimate)
1851+
#'
1852+
#' }
1853+
#' }
1854+
#'
1855+
#'
1856+
18351857
plot_1D_intervals = function(.data, significance_threshold = 0.05, test_composition_above_logit_fold_change = .data |> attr("test_composition_above_logit_fold_change")){
18361858

1859+
message("sccomp says: Some FDR-significant populations may cross the fold change threshold. \n This because, as sccomp is a Bayesian method, the FDR is calculated according to Stephens (doi: 10.1093/biostatistics/kxw041), \n by sorting the probability of the null hypothesis in ascending order and calculating the cumulative average.")
1860+
18371861
# Define the variables as NULL to avoid CRAN NOTES
18381862
parameter <- NULL
18391863
estimate <- NULL

man/sccomp_remove_outliers.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-sccomp_.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ test_that("LOO", {
836836
.sample = sample,
837837
.cell_group = cell_group,
838838
inference_method = "hmc",
839+
cores = 1,
839840
enable_loo = TRUE
840841
) |>
841842
expect_no_error()
@@ -848,6 +849,7 @@ test_that("LOO", {
848849
.sample = sample,
849850
.cell_group = cell_group,
850851
inference_method = "hmc",
852+
cores = 1,
851853
enable_loo = TRUE
852854
) |>
853855
expect_no_error()
@@ -872,9 +874,10 @@ test_that("use two methods", {
872874
formula_composition = ~ 1,
873875
.sample = sample,
874876
.cell_group = cell_group,
875-
inference_method = "hmc"
877+
inference_method = "hmc",
878+
cores = 1
876879
) |>
877-
sccomp_remove_outliers(inference_method = "pathfinder") |>
880+
sccomp_remove_outliers(inference_method = "pathfinder", cores = 1) |>
878881
expect_no_error()
879882

880883
})

0 commit comments

Comments
 (0)