iSpatail Tutorial

Load package

Install iSpatial package from Github. iSpatial is based on Seurat, you need install Seurat first .

# install iSpatial package
# devtools::install_github("Czh3/iSpatial")

# load
library(iSpatial)

library(Seurat)
library(ggplot2)

Load data

Load scRNA-seq and STARmap of Mouse Cortex. scRNA-seq is downlaod from Allen Brain STARmap is from Xiao et al.

# scRNA-seq data
# scRNA_VISp can be download from: https://www.dropbox.com/s/kej7wj2k7hvy5o2/Cortex_scRNA.RDS?dl=0
# use "readRDS" to load

# STARmap data
# starmap can be download from: https://www.dropbox.com/s/yjcp49djv1zbqo6/Cortex_starmap.RDS?dl=0

Normalize data

The data need be log normalized.

# scRNA-seq data
scRNA_VISp = NormalizeData(scRNA_VISp, verbose = FALSE)

# merFISH data
starmap = NormalizeData(starmap, verbose = FALSE)

infer transcriptome-wide spatial expression

# infer spatial transcriptome
starmap_iSpatial = iSpatial::infer(starmap, scRNA_VISp)
## Stablize spatial transcriptome.
## 1st level integration
## Merging dataset 1 into 2
## Extracting anchors for merged samples
## Finding integration vectors
## Finding integration vector weights
## Integrating data
## normalization
## 2nd level integration
## Computing nearest neighbors
## Only one graph name supplied, storing nearest-neighbor graph only
## infer expression.

enhance expression

# cell type makers 
p1 = FeaturePlot(starmap, features = c("Slc17a7", "Gad1", "Plp1", "Aqp4", "Cldn5"), pt.size = 1, ncol=5)  & NoAxes() &
  theme(legend.position = "none") &
  scale_color_gradientn(colours = c(rainbow(10)[5:10], "red"))

starmap_iSpatial[["umap"]] = starmap[["umap"]]
p2 = FeaturePlot(starmap_iSpatial, features = c("Slc17a7", "Gad1", "Plp1", "Aqp4", "Cldn5"), pt.size = 1, ncol=5)  & NoAxes() &
  theme(legend.position = "none") &
  scale_color_gradientn(colours = c(rainbow(10)[5:10], "red"))
p1 / p2

plot of chunk enhance

# layer makers
g = c( "Cux2", "Nov", "Rorb", "Rspo1", "Fezf2", "Foxp2", "Ctgf", "Plp1")

# raw
SpatialFeaturePlot(starmap, features = g, stroke = 0, 
                        pt.size.factor = 4, 
                        crop = T, slot = "data",
                        ncol = 4) &
    theme_void() & theme(legend.position = "none") & coord_flip() &
    scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red", "red2")) 

plot of chunk enhance

# inferred
SpatialFeaturePlot(starmap_iSpatial, features = g, stroke = 0, 
                        pt.size.factor = 4, 
                        crop = T, slot = "data",
                        ncol = 4) &
    theme_void() & theme(legend.position = "none") & coord_flip() &
    scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red", "red2")) 

plot of chunk enhance

infer nontargeted gene

# infer
g = c("Pvrl3", "Evc2", "Tshz1", "Adra1d", "Serinc2", "Col5a1", "Mag", "Ugt8a")
SpatialFeaturePlot(starmap_iSpatial, features = g, stroke = 0, 
                        pt.size.factor = 4, 
                        crop = T, slot = "data",
                        ncol = 4) &
    theme(legend.position = "none") & coord_flip() &
    scale_fill_gradientn(colours = c(rainbow(10)[5:10], "red", "red2")) 

plot of chunk infer

