Skip to contents

License: GPL-3.0 RPythonPlatform

spacedeconv is a unified interface to first- and second-generation deconvolution tools with focus on spatial transcriptomics datasets. The package is able to directly estimate celltype proportions of immune cells and can deconvolute any celltype if an annotated single-cell reference dataset is available.

⬇️ Installation

System requirements

The supplied Conda environment targets 64-bit Linux (x86_64) and uses R 4.3.3 and Python 3.10. In principle, all supported deconvolution methods can run on a single CPU core. CPU parallelism can be configured for RCTD (n_cores), Rectangle (n_cpus), and xCell (parallel.sz, passed through immunedeconv). cell2location can run on a CPU with gpu = FALSE, although we recommend a CUDA-compatible NVIDIA GPU for this method. Memory and runtime depend on the method and on the numbers of spots, genes, and reference cells.

Install with Conda

Since many different packages need to be included, we highly recommend to install spacedeconv in a new Conda environment with the following commands.

First, a tool for fast dependency resolution is needed, therefore we recommend installing micromamba (or mamba / conda with libmamba solver) if not already available:

"${SHELL}" <(curl -L micro.mamba.pm/install.sh)

Download the environment file and the R installer, create the Conda environment, and run the installer in that environment.

wget https://raw.githubusercontent.com/omnideconv/spacedeconv/main/tools/{environment.yml,install.R}
micromamba env create -f environment.yml --channel-priority flexible
micromamba run -n spacedeconv-env Rscript install.R

The installer adds the remaining R packages and installs spacedeconv from the repository’s main branch.

✨ Features

  • Unified access to first- and second-generation deconvolution tools
  • Direct deconvolution of immune cells
  • Compute custom reference signatures to deconvolute any celltype
  • Flexible visualization functions
  • Resource optimization
  • Pathway and Transcription Factor analysis (decoupleR integration)
  • Ligand-Receptor analysis
  • Easy integration into spatial transcriptomics workflows

spacedeconv summary diagram

💾 Data requirements

Spatial transcriptomics data: SpatialExperiment

Single-cell data with cell-type annotation: SingleCellExperiment (recommended) or Seurat

🧑‍💻 Usage

The main workflow consists of the following steps:

1. Load datasets

To explore the package, start by loading some of the built-in example datasets.

library(spacedeconv)

# 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")

Alternatively, load data from a repository such as GitHub or Zenodo. Spatial data should be provided as a SpatialExperiment and single-cell reference data as a SingleCellExperiment. The example below downloads the same spatial_data_3 and single_cell_data_3 objects from GitHub. For more information on importing single-cell reference data, see the AnnData/Seurat import vignette.

download.file(
  "https://raw.githubusercontent.com/omnideconv/spacedeconv/main/data/spatial_data_3.RData",
  destfile = "spatial_data_3.RData",
  mode = "wb"
)
load("spatial_data_3.RData")

download.file(
  "https://raw.githubusercontent.com/omnideconv/spacedeconv/main/data/single_cell_data_3.RData",
  destfile = "single_cell_data_3.RData",
  mode = "wb"
)
load("single_cell_data_3.RData")

2. Preprocessing

Depending on the use case, certain preprocessing steps might be necessary.

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

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

3. Build a Signature Matrix

Build a cell type specific signature matrix from annotated single-cell reference data.

signature <- spacedeconv::build_model(
  single_cell_obj = single_cell_data_3,
  cell_type_col = "celltype_major",
  method = "spatialdwls", verbose = T
)

You can see all supported deconvolution methods with spacedeconv::deconvolution_methods.

4. Deconvolution

While some methods are able to directly estimate immune cell abundances other tools require a custom reference signature.

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

5. Visualization

spacedeconv includes highly-flexible visualization functions.

plot_spatial(
  spe = deconv,
  result = "spatialdwls_B.cells",
  title = "B cells",
  density = FALSE
)

Available methods, licenses, and citations

We focused on supporting methods that have demonstrated robust performance in published benchmarking analyses, while also considering the feasibility of integration, installation, and maintenance. Results from external deconvolution tools not directly supported by spacedeconv can also be imported for downstream analysis and visualization, as demonstrated in the external deconvolution results vignette.

To balance a minimal installation burden for users with convenient access to high-performing methods, we plan to consider incorporating newly published methods upon request or through contributions from their developers, provided that independent or published benchmarking evidence demonstrates a substantial performance gain over the methods already supported.

Note that, while spacedeconv itself is free (GPL 3.0), you may need to obtain a license to use the individual methods. See the table below for more information. If you use this package in your work, please cite both our package and the method(s) you are using.

Constantin Zackl, Maria Zopoglou, Reto Stauffer, Markus Ausserhofer, Marieke E. Ijsselsteijn, Gregor Sturm, Noel Filipe da Cunha Carvalho de Miranda, Francesca Finotello. spacedeconv: deconvolution of tissue architecture from spatial transcriptomics, PREPRINT available at Research Square https://doi.org/10.21203/rs.3.rs-5102166/v1.

First-generation methods use predefined signatures or gene sets and are accessed through immunedeconv (Sturm et al., 2019; Merotto et al., 2024 for mouse deconvolution). Please cite both immunedeconv and the original method. Second-generation methods use a user-provided annotated single-cell or single-nucleus reference.

“Originally developed for” indicates the method’s original application. Bulk methods are applied to spatial spots as individual samples in spacedeconv. Species entries describe the standard references available through spacedeconv. For reference-dependent methods, species support depends on a suitable annotated reference and compatible gene identifiers.

