InSituPy: A framework for histology-guided, multi-sample analysis of single-cell spatial transcriptomics data
InSituPy is a Python package designed to facilitate the analysis of single-cell spatial transcriptomics data. With InSituPy, you can easily load, visualize, and analyze the data, enabling and simplifying the comprehensive exploration of spatial gene expression patterns within tissue sections and across multiple samples. Currently the analysis is focused on data from the Xenium In Situ methodology but a broader range of reading functions will be implemented in the future.
!!!Warning: This repository is under very active development and it cannot be ruled out that changes might impair backwards compatibility. If you observe any such thing, please feel free to contact us to solve the problem. Thanks!
- Restructure DGE analysis on single-cell level and implement pseudobulk DGE analysis
- Aligned logic between single-cell level and pseudobulk level
- Introduces
DiffExprResultsclass to structure DGE analysis results (plus read/write) - DGE analysis divided into two parts:
tl.dgeandpl.volcano - Implement
pl.dual_fold_changefor contamination-aware DGE analysis - renamed
calculate_pseudobulktopp.pseudobulk
- Restructuring of documentation
For the latest developments check out the releases.
A interface to convert data from and to SpatialData is currently implemented and will be released soon. If you are interested in this, feel free to contact us to get early access.
A key feature of InSituPy is its hierarchical data structure, centered around the InSituExperiment and InSituData objects:
InSituData: Represents and manages at the individual sample level. It integrates all modalities of spatial omics datasets, including cellular readouts, cellular boundaries, images, transcripts, regions, and annotations.InSituExperiment: Aggregates multipleInSituDatainstances and links them with associated metadata, enabling cross-sample analysis and organization.
For detailed instructions on using InSituPy, refer to the official documentation.
InSituPy works best within Jupyter Lab or Jupyter Notebook sessions. If you are not familiar with these platforms, see the documentation of Project Jupyter.
Make sure you have Conda installed on your system before proceeding with these steps. If not, you can install Miniconda or Anaconda from https://docs.conda.io/en/latest/miniconda.html.
Create and activate a conda environment:
conda create --name insitupy python=3.10
conda activate insitupyInstall from PyPi:
pip install insitupy-spatialIf you want to use the graphical interface features powered by napari, install with the gui extra:
pip install insitupy-spatial[gui]To ensure that the InSituPy package is available as a kernel in Jupyter notebooks within your conda environment, you can follow the instructions here.
For alternative installation strategies see the documentation.
- Data storage: Store data on both the single sample level and the multi-sample level using the
InSituDataandInSituExperimentobjects. - Data Preprocessing: InSituPy provides functions for normalizing, filtering, and transforming raw in situ transcriptomics data.
- Interactive Visualization: Create interactive plots using napari to easily explore spatial gene expression patterns.
- Annotation: Annotate Xenium In Situ data in the napari viewer or import annotations from external tools like QuPath.
- Multi-sample analysis: Perform analysis on an experiment-level, i.e. with multiple samples at once.
We try to develop InSituPy alongside the Bioimage Analysis tool QuPath. QuPath has great functionalities to visualize whole slide image data, add annotations, generate segmentations or analyze signal intensities. Scripts to simplify the connection between QuPath and InSituPy, we collect here. This includes:
- Export of annotations as GEOJSON from QuPath
- Export of images as OME-TIFF from QuPath
- Collected export of data from a multiplexed IF image to be imported into InSituPy. Import can be performed using either
read_qupathorread_qupath_project. For cell and nucleus segmentation of multiplexed IF images we recommend using Instanseg.
Contributions are welcome! If you find any issues or have suggestions for new features, please open an issue, submit a pull request or contact us via our zulip chat.
If you use InSituPy in your work, please cite the preprint as follows:
InSituPy – A Framework for Histology-Guided, Multi-Sample Analysis of Single-Cell Spatial Transcriptomics Data.
Wirth, Johannes, Anna Chernysheva, Birthe Lemke, Isabel Giray, Aitana Egea Lavandera, and Katja Steiger.
bioRxiv, March 12, 2025. https://doi.org/10.1101/2025.03.07.641860.
InSituPy is licensed under the BSD-3-Clause.
InSituPy is developed and maintained by Johannes Wirth and Anna Chernysheva. Feedback is highly appreciated and hopefully InSituPy helps you with your analysis of spatial transcriptomics data. The package is thought to be a starting point to simplify the analysis of in situ sequencing data in Python and it would be exciting to integrate functionalities for larger and more comprehensive data structures. Currently, the framework focuses on the analysis of Xenium In Situ data but it is planned to integrate more methodologies and any support on this is highly welcomed.