Last updated: 2020-04-03

Checks: 7 0

Knit directory: STUtility_web_site/

This reproducible R Markdown analysis was created with workflowr (version 1.6.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(20191031) 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 version displayed above was the version of the Git repository at the time these results were generated.

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:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/getting_started_cache/

Unstaged changes:
    Modified:   myproject.Rproj

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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view them.

File Version Author Date Message
Rmd b5f9314 jbergenstrahle 2020-04-01 removed regress
html fb06450 jbergenstrahle 2020-01-11 Build site.
Rmd efbbda3 jbergenstrahle 2020-01-01 update pek
Rmd 5cb8ab1 jbergenstrahle 2019-12-02 update2
html a3a1f1f Ludvig Larsson 2019-10-31 Changed font
Rmd 7cdf8e1 Ludvig Larsson 2019-10-31 Changed font size
Rmd 786357d Ludvig Larsson 2019-10-31 Fixed warnings
html 786357d Ludvig Larsson 2019-10-31 Fixed warnings
Rmd f10ef37 Ludvig Larsson 2019-10-31 Added section noramlization and spatial faetures
html f10ef37 Ludvig Larsson 2019-10-31 Added section noramlization and spatial faetures

SCTransform (Seurat)

In order to normalize the data we recommend using variance stabilized transformation available in the SCTransform function in Seurat as of v3.0.

Following the rationale expressed below, we transform the data according to the Seurat workflow.

se <- SCTransform(se)

Note: for comprehensive tutorials in the different options and workflow possibilities available within Seurat, we recommend looking at their website https://satijalab.org/seurat/. Special consideration should be put into if and how the user apply the vars.to.regress parameter, which specifies which variables to regress out. This can be used to correct for heterogeneity in the data that is of no interest.


Rationale of approach

Each spot in a Spatial Transcriptomics dataset typically contains RNA from a mixture of cells so why would we apply a workflow that was developed for single-cell RNAseq data? We can calculate some properties to visually inspect the data to see that ST data have similar properties to that of scRNAseq data.

library(Matrix)
library(magrittr)
library(dplyr)
library(ggplot2)

# Get raw count data 
umi_data <- GetAssayData(object = se, slot = "counts", assay = "RNA")
dim(umi_data)

# Calculate gene attributes
gene_attr <- data.frame(mean = rowMeans(umi_data),
                        detection_rate = rowMeans(umi_data > 0),
                        var = apply(umi_data, 1, var), 
                        row.names = rownames(umi_data)) %>%
  mutate(log_mean = log10(mean), log_var = log10(var))

# Obtain spot attributes from Seurat meta.data slot
spot_attr <- se[[c("nFeature_RNA", "nCount_RNA")]]

p1 <- ggplot(gene_attr, aes(log_mean, log_var)) + 
  geom_point(alpha = 0.3, shape = 16, color = "white") + 
  geom_density_2d(size = 0.3) +
  geom_abline(intercept = 0, slope = 1, color = 'red') +
  ggtitle("Mean-variance relationship") + DarkTheme()

# add the expected detection rate under Poisson model
x = seq(from = -2, to = 2, length.out = 1000)
poisson_model <- data.frame(log_mean = x, detection_rate = 1 - dpois(0, lambda = 10^x))
p2 <- ggplot(gene_attr, aes(log_mean, detection_rate)) + 
  geom_point(alpha = 0.3, shape = 16, color = "white") + 
  geom_line(data = poisson_model, color='red') +
  ggtitle("Mean-detection-rate relationship") + DarkTheme()

cowplot::plot_grid(p1, p2, nrow = 2)

Version Author Date
fb06450 jbergenstrahle 2020-01-11
f10ef37 Ludvig Larsson 2019-10-31

We can see from the mean-variance and Mean-detection-rate scatter plots that genes show overdispersion compared to what would be expected under a Poisson model. Because these properties are shared between ST and scRNAseq data we have reasoned that the workflow presented in the Seurat package should be applicable for ST data as well. It is important however to keep in mind that each spots contains a mixture of cell types and should be interpreted as a morphological unit in the context of a tissue section.

 

A work by Joseph Bergenstråhle and Ludvig Larsson

 


sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 19.3

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /home/joey/.local/share/r-miniconda/envs/r-reticulate/lib/libmkl_rt.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=sv_SE.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=sv_SE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=sv_SE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] dplyr_0.8.3                 magrittr_1.5               
 [3] Matrix_1.2-18               STutility_0.1.0            
 [5] ggplot2_3.2.1               SingleCellExperiment_1.8.0 
 [7] SummarizedExperiment_1.16.1 DelayedArray_0.12.2        
 [9] BiocParallel_1.20.1         matrixStats_0.55.0         
[11] Biobase_2.46.0              GenomicRanges_1.38.0       
[13] GenomeInfoDb_1.22.0         IRanges_2.20.2             
[15] S4Vectors_0.24.2            BiocGenerics_0.32.0        
[17] Seurat_3.1.3.9002           workflowr_1.6.0            