Method Generation Originally developed for Species License Citation
MCP-counter First Bulk Human GPL-3.0 Becht E. et al. Estimating the population abundance of tissue-infiltrating immune and stromal cell populations using gene expression. Genome Biology 17, 218 (2016). https://doi.org/10.1186/s13059-016-1070-5
EPIC First Bulk Human Academic non-commercial research Racle J. et al. Simultaneous enumeration of cancer and immune cell types from bulk tumor gene expression data. eLife 6, e26476 (2017). https://doi.org/10.7554/eLife.26476
quanTIseq First Bulk Human BSD-3-Clause Finotello F. et al. Molecular and pharmacological modulators of the tumor immune contexture revealed by deconvolution of RNA-seq data. Genome Medicine 11, 34 (2019). https://doi.org/10.1186/s13073-019-0638-6
xCell First Bulk Human GPL-3.0 Aran D. et al. xCell: digitally portraying the tissue cellular heterogeneity landscape. Genome Biology 18, 220 (2017). https://doi.org/10.1186/s13059-017-1349-1
CIBERSORT First Bulk Human (LM22) Non-commercial terms Newman A.M. et al. Robust enumeration of cell subsets from tissue expression profiles. Nature Methods 12, 453–457 (2015). https://doi.org/10.1038/nmeth.3337
TIMER First Bulk Human GPL-2.0 Li B. et al. Comprehensive analyses of tumor immunity: implications for cancer immunotherapy. Genome Biology 17, 174 (2016). https://doi.org/10.1186/s13059-016-1028-7
ConsensusTME First Bulk Human GPL-3.0 Jiménez-Sánchez A. et al. Comprehensive Benchmarking and Integration of Tumor Microenvironment Cell Estimation Methods. Cancer Research 79(24), 6238–6246 (2019). https://doi.org/10.1158/0008-5472.CAN-18-3560
ABIS First Bulk Human GPL-2.0 Monaco G. et al. RNA-Seq Signatures Normalized by mRNA Abundance Allow Absolute Deconvolution of Human Immune Cell Types. Cell Reports 26(6), 1627–1640.e7 (2019). https://doi.org/10.1016/j.celrep.2019.01.041
ESTIMATE First Bulk Human GPL-2.0 Yoshihara K. et al. Inferring tumour purity and stromal and immune cell admixture from expression data. Nature Communications 4, 2612 (2013). https://doi.org/10.1038/ncomms3612
mMCP-counter First Bulk Mouse GPL-3.0 Petitprez F. et al. The murine Microenvironment Cell Population counter method to estimate abundance of tissue-infiltrating immune and stromal cell populations in murine samples using gene expression. Genome Medicine 12, 86 (2020). https://doi.org/10.1186/s13073-020-00783-w
seqImmuCC First Bulk Mouse Non-commercial terms Chen Z. et al. seq-ImmuCC: Cell-Centric View of Tissue Transcriptome Measuring Cellular Compositions of Immune Microenvironment From Mouse RNA-Seq Data. Frontiers in Immunology 9, 1286 (2018). https://doi.org/10.3389/fimmu.2018.01286
DCQ First Bulk Mouse GPL-2.0 Altboum Z. et al. Digital cell quantification identifies global immune cell dynamics during influenza infection. Molecular Systems Biology 10, 720 (2014). https://doi.org/10.1002/msb.134947
BASE First Bulk Mouse See upstream notes Varn F.S. et al. Integrative analysis of breast cancer reveals prognostic haematopoietic activity and patient-specific immune response profiles. Nature Communications 7, 10248 (2016). https://doi.org/10.1038/ncomms10248
spatialDWLS Second Spatial Reference-dependent GPL-3.0-or-later Dong R., Yuan G.C. SpatialDWLS: accurate deconvolution of spatial transcriptomic data. Genome Biology 22, 145 (2021). https://doi.org/10.1186/s13059-021-02362-7
cell2location Second Spatial Reference-dependent Apache-2.0 Kleshchevnikov V. et al. Cell2location maps fine-grained cell types in spatial transcriptomics. Nature Biotechnology 40, 661–671 (2022). https://doi.org/10.1038/s41587-021-01139-4
SPOTlight Second Spatial Reference-dependent GPL 3.0 Elosua-Bayes M. et al. SPOTlight: seeded NMF regression to deconvolute spatial transcriptomics spots with single-cell transcriptomes. Nucleic Acids Research 49(9):e50 (2021). https://doi.org/10.1093/nar/gkab043.
RCTD Second Spatial Reference-dependent GPL 3.0 Cable D.M. et al. Robust decomposition of cell type mixtures in spatial transcriptomics. Nature Biotechnology 40, 517–526 (2022). https://doi.org/10.1038/s41587-021-00830-w
CARD Second Spatial Reference-dependent GPL-3.0-or-later Ma Y., Zhou X. Spatially informed cell type deconvolution for spatial transcriptomics. Nature Biotechnology 40, 1349–1359 (2022). https://doi.org/10.1038/s41587-022-01273-7
DOT Second Spatial Reference-dependent GPL-3.0-or-later Rahimi A. et al. DOT: a flexible multi-objective optimization framework for transferring features across single-cell and spatial omics. Nature Communications 15, 4994 (2024). https://www.nature.com/articles/s41467-024-48868-z
Rectangle Second Bulk / spatial Reference-dependent BSD-3-Clause OR Commercial Eder B, Rigato I, Dietrich A, Merotto L, Sturm G, Treis T, List M, Theis FJ, Finotello F. Rectangle: robust and scalable multiscale deconvolution informed by single-cell RNA sequencing data. bioRxiv. 2026. https://doi.org/10.64898/2026.07.07.736950