Contents

1 Welcome

Welcome to the SRTsim project! It is composed of:

The web application allows you to design spatial pattern and generate SRT data with patterns of interest.

2 Install SRTsim

R is an open-source statistical environment which can be easily modified to enhance its functionality via packages. SRTsim is a R package available via CRAN. R can be installed on any operating system from CRAN after which you can install SRTsim by using the following commands in your R session:

 install.packages("SRTsim")

3 Run Reference-Based Simulation

To get started, please load the SRTsim package.

library("SRTsim")

Once you have installed the package, we can perform reference-based Tissue-wise simulation with the example data.

## explore example SRT data 
str(exampleLIBD)
#> List of 2
#>  $ count:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
#>   .. ..@ i       : int [1:241030] 1 2 8 9 10 11 13 14 15 16 ...
#>   .. ..@ p       : int [1:3612] 0 67 122 182 252 322 392 462 534 609 ...
#>   .. ..@ Dim     : int [1:2] 80 3611
#>   .. ..@ Dimnames:List of 2
#>   .. .. ..$ : chr [1:80] "ENSG00000175130" "ENSG00000159176" "ENSG00000168314" "ENSG00000080822" ...
#>   .. .. ..$ : chr [1:3611] "AAACAAGTATCTCCCA-1" "AAACAATCTACTAGCA-1" "AAACACCAATAACTGC-1" "AAACAGAGCGACTCCT-1" ...
#>   .. ..@ x       : num [1:241030] 1 1 1 7 10 1 5 2 1 1 ...
#>   .. ..@ factors : list()
#>  $ info :'data.frame':   3611 obs. of  6 variables:
#>   ..$ row     : int [1:3611] 50 3 59 14 43 47 73 61 45 42 ...
#>   ..$ col     : int [1:3611] 102 43 19 94 9 13 43 97 115 28 ...
#>   ..$ imagerow: num [1:3611] 381 126 428 187 341 ...
#>   ..$ imagecol: num [1:3611] 441 260 183 417 153 ...
#>   ..$ tissue  : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
#>   ..$ layer   : chr [1:3611] "Layer3" "Layer1" "WM" "Layer3" ...

example_count   <- exampleLIBD$count
example_loc     <- exampleLIBD$info[,c("imagecol","imagerow","layer")]
colnames(example_loc) <- c("x","y","label")

## create a SRT object
simSRT  <- createSRT(count_in=example_count,loc_in =example_loc)


## Set a seed for reproducible simulation
set.seed(1)

## Estimate model parameters for data generation
simSRT1 <- srtsim_fit(simSRT,sim_schem="tissue")

## Generate synthetic data with estimated parameters
simSRT1 <- srtsim_count(simSRT1)

## Explore the synthetic data
simCounts(simSRT1)[1:5,1:5]
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>                 AAACAAGTATCTCCCA-1 AAACAATCTACTAGCA-1 AAACACCAATAACTGC-1
#> ENSG00000175130                  .                  .                 10
#> ENSG00000159176                  1                  3                  5
#> ENSG00000168314                  1                  .                  6
#> ENSG00000080822                  .                  .                  3
#> ENSG00000091513                  .                  .                  5
#>                 AAACAGAGCGACTCCT-1 AAACAGCTTTCAGAAG-1
#> ENSG00000175130                  .                  2
#> ENSG00000159176                  .                  1
#> ENSG00000168314                  2                  1
#> ENSG00000080822                  1                  .
#> ENSG00000091513                  1                  3
simcolData(simSRT1)
#> DataFrame with 3611 rows and 3 columns
#>                            x         y       label
#>                    <numeric> <numeric> <character>
#> AAACAAGTATCTCCCA-1   440.639   381.098      Layer3
#> AAACAATCTACTAGCA-1   259.631   126.328      Layer1
#> AAACACCAATAACTGC-1   183.078   427.768          WM
#> AAACAGAGCGACTCCT-1   417.237   186.814      Layer3
#> AAACAGCTTTCAGAAG-1   152.700   341.269      Layer5
#> ...                      ...       ...         ...
#> TTGTTTCACATCCAGG-1   254.410   422.862          WM
#> TTGTTTCATTAGTCTA-1   217.147   433.393          WM
#> TTGTTTCCATACAACT-1   208.416   352.430      Layer6
#> TTGTTTGTATTACACG-1   250.720   503.735          WM
#> TTGTTTGTGTAAATTC-1   284.293   148.110      Layer2