sessionInfo()
## R version 4.0.5 (2021-03-31)
## Platform: x86_64-conda-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
## 
## Matrix products: default
## BLAS/LAPACK: /netscr/chaozhang/miniconda3/lib/libopenblasp-r0.3.18.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
##  [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
##  [1] grid      parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] iSpatial_1.0.0              ggrepel_0.9.1               gatepoints_0.1.4            sctransform_0.3.2           KernSmooth_2.23-20         
##  [6] viridisLite_0.4.0           spam_2.7-0                  dotCall64_1.0-1             DoubletFinder_2.0.3         dplyr_1.0.7                
## [11] SeuratData_0.2.1            data.table_1.14.2           devtools_2.4.2              usethis_2.1.3               DiffBind_3.0.15            
## [16] SummarizedExperiment_1.20.0 MatrixGenerics_1.2.1        matrixStats_0.61.0          GenomicRanges_1.42.0        GenomeInfoDb_1.26.4        
## [21] enrichR_3.0                 enrichplot_1.12.2           org.Mm.eg.db_3.13.0         AnnotationDbi_1.54.1        IRanges_2.26.0             
## [26] S4Vectors_0.30.0            Biobase_2.52.0              BiocGenerics_0.40.0         clusterProfiler_4.0.2       SeuratObject_4.0.2         
## [31] Seurat_4.0.5                ggplot2_3.3.5               rliger_1.0.0                patchwork_1.1.1             Matrix_1.3-4               
## [36] cowplot_1.1.1              
## 
## loaded via a namespace (and not attached):
##   [1] ica_1.0-2                apeglm_1.12.0            ps_1.6.0                 Rsamtools_2.6.0          rsvg_2.1.2               rprojroot_2.0.2         
##   [7] foreach_1.5.1            lmtest_0.9-38            crayon_1.4.2             V8_4.0.0                 spatstat.core_2.3-1      MASS_7.3-54             
##  [13] nlme_3.1-153             backports_1.3.0          GOSemSim_2.18.1          rlang_0.4.12             XVector_0.32.0           ROCR_1.0-11             
##  [19] irlba_2.3.3              callr_3.7.0              limma_3.46.0             GOstats_2.56.0           BiocParallel_1.26.1      rjson_0.2.20            
##  [25] bit64_4.0.5              harmony_1.0              glue_1.4.2               mixsqp_0.3-43            pheatmap_1.0.12          processx_3.5.2          
##  [31] spatstat.sparse_2.0-0    SeuratDisk_0.0.0.9019    base64url_1.4            DOSE_3.18.1              spatstat.geom_2.3-0      tidyselect_1.1.1        
##  [37] fitdistrplus_1.1-6       XML_3.99-0.8             tidyr_1.1.4              zoo_1.8-9                GenomicAlignments_1.26.0 xtable_1.8-4            
##  [43] magrittr_2.0.1           evaluate_0.14            cli_3.1.0                zlibbioc_1.38.0          hwriter_1.3.2            rstudioapi_0.13         
##  [49] miniUI_0.1.1.1           rpart_4.1-15             GreyListChIP_1.22.0      fastmatch_1.1-3          treeio_1.16.1            shiny_1.7.1             
##  [55] xfun_0.28                askpass_1.1              pkgbuild_1.2.0           cluster_2.1.2            caTools_1.18.2           tidygraph_1.2.0         
##  [61] KEGGREST_1.32.0          tibble_3.1.5             ape_5.5                  listenv_0.8.0            Biostrings_2.60.2        png_0.1-7               
##  [67] future_1.23.0            withr_2.4.2              bitops_1.0-7             ggforce_0.3.3            RBGL_1.66.0              plyr_1.8.6              
##  [73] GSEABase_1.52.1          pROC_1.18.0              coda_0.19-4              pillar_1.6.4             gplots_3.1.1             cachem_1.0.5            
##  [79] GenomicFeatures_1.42.2   fs_1.5.0                 hdf5r_1.3.3              vctrs_0.3.8              ellipsis_0.3.2           generics_0.1.1          
##  [85] tools_4.0.5              munsell_0.5.0            tweenr_1.0.2             fgsea_1.18.0             DelayedArray_0.16.3      fastmap_1.1.0           
##  [91] compiler_4.0.5           pkgload_1.2.3            abind_1.4-5              httpuv_1.6.3             rtracklayer_1.50.0       sessioninfo_1.2.1       
##  [97] plotly_4.10.0            GenomeInfoDbData_1.2.6   gridExtra_2.3            edgeR_3.32.1             riverplot_0.10           lattice_0.20-45         
## [103] deldir_1.0-6             AnnotationForge_1.32.0   utf8_1.2.2               later_1.2.0              BiocFileCache_1.14.0     jsonlite_1.7.2          
## [109] scales_1.1.1             graph_1.68.0             tidytree_0.3.4           pbapply_1.5-0            genefilter_1.72.1        lazyeval_0.2.2          
## [115] promises_1.2.0.1         doParallel_1.0.16        latticeExtra_0.6-29      goftest_1.2-3            spatstat.utils_2.2-0     reticulate_1.22         
## [121] brew_1.0-6               checkmate_2.0.0          rmarkdown_2.11           Rtsne_0.15               downloader_0.4           BSgenome_1.58.0         
## [127] uwot_0.1.10              igraph_1.2.7             survival_3.2-13          numDeriv_2016.8-1.1      yaml_2.2.1               ashr_2.2-54             
## [133] SQUAREM_2021.1           htmltools_0.5.2          memoise_2.0.0            VariantAnnotation_1.36.0 locfit_1.5-9.4           graphlayouts_0.7.1      
## [139] batchtools_0.9.15        digest_0.6.28            assertthat_0.2.1         mime_0.12                rappdirs_0.3.3           emdbook_1.3.12          
## [145] RSQLite_2.2.7            amap_0.8-18              future.apply_1.8.1       remotes_2.4.1            blob_1.2.2               labeling_0.4.2          
## [151] ggsci_2.9                splines_4.0.5            RCurl_1.98-1.3           hms_1.1.1                colorspace_2.0-2         BiocManager_1.30.16     
## [157] aplot_0.0.6              Rcpp_1.0.7               mclust_5.4.9             RANN_2.6.1               mvtnorm_1.1-3            fansi_0.5.0             
## [163] truncnorm_1.0-8          parallelly_1.28.1        R6_2.5.1                 ggridges_0.5.3           lifecycle_1.0.1          ShortRead_1.48.0        
## [169] curl_4.3.2               testthat_3.1.0           leiden_0.3.9             DO.db_2.9                qvalue_2.24.0            desc_1.4.0              
## [175] RcppAnnoy_0.0.19         RColorBrewer_1.1-2       iterators_1.0.13         stringr_1.4.0            DOT_0.1                  htmlwidgets_1.5.4       
## [181] markdown_1.1             polyclip_1.10-0          biomaRt_2.46.3           purrr_0.3.4              shadowtext_0.0.8         mgcv_1.8-38             
## [187] globals_0.14.0           openssl_1.4.5            bdsmatrix_1.3-4          codetools_0.2-18         invgamma_1.1             GO.db_3.13.0            
## [193] FNN_1.1.3                gtools_3.9.2             prettyunits_1.1.1        dbplyr_2.1.1             gtable_0.3.0             DBI_1.1.1               
## [199] highr_0.9                tensor_1.5               httr_1.4.2               stringi_1.7.5            progress_1.2.2           reshape2_1.4.4          
## [205] farver_2.1.0             annotate_1.68.0          viridis_0.6.1            Rgraphviz_2.34.0         ggtree_3.0.2             xml2_1.3.2              
## [211] rvcheck_0.1.8            bbmle_1.0.24             systemPipeR_1.24.3       Category_2.56.0          scattermore_0.7          bit_4.0.4               
## [217] scatterpie_0.1.6         jpeg_0.1-9               spatstat.data_2.1-0      ggraph_2.0.5             pkgconfig_2.0.3          knitr_1.36