An end-to-end spatial transcriptomics pipeline built with Scanpy and Squidpy, taking a 10x Genomics Visium slide from raw counts through quality control, clustering, marker-gene analysis, and cell-type annotation, and then mapping the annotated cell types back onto the tissue image.
| Step | Implementation |
|---|---|
| Load data | sc.datasets.visium_sge(), with var_names_make_unique() |
| Quality control | sc.pp.calculate_qc_metrics |
| Normalization | normalize_total(target_sum=1e4) + log1p |
| Dimensionality reduction | sc.pp.pca -> sc.pp.neighbors -> sc.tl.umap |
| Clustering | sc.tl.leiden |
| Marker genes | sc.tl.rank_genes_groups (cluster vs. rest), dotplot |
| Annotation | Leiden clusters mapped to cell-type labels |
| Spatial visualization | sq.pl.spatial_scatter over the tissue image |
A public 10x Visium sample loaded directly through Scanpy's
visium_sge() dataset loader, so no manual download is needed.
Quality control — total counts and genes detected per spot:
Leiden clustering in UMAP space:
Marker genes distinguishing each cluster from the rest, as a ranking and as a dotplot of mean expression and the fraction of spots expressing each gene:
Expression of the brain markers SLC17A7 (excitatory neurons), OLIG1 (oligodendrocytes), and GFAP (astrocytes) across the UMAP:
Annotated cell types, in UMAP space and mapped back onto the tissue section:
The spatial plot is the point of the whole exercise: clusters that look like abstract blobs in UMAP space resolve into contiguous, anatomically coherent regions once they are placed back on the tissue.
spatial.transcriptomic_Colab/
src/
pipeline.py the pipeline, organized into functions
pipeline_exploratory.py the original linear Colab working script
results/ generated figures (checked in)
cosmx_frontal_cortex/ figures from separate CosMx SMI work (see note)
data/ input data (not included; fetched by Scanpy)
pip install scanpy squidpy matplotlib
python src/pipeline.pypipeline.py is the maintained version. pipeline_exploratory.py keeps the
original top-to-bottom Colab script, including the intermediate steps and
annotation attempts that led to the final cluster-to-cell-type mapping.
Those four figures come from a different experiment — an R/ggplot analysis of a NanoString CosMx SMI Human Frontal Cortex dataset (cell types plotted against FOV pixel coordinates), not from the Scanpy/Squidpy Visium pipeline in this repository. They are kept in their own folder so the Visium results stay unambiguous. The full CosMx work lives in cosmx-spatial-transcriptomics.






