Skip to content

Commit a81bc86

Browse files
authored
Merge pull request #84 from MangiolaLaboratory/cmdstanr
Cmdstanr
2 parents 71f2e1a + 1c19258 commit a81bc86

File tree

85 files changed

+3577
-2923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3577
-2923
lines changed

.Rbuildignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
^\.github$
2+
^LICENSE\.md$
3+
^README\.md$
4+
^README\.rmd$
5+
^\.gitignore$
16
^sccomp\.Rproj$
7+
^README_files$
28
^\.Rproj\.user$
3-
^\.github
9+
^NOTICE$
10+
^\.Rhistory$
11+
^\.Rbuildignore$
12+
^\.RData$
13+
^dev$
14+
sccomp_draws_files*
15+
src/stanExport*
16+
src/Rcpp*
417
^\.git
518
^README*
619
^dev
@@ -13,3 +26,4 @@ model_glm_dirichlet_multinomial_imputation.rds
1326
^doc$
1427
^Meta$
1528
sccomp_draws_files
29+

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
.Rhistory
33
.RData
44
.Ruserdata
5-
README_cache/*
6-
vignettes/introduction_cache*
5+
.Rapp.history
6+
inst/doc
77
sccomp.Rproj
88
Meta
99
doc

DESCRIPTION

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
Package: sccomp
22
Title: Robust Outlier-aware Estimation of Composition and Heterogeneity for Single-cell Data
3-
Version: 1.7.15
3+
Version: 1.7.16
44
Authors@R: c(person("Stefano", "Mangiola", email = "mangiolastefano@gmail.com",
55
role = c("aut", "cre"))
66
)
77
Description: A robust and outlier-aware method for testing differential tissue composition from single-cell data. This model can infer changes in tissue composition and heterogeneity, and can produce realistic data simulations based on any existing dataset. This model can also transfer knowledge from a large set of integrated datasets to increase accuracy further.
88
License: GPL-3
9+
URL: https://github.com/MangiolaLaboratory/sccomp
10+
BugReports: https://github.com/MangiolaLaboratory/sccomp/issues
911
Encoding: UTF-8
10-
LazyData: true
1112
Roxygen: list(markdown = TRUE)
12-
RoxygenNote: 7.3.1
13-
Biarch: true
14-
Depends:
15-
R (>= 4.2.0)
16-
Imports:
17-
methods,
18-
Rcpp (>= 0.12.0),
19-
RcppParallel (>= 5.0.1),
20-
rstantools (>= 2.1.1),
21-
rstan (>= 2.26.0),
13+
RoxygenNote: 7.3.2
14+
Depends: R (>= 4.2.0)
15+
Imports:
16+
instantiate (>= 0.2.3),
17+
callr,
18+
fs,
19+
stats,
2220
SeuratObject,
2321
SingleCellExperiment,
2422
parallel,
@@ -40,44 +38,27 @@ Imports:
4038
readr,
4139
scales,
4240
stringr,
43-
glue
41+
glue,
42+
withr
4443
Suggests:
44+
cmdstanr (>= 0.6.0),
45+
knitr,
46+
rmarkdown,
4547
BiocStyle,
4648
testthat (>= 3.0.0),
4749
markdown,
4850
knitr,
4951
loo,
52+
prettydoc,
5053
tidyseurat,
5154
tidySingleCellExperiment,
52-
prettydoc
53-
Enhances:
54-
furrr,
55-
extraDistr
56-
LinkingTo:
57-
BH (>= 1.66.0),
58-
Rcpp (>= 0.12.0),
59-
RcppEigen (>= 0.3.3.3.0),
60-
RcppParallel (>= 5.0.1),
61-
rstan (>= 2.26.0),
62-
StanHeaders (>= 2.26.0)
63-
SystemRequirements: GNU make
64-
VignetteBuilder:
65-
knitr
66-
RdMacros:
67-
lifecycle
68-
biocViews:
69-
ImmunoOncology,
70-
Normalization,
71-
Sequencing,
72-
RNASeq,
73-
Software,
74-
GeneExpression,
75-
Transcriptomics,
76-
SingleCell,
77-
Clustering
78-
LazyDataCompression: xz
79-
Config/testthat/edition: 3
80-
URL: https://github.com/stemangiola/sccomp
81-
BugReports: https://github.com/stemangiola/sccomp/issues
55+
bayesplot,
56+
posterior
57+
Remotes:
58+
wlandau/instantiate
8259
Additional_repositories:
8360
https://mc-stan.org/r-packages/
61+
SystemRequirements: CmdStan (https://mc-stan.org/users/interfaces/cmdstan)
62+
biocViews: Bayesian, Regression, DifferentialExpression, SingleCell
63+
LazyData: true
64+
VignetteBuilder: knitr

NAMESPACE

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,40 @@ S3method(sccomp_remove_unwanted_variation,sccomp_tbl)
1616
S3method(sccomp_replicate,sccomp_tbl)
1717
S3method(sccomp_test,sccomp_tbl)
1818
S3method(simulate_data,tbl)
19+
export(get_output_samples)
1920
export(plot_1D_intervals)
2021
export(plot_2D_intervals)
21-
export(plot_summary)
2222
export(sccomp_boxplot)
2323
export(sccomp_estimate)
24-
export(sccomp_glm)
2524
export(sccomp_predict)
2625
export(sccomp_proportional_fold_change)
2726
export(sccomp_remove_outliers)
2827
export(sccomp_remove_unwanted_variation)
2928
export(sccomp_replicate)
3029
export(sccomp_test)
3130
export(simulate_data)
32-
export(test_contrasts)
33-
import(Rcpp)
34-
import(SeuratObject)
3531
import(dplyr)
3632
import(ggplot2)
37-
import(lifecycle)
38-
import(methods)
39-
import(rstantools)
40-
importFrom(RcppParallel,CxxFlags)
41-
importFrom(RcppParallel,RcppParallelLibs)
4233
importFrom(SingleCellExperiment,colData)
4334
importFrom(SingleCellExperiment,counts)
44-
importFrom(boot,logit)
4535
importFrom(dplyr,any_of)
4636
importFrom(dplyr,arrange)
37+
importFrom(dplyr,as_tibble)
4738
importFrom(dplyr,cummean)
39+
importFrom(dplyr,distinct)
4840
importFrom(dplyr,distinct_at)
4941
importFrom(dplyr,enquo)
5042
importFrom(dplyr,filter)
43+
importFrom(dplyr,group_by)
5144
importFrom(dplyr,if_else)
5245
importFrom(dplyr,left_join)
5346
importFrom(dplyr,mutate)
47+
importFrom(dplyr,mutate_all)
48+
importFrom(dplyr,mutate_if)
49+
importFrom(dplyr,pull)
5450
importFrom(dplyr,row_number)
5551
importFrom(dplyr,select)
52+
importFrom(dplyr,summarise)
5653
importFrom(dplyr,with_groups)
5754
importFrom(forcats,fct_relevel)
5855
importFrom(forcats,fct_reorder)
@@ -66,6 +63,11 @@ importFrom(ggplot2,geom_vline)
6663
importFrom(ggplot2,ggplot)
6764
importFrom(ggrepel,geom_text_repel)
6865
importFrom(glue,glue)
66+
importFrom(instantiate,stan_cmdstan_exists)
67+
importFrom(instantiate,stan_package_compile)
68+
importFrom(instantiate,stan_package_model)
69+
importFrom(lifecycle,deprecate_warn)
70+
importFrom(lifecycle,is_present)
6971
importFrom(magrittr,"%$%")
7072
importFrom(magrittr,divide_by)
7173
importFrom(magrittr,equals)
@@ -89,6 +91,8 @@ importFrom(purrr,pmap)
8991
importFrom(purrr,reduce)
9092
importFrom(purrr,when)
9193
importFrom(readr,read_file)
94+
importFrom(readr,type_convert)
95+
importFrom(readr,write_file)
9296
importFrom(rlang,":=")
9397
importFrom(rlang,enquo)
9498
importFrom(rlang,ensym)
@@ -98,13 +102,6 @@ importFrom(rlang,quo_is_symbolic)
98102
importFrom(rlang,quo_name)
99103
importFrom(rlang,quo_squash)
100104
importFrom(rlang,set_names)
101-
importFrom(rstan,Rhat)
102-
importFrom(rstan,extract)
103-
importFrom(rstan,sampling)
104-
importFrom(rstan,sflist2stanfit)
105-
importFrom(rstan,stan_model)
106-
importFrom(rstan,summary)
107-
importFrom(rstan,vb)
108105
importFrom(scales,trans_new)
109106
importFrom(stats,C)
110107
importFrom(stats,as.formula)
@@ -119,10 +116,8 @@ importFrom(stringr,str_split)
119116
importFrom(stringr,str_subset)
120117
importFrom(stringr,str_trim)
121118
importFrom(tibble,add_column)
122-
importFrom(tibble,as_tibble)
123119
importFrom(tibble,deframe)
124120
importFrom(tibble,enframe)
125-
importFrom(tibble,rowid_to_column)
126121
importFrom(tidyr,complete)
127122
importFrom(tidyr,drop_na)
128123
importFrom(tidyr,expand_grid)
@@ -136,7 +131,9 @@ importFrom(tidyr,separate)
136131
importFrom(tidyr,spread)
137132
importFrom(tidyr,unite)
138133
importFrom(tidyr,unnest)
134+
importFrom(tidyselect,all_of)
139135
importFrom(tidyselect,eval_select)
140136
importFrom(tidyselect,last_col)
141137
importFrom(utils,data)
142-
useDynLib(sccomp, .registration = TRUE)
138+
importFrom(utils,install.packages)
139+
importFrom(utils,menu)

R/cmdstanr_safe.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
sample_safe <- function(model, fx, ...) {
4+
tryCatch(
5+
{
6+
# Attempt to run the arbitrary fx with additional arguments
7+
result <- fx(model, ...)
8+
return(result)
9+
},
10+
error = function(e) {
11+
# Check if the error message is "model not compiled"
12+
if (grepl("Model not compiled", e$message)) {
13+
message("Model not compiled. Compiling.")
14+
# Load the model with force=TRUE
15+
model <- model$compile(cpp_options = list(stan_threads = TRUE)) # load_model("glm_multi_beta_binomial_generate_data", force = TRUE)
16+
# Retry the arbitrary fx with additional arguments
17+
result <- fx(model, ...)
18+
return(result)
19+
} else {
20+
# If a different error, rethrow the error
21+
stop(e)
22+
}
23+
}
24+
)
25+
}
26+
27+
28+
sample_fx <- function(model, ...) {
29+
model$sample(...)
30+
}
31+
32+
pathfinder_fx <- function(model, ...) {
33+
model$pathfinder(...)
34+
}
35+
36+
variational_fx <- function(model, ...) {
37+
model$variational(...)
38+
}
39+
40+
generate_quantities_fx <- function(model, ...) {
41+
model$generate_quantities(...)
42+
}

0 commit comments

Comments
 (0)