loaded via a namespace (and not attached):
  [1] reticulate_1.14         tidyselect_0.2.5        htmlwidgets_1.5.1      
  [4] grid_3.6.2              Rtsne_0.15              munsell_0.5.0          
  [7] codetools_0.2-16        mutoss_0.1-12           ica_1.0-2              
 [10] future_1.15.1           miniUI_0.1.1.1          withr_2.1.2            
 [13] colorspace_1.4-1        knitr_1.26              uuid_0.1-2             
 [16] ROCR_1.0-7              tensor_1.5              gbRd_0.4-11            
 [19] listenv_0.8.0           labeling_0.3            Rdpack_0.11-1          
 [22] git2r_0.26.1.9000       GenomeInfoDbData_1.2.2  mnormt_1.5-5           
 [25] polyclip_1.10-0         farver_2.0.1            rprojroot_1.3-2        
 [28] vctrs_0.2.1             TH.data_1.0-10          xfun_0.12              
 [31] R6_2.4.1                doParallel_1.0.15       rsvd_1.0.2             
 [34] Morpho_2.7              ggiraph_0.7.0           manipulateWidget_0.10.0
 [37] bitops_1.0-6            spatstat.utils_1.15-0   assertthat_0.2.1       
 [40] promises_1.1.0          scales_1.1.0            imager_0.41.2          
 [43] multcomp_1.4-12         gtable_0.3.0            npsurv_0.4-0           
 [46] globals_0.12.5          bmp_0.3                 goftest_1.2-2          
 [49] sandwich_2.5-1          rlang_0.4.2             zeallot_0.1.0          
 [52] akima_0.6-2             systemfonts_0.1.1       splines_3.6.2          
 [55] lazyeval_0.2.2          rgl_0.100.30            yaml_2.2.0             
 [58] reshape2_1.4.3          abind_1.4-5             crosstalk_1.0.0        
 [61] backports_1.1.5         httpuv_1.5.2            tools_3.6.2            
 [64] gplots_3.0.1.2          raster_3.0-7            RColorBrewer_1.1-2     
 [67] Rvcg_0.18               ggridges_0.5.2          TFisher_0.2.0          
 [70] Rcpp_1.0.3              plyr_1.8.5              zlibbioc_1.32.0        
 [73] purrr_0.3.3             RCurl_1.95-4.12         rpart_4.1-15           
 [76] deldir_0.1-23           viridis_0.5.1           pbapply_1.4-2          
 [79] cowplot_1.0.0           zoo_1.8-7               ggrepel_0.8.1          
 [82] cluster_2.1.0           colorRamps_2.3          fs_1.3.1               
 [85] magick_2.2              data.table_1.12.8       readbitmap_0.1.5       
 [88] lmtest_0.9-37           RANN_2.6.1              mvtnorm_1.0-12         
 [91] whisker_0.4             fitdistrplus_1.0-14     shinyjs_1.1            
 [94] patchwork_1.0.0         lsei_1.2-0              mime_0.8               
 [97] evaluate_0.14           xtable_1.8-4            jpeg_0.1-8.1           
[100] gridExtra_2.3           compiler_3.6.2          tibble_2.1.3           
[103] KernSmooth_2.23-16      crayon_1.3.4            htmltools_0.4.0        
[106] tiff_0.1-5              mgcv_1.8-31             later_1.0.0            
[109] tidyr_1.0.0             RcppParallel_4.4.4      MASS_7.3-51.5          
[112] rappdirs_0.3.1          gdata_2.18.0            metap_1.2              
[115] igraph_1.2.4.2          pkgconfig_2.0.3         sn_1.5-4               
[118] numDeriv_2016.8-1.1     sp_1.3-2                plotly_4.9.1           
[121] xml2_1.2.2              foreach_1.4.7           multtest_2.42.0        
[124] webshot_0.5.2           XVector_0.26.0          bibtex_0.4.2.2         
[127] stringr_1.4.0           digest_0.6.23           sctransform_0.2.1      
[130] RcppAnnoy_0.0.14        tsne_0.1-3              spatstat.data_1.4-0    
[133] rmarkdown_2.0           leiden_0.3.1            uwot_0.1.5             
[136] gdtools_0.2.1           shiny_1.4.0             gtools_3.8.1           
[139] lifecycle_0.1.0         nlme_3.1-143            jsonlite_1.6           
[142] viridisLite_0.3.0       pillar_1.4.3            lattice_0.20-38        
[145] fastmap_1.0.1           httr_1.4.1              plotrix_3.7-7          
[148] survival_3.1-8          glue_1.3.1              spatstat_1.62-2        
[151] png_0.1-7               iterators_1.0.12        stringi_1.4.5          
[154] caTools_1.17.1.4        irlba_2.3.3             future.apply_1.4.0     
[157] ape_5.3