Skip to contents

spacedeconv is a unified interface for the deconvolution of spatial transcriptomics data. In total spacedeconv gives access to 31 deconvolution methods:

#> Loading required package: SingleCellExperiment
#> Loading required package: SummarizedExperiment
#> Loading required package: MatrixGenerics
#> Loading required package: matrixStats
#> 
#> Attaching package: 'MatrixGenerics'
#> The following objects are masked from 'package:matrixStats':
#> 
#>     colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
#>     colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
#>     colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
#>     colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
#>     colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
#>     colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
#>     colWeightedMeans, colWeightedMedians, colWeightedSds,
#>     colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
#>     rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
#>     rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
#>     rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
#>     rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
#>     rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
#>     rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
#>     rowWeightedSds, rowWeightedVars
#> Loading required package: GenomicRanges
#> Loading required package: stats4
#> Loading required package: BiocGenerics
#> 
#> Attaching package: 'BiocGenerics'
#> The following object is masked from 'package:spacedeconv':
#> 
#>     normalize
#> The following objects are masked from 'package:stats':
#> 
#>     IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#> 
#>     anyDuplicated, aperm, append, as.data.frame, basename, cbind,
#>     colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
#>     get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
#>     match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
#>     Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
#>     table, tapply, union, unique, unsplit, which.max, which.min
#> Loading required package: S4Vectors
#> 
#> Attaching package: 'S4Vectors'
#> The following object is masked from 'package:utils':
#> 
#>     findMatches
#> The following objects are masked from 'package:base':
#> 
#>     expand.grid, I, unname
#> Loading required package: IRanges
#> Loading required package: GenomeInfoDb
#> Loading required package: Biobase
#> Welcome to Bioconductor
#> 
#>     Vignettes contain introductory material; view with
#>     'browseVignettes()'. To cite Bioconductor, see
#>     'citation("Biobase")', and for packages 'citation("pkgname")'.
#> 
#> Attaching package: 'Biobase'
#> The following object is masked from 'package:MatrixGenerics':
#> 
#>     rowMedians
#> The following objects are masked from 'package:matrixStats':
#> 
#>     anyMissing, rowMedians
#>             RCTD        SPOTlight             CARD      spatialDWLS 
#>           "rctd"      "spotlight"           "card"    "spatialdwls" 
#>    cell2location        AutoGeneS       BayesPrism           Bisque 
#>  "cell2location"      "autogenes"     "bayesprism"         "bisque" 
#>          BSeq-sc       CIBERSORTx            CDSeq              CPM 
#>         "bseqsc"     "cibersortx"          "cdseq"            "cpm" 
#>             DWLS             MOMF            MuSiC           Scaden 
#>           "dwls"           "momf"          "music"         "scaden" 
#>             SCDC       MCPcounter             EPIC        quanTIseq 
#>           "scdc"    "mcp_counter"           "epic"      "quantiseq" 
#>            xCell        CIBERSORT CIBERSORT (abs.)            TIMER 
#>          "xcell"      "cibersort"  "cibersort_abs"          "timer" 
#>     ConsensusTME             ABIS         ESTIMATE      mMCPcounter 
#>  "consensus_tme"           "abis"       "estimate"   "mmcp_counter" 
#>        seqImmuCC              DCQ             BASE 
#>      "seqimmucc"            "dcq"           "base"

Sample Data

For this tutorial we will use one of spacedeconvs sample dataset and the deconvolution algorithm “SCDC”.

data("single_cell_data_3")
data("spatial_data_3")

Preprocessing and Normalization

To get a first insight into the data we type the dataset name into the terminal:

single_cell_data_3

# for performance reasons we are subsampling the data


# single_cell_data_3 <- subsetSCE(single_cell_data_3, cell_type_col = "celltype_major", ncells = 180)

We can see that the single-cell data is available as a SingleCellExperiment. In total this dataset includes expression values from 29733 genes and 7986 cells. It can further be seen that cell type information is available in colData where cell related annotation is stored.

As the next step we normalize the data as cpm (“Counts Per Million”). The normalization is stored as an additional assay in the single-cell object.

single_cell_data_3 <- spacedeconv::preprocess(single_cell_data_3)
spatial_data_3 <- spacedeconv::preprocess(spatial_data_3)

