Spatial transcriptomics visualization using scimap

1 minute read

Author: Kévin Lebrigand

Ressources

  • scimap is a scalable toolkit for analyzing spatial molecular data. The underlying framework is generalizable to spatial datasets mapped to XY coordinates. The package uses the anndata framework making it easy to integrate with other popular single-cell analysis toolkits. It includes preprocessing, phenotyping, visualization, clustering, spatial analysis and differential spatial testing. The Python-based implementation efficiently deals with large datasets of millions of cells.

  • scanpy is a scalable toolkit for analyzing single-cell gene expression data built jointly with anndata. It includes preprocessing, visualization, clustering, trajectory inference and differential expression testing. The Python-based implementation efficiently deals with datasets of more than one million cells.

  • anndata is a Python package for handling annotated data matrices in memory and on disk, positioned between pandas and xarray. anndata offers a broad range of computationally efficient features including, among others, sparse data support, lazy operations, and a PyTorch interface.

  • spatialdata is a data framework that comprises a FAIR storage format and a collection of python libraries for performant access, alignment, and processing of uni- and multi-modal spatial omics datasets. This page provides documentation on how to install, use, and extend the core spatialdata library

Import required package in a python notebook

import scimap as sm
import anndata as ad
import spatialdata as sd
from spatialdata import SpatialData

Read a spatial experiment object as Anndata object

You might refers to previous blog posts on spatial transcriptomics data analysis to produce such a .h5ad anndata file or spatialdata object that contains the analysis of a spatial transcriptomics experiment.

sdata = SpatialData.read("PGW9-2-5P-r1_sdata")

Use scimap to visualize cells within the UMAP and it’s real spatial position into the tissue slice


# init color palette
cats = sdata.table.obs['cell_type'].cat.categories.tolist()
colors = list(sdata.table.uns['cell_type' + "_colors"])
mypal = dict(zip(cats, colors))

sm.hl.animate (sdata.table, color='cell_type', embedding='X_umap', palette=mypal,
               x_coordinate='center_x', y_coordinate='center_y',n_frames=150,
               interval=150, final_frame=50, title='Fetal head (PGW9)', alpha=1,
               plot_legend=True, fontsize=8, s=1, pltStyle='dark_background',
               figsize=(10, 8), watermark=False, save_animation="test.gif")

Form UMAP to spatial cell positionment of fetal head (PGW9)