Skip to content

Commit 299ea19

Browse files
committed
merge
Merge branch 'master' into github-pages-for-cmdstanr # Conflicts: # DESCRIPTION
2 parents 9ed3f7f + 19a5182 commit 299ea19

22 files changed

+613
-229
lines changed

Diff for: .Rbuildignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ src/Rcpp*
1818
^README*
1919
^dev
2020
^rsconnect
21+
# DO NOT ADD ANY INST FILES HERE AS THE INST DIRECTORY WILL NOT BE INSTALLED
2122
model_glm_dirichlet_multinomial.rds
2223
model_glm_dirichlet_multinomial_generate_quantities.rds
2324
model_glm_dirichlet_multinomial_imputation.rds
24-
inst/stan/glm_multi_beta_binomial
25-
inst/stan/glm_multi_beta_binomial_generate_data
2625
^doc$
2726
^Meta$
2827
sccomp_draws_files

Diff for: DESCRIPTION

+3-2
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.9
3+
Version: 1.99.14
44
Authors@R: c(person("Stefano", "Mangiola", email = "[email protected]",
55
role = c("aut", "cre"))
66
)
@@ -34,7 +34,8 @@ Imports:
3434
readr,
3535
scales,
3636
stringr,
37-
glue
37+
glue,
38+
crayon
3839
Suggests:
3940
knitr,
4041
rmarkdown,

Diff for: NAMESPACE

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ import(dplyr)
3434
import(ggplot2)
3535
importFrom(SingleCellExperiment,colData)
3636
importFrom(SingleCellExperiment,counts)
37+
importFrom(crayon,red)
38+
importFrom(dplyr,add_count)
3739
importFrom(dplyr,any_of)
3840
importFrom(dplyr,arrange)
3941
importFrom(dplyr,as_tibble)
42+
importFrom(dplyr,count)
4043
importFrom(dplyr,cummean)
4144
importFrom(dplyr,distinct)
4245
importFrom(dplyr,distinct_at)
@@ -97,6 +100,7 @@ importFrom(readr,read_file)
97100
importFrom(readr,type_convert)
98101
importFrom(readr,write_file)
99102
importFrom(rlang,":=")
103+
importFrom(rlang,abort)
100104
importFrom(rlang,check_installed)
101105
importFrom(rlang,enquo)
102106
importFrom(rlang,ensym)
@@ -140,4 +144,3 @@ importFrom(tidyselect,all_of)
140144
importFrom(tidyselect,eval_select)
141145
importFrom(tidyselect,last_col)
142146
importFrom(utils,data)
143-
importFrom(utils,menu)

Diff for: R/functions_multi_beta_binomial.R

+10-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,16 @@ sccomp_glm_data_frame_counts = function(.data,
139139
.sample_cell_group_pairs_to_exclude = enquo(.sample_cell_group_pairs_to_exclude)
140140
#.grouping_for_random_effect = enquo(.grouping_for_random_effect)
141141

142+
# Check Sample Consistency of Factors
143+
check_sample_consistency_of_factors(.data, formula_composition, !!.sample, !!.cell_group)
142144

143145
#Check column class
144146
check_if_columns_right_class(.data, !!.sample, !!.cell_group)
145147

146148
# Check that count is integer
147149
if(.data %>% pull(!!.count) %>% is("integer")) message(sprintf("sccomp says: %s column is an integer. The sum-constrained beta binomial model will be used", quo_name(.count)))
148150
else if(.data %>% pull(!!.count) %>% is("integer") |> not() & .data %>% pull(!!.count) |> dplyr::between(0, 1) |> all()) message(sprintf("sccomp says: %s column is a proportion. The sum-constrained beta model will be used. When possible using counts is preferred as the binomial noise component is often dominating for rare groups (e.g. rare cell types).", quo_name(.count)))
149-
else stop(sprintf("sccomp: %s column must be an integer or a proportion", quo_name(.count)))
151+
else stop(sprintf("sccomp: `%s` column must be an integer or a proportion", quo_name(.count)))
150152

151153
# Check if columns exist
152154
check_columns_exist(.data, c(
@@ -240,7 +242,13 @@ sccomp_glm_data_frame_counts = function(.data,
240242

241243
data_for_model =
242244
.data %>%
243-
data_to_spread ( formula_composition, !!.sample, !!.cell_group, !!.count, .grouping_for_random_effect) %>%
245+
data_to_spread ( formula_composition, !!.sample, !!.cell_group, !!.count, .grouping_for_random_effect) |>
246+
247+
# This emerged with
248+
# https://github.com/MangiolaLaboratory/sccomp/issues/175#issuecomment-2622749180
249+
check_if_sample_is_a_unique_identifier(!!.sample) |>
250+
251+
# Create input for Stan
244252
data_spread_to_model_input(
245253
formula_composition, !!.sample, !!.cell_group, !!.count,
246254
truncation_ajustment = 1.1,

Diff for: R/methods.R

+6-9
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ sccomp_estimate.data.frame <- function(.data,
463463
.abundance <- .count
464464
}
465465

466-
467466
# DEPRECATION OF approximate_posterior_inference
468467
if (lifecycle::is_present(approximate_posterior_inference) & !is.null(approximate_posterior_inference)) {
469468
lifecycle::deprecate_warn("1.7.7", "sccomp::sccomp_estimate(approximate_posterior_inference = )", details = "The argument approximate_posterior_inference is now deprecated. Please use inference_method. By default, inference_method value is inferred from approximate_posterior_inference.")
@@ -1878,7 +1877,8 @@ sccomp_boxplot = function(
18781877

18791878
pivot_wider(names_from = parameter, values_from = c(contains("c_"), contains("v_"))) |>
18801879
unnest(count_data) |>
1881-
with_groups(!!.sample, ~ mutate(.x, proportion = (!!.count)/sum(!!.count)) )
1880+
with_groups(!!.sample, ~ mutate(.x, proportion = (!!.count)/sum(!!.count)) ) |>
1881+
mutate(is_zero = proportion==0)
18821882

18831883
if(remove_unwanted_effects){
18841884
.data_adjusted =
@@ -1891,7 +1891,8 @@ sccomp_boxplot = function(
18911891
select(-proportion) |>
18921892
left_join(.data_adjusted, by = join_by(!!.cell_group, !!.sample))
18931893
}
1894-
1894+
else
1895+
message( "sccomp says: When visualising proportions, especially for complex models, consider setting `remove_unwanted_effects=TRUE`. This will adjust the proportions, preserving only the observed effect.")
18951896

18961897
# If I don't have outliers add them
18971898
if(!"outlier" %in% colnames(data_proportion)) data_proportion = data_proportion |> mutate(outlier = FALSE)
@@ -2014,13 +2015,9 @@ else {
20142015
# If discrete
20152016
else
20162017
my_plot =
2017-
plot_boxplot(
2018+
sccomp_boxplot(
20182019
.data = x,
2019-
data_proportion = data_proportion,
2020-
factor_of_interest = .x,
2021-
.cell_group = !!.cell_group,
2022-
.sample = !!.sample,
2023-
my_theme = multipanel_theme,
2020+
factor = .x,
20242021
significance_threshold = significance_threshold
20252022
)
20262023

0 commit comments

Comments
 (0)