We can perform reference-based Domain-specific simulation with the example data.


## Set a seed for reproducible simulation
set.seed(1)

## Estimate model parameters for data generation
simSRT2 <- srtsim_fit(simSRT,sim_scheme='domain')

## Generate synthetic data with estimated parameters
simSRT2 <- srtsim_count(simSRT2)

## Explore the synthetic data
simCounts(simSRT2)[1:5,1:5]
#> 5 x 5 sparse Matrix of class "dgCMatrix"
#>                 AAACAAGTATCTCCCA-1 AAACAATCTACTAGCA-1 AAACACCAATAACTGC-1
#> ENSG00000175130                  .                  .                 11
#> ENSG00000159176                  1                  2                  7
#> ENSG00000168314                  1                  .                  7
#> ENSG00000080822                  .                  .                  3
#> ENSG00000091513                  .                  .                  6
#>                 AAACAGAGCGACTCCT-1 AAACAGCTTTCAGAAG-1
#> ENSG00000175130                  .                  2
#> ENSG00000159176                  .                  1
#> ENSG00000168314                  2                  1
#> ENSG00000080822                  1                  .
#> ENSG00000091513                  2                  3

4 Comparison Between Reference Data and Synthetic Data

4.1 Summarized Metrics

After data generation, we can compare metrics of reference data and synthetic data


## Compute metrics 
simSRT1   <- compareSRT(simSRT1)

## Visualize Metrics
visualize_metrics(simSRT1)

4.2 Expression Patterns For Genes of Interest

visualize_gene(simsrt=simSRT1,plotgn = "ENSG00000183036",rev_y=TRUE)

visualize_gene(simsrt=simSRT2,plotgn = "ENSG00000168314",rev_y=TRUE)

This work was done by Jiaqiang Zhu, Lulu Shang and Xiang Zhou.

5 Reproducibility

The SRTsim package was made possible thanks to:

Code for creating the vignette

## Create the vignette
library("rmarkdown")
system.time(render("SRTsim.Rmd"))

## Extract the R code
library("knitr")
knit("SRTsim.Rmd", tangle = TRUE)

Date the vignette was generated.

#> [1] "2024-08-20 17:01:59 EDT"

Wallclock time spent generating the vignette.

#> Time difference of 8.603 secs

R session information.

#> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14)
#>  os       macOS Sonoma 14.5
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  C
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2024-08-20
#>  pandoc   2.18 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
#>  package         * version date (UTC) lib source
#>  abind             1.4-5   2016-07-21 [2] CRAN (R 4.4.0)
#>  backports         1.5.0   2024-05-23 [2] CRAN (R 4.4.0)
#>  base64enc         0.1-3   2015-07-28 [2] CRAN (R 4.4.0)
#>  bezier            1.1.2   2018-12-14 [2] CRAN (R 4.4.0)
#>  bibtex            0.5.1   2023-01-26 [2] CRAN (R 4.4.0)
#>  BiocGenerics      0.50.0  2024-04-30 [2] Bioconductor 3.19 (R 4.4.0)
#>  BiocManager       1.30.23 2024-05-04 [2] CRAN (R 4.4.0)
#>  BiocStyle       * 2.32.1  2024-06-16 [2] Bioconductor 3.19 (R 4.4.0)
#>  bookdown          0.40    2024-07-02 [2] CRAN (R 4.4.0)
#>  broom             1.0.6   2024-05-17 [2] CRAN (R 4.4.0)
#>  bslib             0.8.0   2024-07-29 [2] CRAN (R 4.4.0)
#>  cachem            1.1.0   2024-05-16 [2] CRAN (R 4.4.0)
#>  car               3.1-2   2023-03-30 [2] CRAN (R 4.4.0)
#>  carData           3.0-5   2022-01-06 [2] CRAN (R 4.4.0)
#>  class             7.3-22  2023-05-03 [2] CRAN (R 4.4.1)
#>  classInt          0.4-10  2023-09-05 [2] CRAN (R 4.4.0)
#>  cli               3.6.3   2024-06-21 [2] CRAN (R 4.4.0)
#>  codetools         0.2-20  2024-03-31 [2] CRAN (R 4.4.1)
#>  colorRamps        2.3.4   2024-03-07 [2] CRAN (R 4.4.0)
#>  colorspace        2.1-1   2024-07-26 [2] CRAN (R 4.4.0)
#>  concaveman        1.1.0   2020-05-11 [2] CRAN (R 4.4.0)
#>  cowplot           1.1.3   2024-01-22 [2] CRAN (R 4.4.0)
#>  dashboardthemes   1.1.6   2022-07-13 [2] CRAN (R 4.4.0)
#>  data.table        1.15.4  2024-03-30 [2] CRAN (R 4.4.0)
#>  DBI               1.2.3   2024-06-02 [2] CRAN (R 4.4.0)
#>  deldir            2.0-4   2024-02-28 [2] CRAN (R 4.4.0)
#>  digest            0.6.36  2024-06-23 [2] CRAN (R 4.4.0)
#>  doParallel        1.0.17  2022-02-07 [2] CRAN (R 4.4.0)
#>  dplyr             1.1.4   2023-11-17 [2] CRAN (R 4.4.0)
#>  DT                0.33    2024-04-04 [2] CRAN (R 4.4.0)
#>  e1071             1.7-14  2023-12-06 [2] CRAN (R 4.4.0)
#>  evaluate          0.24.0  2024-06-10 [2] CRAN (R 4.4.0)
#>  fansi             1.0.6   2023-12-08 [2] CRAN (R 4.4.0)
#>  farver            2.1.2   2024-05-13 [2] CRAN (R 4.4.0)
#>  fastmap           1.2.0   2024-05-15 [2] CRAN (R 4.4.0)
#>  FNN               1.1.4   2024-01-12 [2] CRAN (R 4.4.0)
#>  foreach           1.5.2   2022-02-02 [2] CRAN (R 4.4.0)
#>  generics          0.1.3   2022-07-05 [2] CRAN (R 4.4.0)
#>  ggplot2           3.5.1   2024-04-23 [2] CRAN (R 4.4.0)
#>  ggpubr            0.6.0   2023-02-10 [2] CRAN (R 4.4.0)
#>  ggsignif          0.6.4   2022-10-13 [2] CRAN (R 4.4.0)
#>  glue              1.7.0   2024-01-09 [2] CRAN (R 4.4.0)
#>  gridExtra         2.3     2017-09-09 [2] CRAN (R 4.4.0)
#>  gtable            0.3.5   2024-04-22 [2] CRAN (R 4.4.0)
#>  highr             0.11    2024-05-26 [2] CRAN (R 4.4.0)
#>  htmltools         0.5.8.1 2024-04-04 [2] CRAN (R 4.4.0)
#>  htmlwidgets       1.6.4   2023-12-06 [2] CRAN (R 4.4.0)
#>  httpuv            1.6.15  2024-03-26 [2] CRAN (R 4.4.0)
#>  httr              1.4.7   2023-08-15 [2] CRAN (R 4.4.0)
#>  iterators         1.0.14  2022-02-05 [2] CRAN (R 4.4.0)
#>  jquerylib         0.1.4   2021-04-26 [2] CRAN (R 4.4.0)
#>  jsonlite          1.8.8   2023-12-04 [2] CRAN (R 4.4.0)
#>  KernSmooth        2.23-24 2024-05-17 [2] CRAN (R 4.4.1)
#>  knitr             1.48    2024-07-07 [2] CRAN (R 4.4.0)
#>  labeling          0.4.3   2023-08-29 [2] CRAN (R 4.4.0)
#>  later             1.3.2   2023-12-06 [2] CRAN (R 4.4.0)
#>  lattice           0.22-6  2024-03-20 [2] CRAN (R 4.4.1)
#>  lazyeval          0.2.2   2019-03-15 [2] CRAN (R 4.4.0)
#>  lifecycle         1.0.4   2023-11-07 [2] CRAN (R 4.4.0)
#>  lubridate         1.9.3   2023-09-27 [2] CRAN (R 4.4.0)
#>  magick            2.8.4   2024-07-14 [2] CRAN (R 4.4.0)
#>  magrittr          2.0.3   2022-03-30 [2] CRAN (R 4.4.0)
#>  MASS              7.3-61  2024-06-13 [2] CRAN (R 4.4.0)
#>  Matrix            1.7-0   2024-04-26 [2] CRAN (R 4.4.1)
#>  matrixStats       1.3.0   2024-04-11 [2] CRAN (R 4.4.0)
#>  mime              0.12    2021-09-28 [2] CRAN (R 4.4.0)
#>  Morpho            2.12    2023-12-06 [2] CRAN (R 4.4.0)
#>  munsell           0.5.1   2024-04-01 [2] CRAN (R 4.4.0)
#>  pdist             1.2.1   2022-05-02 [2] CRAN (R 4.4.0)
#>  pillar            1.9.0   2023-03-22 [2] CRAN (R 4.4.0)
#>  pkgconfig         2.0.3   2019-09-22 [2] CRAN (R 4.4.0)
#>  plotly            4.10.4  2024-01-13 [2] CRAN (R 4.4.0)
#>  plyr              1.8.9   2023-10-02 [2] CRAN (R 4.4.0)
#>  polyclip          1.10-7  2024-07-23 [2] CRAN (R 4.4.0)
#>  promises          1.3.0   2024-04-05 [2] CRAN (R 4.4.0)
#>  proxy             0.4-27  2022-06-09 [2] CRAN (R 4.4.0)
#>  purrr             1.0.2   2023-08-10 [2] CRAN (R 4.4.0)
#>  R6                2.5.1   2021-08-19 [2] CRAN (R 4.4.0)
#>  RColorBrewer      1.1-3   2022-04-03 [2] CRAN (R 4.4.0)
#>  Rcpp              1.0.13  2024-07-17 [2] CRAN (R 4.4.0)
#>  RefManageR      * 1.4.0   2022-09-30 [2] CRAN (R 4.4.0)
#>  rgl               1.3.1   2024-03-05 [2] CRAN (R 4.4.0)
#>  rlang             1.1.4   2024-06-04 [2] CRAN (R 4.4.0)
#>  rmarkdown         2.27    2024-05-17 [2] CRAN (R 4.4.0)
#>  rstatix           0.7.2   2023-02-01 [2] CRAN (R 4.4.0)
#>  Rvcg              0.23    2024-06-27 [2] CRAN (R 4.4.0)
#>  S4Vectors         0.42.1  2024-07-03 [2] Bioconductor 3.19 (R 4.4.1)
#>  sass              0.4.9   2024-03-15 [2] CRAN (R 4.4.0)
#>  scales            1.3.0   2023-11-28 [2] CRAN (R 4.4.0)
#>  sessioninfo     * 1.2.2   2021-12-06 [2] CRAN (R 4.4.0)
#>  sf                1.0-16  2024-03-24 [2] CRAN (R 4.4.0)
#>  shiny             1.9.1   2024-08-01 [2] CRAN (R 4.4.0)
#>  shinyBS           0.61.1  2022-04-17 [2] CRAN (R 4.4.0)
#>  shinydashboard    0.7.2   2021-09-30 [2] CRAN (R 4.4.0)
#>  sp                2.1-4   2024-04-30 [2] CRAN (R 4.4.0)
#>  spatstat.data     3.1-2   2024-06-21 [2] CRAN (R 4.4.0)
#>  spatstat.geom     3.3-2   2024-07-15 [2] CRAN (R 4.4.0)
#>  spatstat.random   3.3-1   2024-07-15 [2] CRAN (R 4.4.0)
#>  spatstat.univar   3.0-0   2024-06-28 [2] CRAN (R 4.4.0)
#>  spatstat.utils    3.0-5   2024-06-17 [2] CRAN (R 4.4.0)
#>  SRTsim          * 0.99.7  2024-08-20 [1] local
#>  stringi           1.8.4   2024-05-06 [2] CRAN (R 4.4.0)
#>  stringr           1.5.1   2023-11-14 [2] CRAN (R 4.4.0)
#>  tibble            3.2.1   2023-03-20 [2] CRAN (R 4.4.0)
#>  tidyr             1.3.1   2024-01-24 [2] CRAN (R 4.4.0)
#>  tidyselect        1.2.1   2024-03-11 [2] CRAN (R 4.4.0)
#>  timechange        0.3.0   2024-01-18 [2] CRAN (R 4.4.0)
#>  tinytex           0.52    2024-07-18 [2] CRAN (R 4.4.0)
#>  units             0.8-5   2023-11-28 [2] CRAN (R 4.4.0)
#>  utf8              1.2.4   2023-10-22 [2] CRAN (R 4.4.0)
#>  vctrs             0.6.5   2023-12-01 [2] CRAN (R 4.4.0)
#>  viridis           0.6.5   2024-01-29 [2] CRAN (R 4.4.0)
#>  viridisLite       0.4.2   2023-05-02 [2] CRAN (R 4.4.0)
#>  withr             3.0.1   2024-07-31 [2] CRAN (R 4.4.0)
#>  xfun              0.46    2024-07-18 [2] CRAN (R 4.4.0)
#>  xml2              1.3.6   2023-12-04 [2] CRAN (R 4.4.0)
#>  xtable            1.8-4   2019-04-21 [2] CRAN (R 4.4.0)
#>  yaml              2.3.10  2024-07-26 [2] CRAN (R 4.4.0)
#> 
#>  [1] /private/var/folders/my/31z8ld9s2qd53tvdmv_3w51h0000gn/T/RtmpcWO93f/Rinstadd171dd6eb1
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