single_cell_data_3 <- spacedeconv::normalize(single_cell_data_3, method = "cpm")
spatial_data_3 <- spacedeconv::normalize(spatial_data_3, method = "cpm")

Build Model

To build a model we need to provide a single cell expression object annotated with cell type information. Let’s have a look into the object to see which annotation is available.

names(colData(single_cell_data_3))
#>  [1] "Sample"          "Barcode"         "orig.ident"      "nCount_RNA"     
#>  [5] "nFeature_RNA"    "percent.mito"    "subtype"         "celltype_subset"
#>  [9] "celltype_minor"  "celltype_major"

There are three different resolutions of cell type annotation available. For this tutorial we will choose "celltype_major" as cell type annotation which includes 9 different cell-types.

Next we can calculate a signature using the annotated single-data and the deconvolution tool “spatialDWLS”.

signature <- spacedeconv::build_model(
  single_cell_obj = single_cell_data_3,
  cell_type_col = "celltype_major",
  method = "dwls", verbose = T, dwls_method = "mast_optimized", ncores = 10
)
signature <- readRDS(system.file("extdata", "signature_dwls.rds", package = "spacedeconv"))

The signature contains expression values for all celltypes and a subset of distinctly expressed genes. The following example shows the first 10 rows of the signature calculated in the previous step.

knitr::kable(round(signature[1:10, ], 4))
Endothelial CAFs PVL B-cells Plasmablasts T-cells Myeloid Cancer Epithelial Normal Epithelial
ACKR1 15.1019 0.0086 0.0110 0.0081 0.0208 0.0082 0.0118 0.0089 0.0068
PLVAP 13.4028 0.0172 0.0110 0.0081 0.1250 0.0112 0.1853 0.0168 0.0068
RBP7 10.5972 0.0103 0.0110 0.0027 0.8125 0.0055 0.1103 0.0213 0.3038
RAMP2 9.1157 0.2646 0.0440 0.0027 0.1250 0.0048 0.0176 0.0492 0.0817
FABP4 30.1806 0.1134 9.7582 0.0434 1.5000 0.0186 2.3059 0.2864 0.0272
AQP1 7.3241 0.2354 0.0549 0.0054 0.1250 0.0057 0.0118 0.0190 0.0518
VWF 5.4907 0.0017 0.0000 0.0027 0.0208 0.0021 0.0059 0.0089 0.0041
SDPR 5.7500 0.0052 0.3626 0.0000 0.0833 0.0032 0.0206 0.0268 0.0463
CLEC14A 4.8843 0.1340 0.0440 0.0108 0.0208 0.0021 0.0044 0.0078 0.0041
EMCN 3.8287 0.0155 0.0330 0.0027 0.0000 0.0018 0.0029 0.0045 0.0027

Deconvolution

To deconvolute the Visium slide we use the signature we just calculated. Depending on the selected deconvolution tool further parameters need to be passed, in this case cell_type_col and batch_id_col as well as the scRNA-seq reference dataset.

deconv <- spacedeconv::deconvolute(
  spatial_obj = spatial_data_3,
  single_cell_obj = single_cell_data_3,
  cell_type_col = "celltype_major",
  method = "dwls",
  signature = signature,
  assay_sp = "cpm"
)

Visualization

The deconvolution results are stored in the spatial object to simplify visualizations. spacedeconv offers 6 visualization functions with different scopes, further explained in the visualization vignette.

We can see the available deconvolution results by using available_results(deconv) or by accessing the objects colData:

available_results(deconv)
#> [1] "dwls_B.cells"           "dwls_CAFs"              "dwls_Cancer.Epithelial"
#> [4] "dwls_Endothelial"       "dwls_Myeloid"           "dwls_Normal.Epithelial"
#> [7] "dwls_Plasmablasts"      "dwls_PVL"               "dwls_T.cells"

For each Spot the estimated cell fraction is available as object annotation and can be used for visualizations.

# plot all available results: provide the tool as parameter
spacedeconv::plot_celltype(deconv,
  cell_type = "dwls_B.cells",
  density = FALSE,
  smooth = T,
  title_size = 12
)

# ... or plot a specific result
# spacedeconv::plot_celltype(deconv,
#   cell_type = "card_Cancer.Epithelial",
#   density = FALSE,
#   smooth = T,
#   title_size = 12
# )