Last updated: 2022-03-10
Checks: 7 0
Knit directory: BASS-analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(0)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 34e84d6. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
working directory clean
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/about.Rmd
) and HTML (docs/about.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 34e84d6 | zhengli09 | 2022-03-10 | Add software tutorial and multi-sample simulation |
html | 9a68511 | zhengli09 | 2022-02-27 | Build site. |
Rmd | 4ec8df1 | zhengli09 | 2022-02-27 | Publish the introduction, simulation analysis and STARmap analysis |
html | b2c476b | zhengli09 | 2022-02-06 | Build site. |
html | a6097f4 | zhengli09 | 2022-02-06 | Build site. |
Rmd | 9f8756a | zhengli09 | 2022-02-06 | Start workflowr project. |
In this tutorial, we introduce the workflow and core functions of BASS to help you get familiar with the BASS package and start analyzing your own datasets. Please check the Real data analyses
sections for examples on how we analyze spatial transcriptomic datasets.
Install BASS R package maintained in github through the “devtools” package.
if(!require(devtools))
install.packages(devtools)
devtools::install_github("zhengli09/BASS")
library(BASS)
load("data/starmap_mpfc.RData") # starmap_cnts, starmap_info
To facilitate all steps of the spatial transcriptomic analysis, we wrap up the raw data, processed data, model hyper-parameters, MCMC controlling parameters, and model results into a S4 object (BASS-class). Create a BASS object to start your analysis with the function createBASSObject
. There are four required arguments: an L-list of gene expression count matrices for L tissue sections (X
), an L-list of spatial coordinates matrices for L tissue sections (xy
), the number of cell types (C
) and the number of spatial domains (R
). By default, we fix the cell-cell interaction parameter \(\beta\) to the value specified by beta
if the user has already had a good sense about the value of this parameter. However, BASS can also accurately infer the cell-cell interaction parameter \(\beta\) based on the data at hand at the cost of a slightly longer computational time. Check the documentation of createBASSObject
for further details.
# gene expression count data
cnts <- starmap_cnts
# spatial coordinates
xy <- lapply(starmap_info, function(info.i){
as.matrix(info.i[, c("x", "y")])
})
BASS <- createBASSObject(cnts, xy, C = 15, R = 4,
beta_est_approach = "ACCUR_EST")
***************************************
INPUT INFO:
- Number of tissue sections: 3
- Number of cells/spots: 1049 1053 1088
- Number of genes: 166
- Potts interaction parameter estimation approach: ACCUR_EST
- Variance-covariance structure of gene expression features: EEE
To list all hyper-parameters, Type listAllHyper(BASS_object)
***************************************
You can check all the hyper-parameters that BASS uses with the function listAllHyper
.
listAllHyper(BASS)
***************************************
Please refer to the paper for details of the paramters
ALL HYPER-PARAMETERS:
- Number of cell types C: 15
- Number of spatial domains R: 4
- Initialization method: kmeans
- Covariance structure: EEE
- Scale matrix of the inverse-Wishart prior W0: 1I
- Degrees of freedom of the inverse-Wishart prior n0: 1
- Number of MCMC burn-in iterations: 10000
- Number of MCMC posterior samples: 10000
- Potts interaction parameter estimation approach: ACCUR_EST
- Number of burn-in interations in Potts sampling: 100
- Number of Potts samples to approximate the partition ratio: 100
- Step size of a uniform random walk epsilon: 0.1
- Threshold of convergence for beta: 0.1
- Upper bound for beta: 4
- Concentration parameter of the Dirichlet prior alpha0: 1
- Minimum number of neighbors for each cell/spot based on the Euclidean distance: 4
***************************************
We pre-process the raw gene expression data stored at the BASS@X
slot and store the processed data at the BASS@X_run
slot for running the following BASS algorithm. We have provided a function BASS.preprocess
to automate the pre-processing steps, where we combine cells/spots across all L tissue sections, conduct library size normalization followed by a log2-transformation (after adding a pseudo-count of 1), select feature genes, perform dimension reduction with PCA on the normalized expression matrix to extract J low-dimensional expression features, and perform batch effect adjustment with Harmony to align expression data from different tissue sections. Users can also pre-process the gene expression data by themselves and store the processed data to the BASS@X_run
slot. Check the documentation of BASS.preprocess
for further details and various other controls.
BASS <- BASS.preprocess(BASS)
Run the Gibbs sampling algorithm in combination with the Metroplis-Hastings algorithm to sample all the parameters specified in the BASS model. Posterior samples of all the parameters are stored in the BASS@res
slot and you can find a detailed description of what has been stored in BASS@res
in the documentation of the BASS object (?`BASS-class`). Check the documentation of BASS.run
for further details.
BASS <- BASS.run(BASS)
Post-process the posterior sampling results with the function BASS.postprocess
. There, we address the label switching issue associated with the sampling of cell type labels and spatial domain labels based on the iterative version 1 of the equivalence class representation (ECR) algorithm implemented in the label.switching package. In addition, we summarize posterior samples and obtain final estimates of cell type labels, spatial domain labels, and cell type composition in each spatial domain. The resulting estimates are stored in the BASS@res_postprocess
slot. Check the documentation of BASS.postprocess
for further details.
BASS <- BASS.postprocess(BASS)
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.6 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
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
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BASS_1.0 mclust_5.4.9 GIGrvg_0.5 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8 bslib_0.3.1 compiler_4.1.2 pillar_1.7.0
[5] later_1.1.0.1 git2r_0.28.0 jquerylib_0.1.4 tools_4.1.2
[9] getPass_0.2-2 digest_0.6.29 jsonlite_1.8.0 evaluate_0.15
[13] tibble_3.1.6 lifecycle_1.0.1 pkgconfig_2.0.3 rlang_1.0.1
[17] cli_3.2.0 rstudioapi_0.13 yaml_2.3.5 xfun_0.29
[21] fastmap_1.1.0 httr_1.4.2 stringr_1.4.0 knitr_1.37
[25] sass_0.4.0 fs_1.5.2 vctrs_0.3.8 rprojroot_2.0.2
[29] glue_1.6.2 R6_2.5.1 processx_3.5.2 fansi_1.0.2
[33] rmarkdown_2.12.1 callr_3.7.0 magrittr_2.0.2 whisker_0.4
[37] ps_1.6.0 promises_1.1.1 htmltools_0.5.2 ellipsis_0.3.2
[41] httpuv_1.5.4 utf8_1.2.2 stringi_1.7.6 crayon_1.5.0