6 Bibliography

This vignette was generated using BiocStyle (Oleś, 2024), knitr (Xie, 2014) and rmarkdown (Allaire, Xie, Dervieux et al., 2024) running behind the scenes.

Citations made with RefManageR (McLean, 2017).

[1] J. Allaire, Y. Xie, C. Dervieux, et al. rmarkdown: Dynamic Documents for R. R package version 2.27. 2024. URL: https://github.com/rstudio/rmarkdown.

[2] D. Bates, M. Maechler, and M. Jagan. Matrix: Sparse and Dense Matrix Classes and Methods. R package version 1.7-0. 2024. URL: https://CRAN.R-project.org/package=Matrix.

[3] M. W. McLean. “RefManageR: Import and Manage BibTeX and BibLaTeX References in R”. In: The Journal of Open Source Software (2017). DOI: 10.21105/joss.00338.

[4] A. Oleś. BiocStyle: Standard styles for vignettes and other Bioconductor documents. R package version 2.32.1. 2024. DOI: 10.18129/B9.bioc.BiocStyle. URL: https://bioconductor.org/packages/BiocStyle.

[5] H. Pagès, M. Lawrence, and P. Aboyoun. S4Vectors: Foundation of vector-like and list-like containers in Bioconductor. R package version 0.42.1. 2024. DOI: 10.18129/B9.bioc.S4Vectors. URL: https://bioconductor.org/packages/S4Vectors.

[6] R Core Team. R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria, 2024. URL: https://www.R-project.org/.

[7] H. Wickham, W. Chang, R. Flight, et al. sessioninfo: R Session Information. R package version 1.2.2. 2021. URL: https://CRAN.R-project.org/package=sessioninfo.

[8] Y. Xie. “knitr: A Comprehensive Tool for Reproducible Research in R”. In: Implementing Reproducible Computational Research. Ed. by V. Stodden, F. Leisch and R. D. Peng. Chapman and Hall/CRC, 2014. ISBN: 978-1466561595. URL: https://www.routledge.com/Implementing-Reproducible-Research/Stodden-Leisch-Peng/p/book/9781466561595.