Data Input
spacedeconv_data.RmdIntroduction
spacedeconv integrates first- and second-generation deconvolution algorithms for transcriptome data. While first-generation tools deconvolute based on internal precomputed signatures, second-generation deconvolution tools compute cell type specific expression signatures from annotated single-cell expression data. In the following requirements and workflow details for both types of data are explained in detail.
Example Data
spacedeconv contains 4 different spatial datasets obtained with the 10XVisium platform. Additionally there are 4 matching scRNA-seq datasets available which can be used to calculate custom expression signatures. The data can be loaded like this:
library(spacedeconv)
#> → Setting up spacedeconv environment..
#> → Using conda environment 'r-omnideconv'
data("single_cell_data_1")
data("single_cell_data_2")
data("single_cell_data_3")
data("single_cell_data_4")
data("spatial_data_1")
data("spatial_data_2")
data("spatial_data_3")
data("spatial_data_4")
Reference Data
To build cell-type specific signatures for second-generation deconvolution spacedeconv utilized annotated single-cell reference data. Your single cell data needs to include cell-type annotations and can be one of the following formats:
- SingleCellExperiment (recommended)
- Seurat
Cell type information needs to be available. You can specify the
column containing the annotation with the
cell_type_col parameter. The same applies to batch ID
information required for CARD with the parameter
batch_id_col.
signature <- build_model(single_cell_data_1,
method = "spatialdwls",
cell_type_col = "celltype_major",
)
# some methods require batch_id information as well
sigature <- build_model(single_cell_data_1,
method = "cell2location",
cell_type_col = "celltype_major",
batch_id_col = "orig.ident"
)
Spatial Data
Spatially resolved data needs to be available in the SpatialExperiment format. For 10XVisium slides the data can be loaded easily by providing the path to the directory create by SpaceRanger. More information about data loading and manual object construction can be found in the SpatialExperiment Vignette.
spe <- SpatialExperiment::read10xVisium(path_to_directory)
Spatial data available as a Seurat Object can be converted into a SpatialExperiment:
spe <- seurat_to_spatialexperiment(seurat_object)
Normalization
SpaceDeconv offers an additional function for convenient
normalization of SpatialExperiments. The normalization is saved in
a new assay, so make sure the correct data is used during
deconvolution by providing the desired assay with the parameters
assay_sc and assay_sp. As normalization
method cpm and logcpm are available.
spe <- spacedeconv::preprocess(spatial_data_1)
#> ── spacedeconv ─────────────────────────────────────────────────────────────────
#> ℹ testing parameter
#> ✔ parameter OK [64ms]
#>
#> ℹ Removing 247 observations with umi count below threshold
#> ✔ Removed 247 observations with umi count below threshold [193ms]
#>
#> ℹ Removing 13479 variables with all zero expression
#> Warning in spacedeconv::preprocess(spatial_data_1): There are 13 mitochondrial
#> genes present. Consider removing them.
#> ✔ Removed 13479 variables with all zero expression [820ms]
#>
#> ℹ Checking for ENSEMBL Identifiers
#> ! Warning: ENSEMBL identifiers detected in gene names
#> ℹ Checking for ENSEMBL Identifiersℹ Consider using Gene Names for first-generation deconvolution tools
#> ℹ Checking for ENSEMBL Identifiers✔ Finished Preprocessing [9ms]
spe <- normalize(spe, method = "cpm")
#> ── spacedeconv ─────────────────────────────────────────────────────────────────
#> ℹ testing parameter
#> ✔ parameter OK [16ms]
#>
#> ℹ Normalizing using cpm
#> ✔ Finished normalization using cpm [2.1s]
#>
#> ℹ Please note the normalization is stored in an additional assay
# make sure to use cpm assay in deconvolution step
deconvolution <- deconvolute(spe, method = "quantiseq", assay_sp = "cpm")
#> ── spacedeconv ─────────────────────────────────────────────────────────────────
#> ℹ testing parameter
#> ✔ parameter OK [22ms]
#>
#>
#>
#> ── Spatial
#> Assays: "counts" and "cpm"
#> Genes: 23112
#> → without expression: 0 (0%)
#> Spots: 2467
#> Spots under tissue: 2467 (100%)
#> Median Genes Per Spot: 3329
#> → without expression: 0 (0%)
#> Umi count range: 500 - 58175
#> Spots with UMI count below 500: 0 (0%)
#> ✔ Rownames set
#> ✔ Colnames set
#> ℹ deconvoluting
#>
#> >>> Running quantiseq
#>
#> Running quanTIseq deconvolution module
#>
#> Gene expression normalization and re-annotation (arrays: FALSE)
#>
#> Removing 17 noisy genes
#>
#> Removing 15 genes with high expression in tumors
#>
#> Signature genes found in data set: 134/138 (97.1%)
#>
#> Mixture deconvolution (method: lsei)
#>
#> Deconvolution successful!
#> ✔ finished [28.3s]
Image Alignment
In case the background image is not aligned properly the SpatialExperiment class offers convenient functions for rotation / mirroring:
rotateImg(image, degrees)mirrorImg(image, axis) # 'h'/'v'
More Information is available in the SpatialExperiment Documentation