Jupyter Notebook Examples
These example notebooks demonstrate how to use Celldega for spatial transcriptomics analysis and visualization. Each notebook is designed to be run in a Jupyter environment and showcases different features of the library.
Tutorials
Comprehensive tutorials that walk through complete workflows:
- Atera Breast Cancer Landscape-Clustergram - Loads a precomputed Scanpy clustering (or optionally recomputes it) and creates linked Landscape, Clustergram, and Enrich widgets
- Atera Breast Cancer Neighborhood Exploration - Continues the Atera tutorial with hextile niches linked to cell-type composition and alpha-shape overlap linked to a separate Landscape
- Visium HD Human CRC Landscape-Clustergram-Enrich - Builds a SetCollection from a clustered Visium HD colorectal cancer sample (signatures, fraction expressing, marker genes) and explores it in linked Landscape, Clustergram, and Enrich widgets, ready for interactive annotation
- Scanpy-Squidpy Xenium Pancreas - Full analysis workflow using Scanpy and Squidpy with Xenium data
- Preprocess DegaFiles and Viz Pancreas - Preprocessing raw Xenium Pancreas data into DegaFiles and visualizing the result in a Landscape widget
- Chromium PBMC Landscape-Clustergram-Enrich - Downloads a 10x PBMC count matrix, clusters cells with Scanpy, and builds a SetCollection with expression signatures, fraction expressing, and marker-ranked Clustergram views linked to a UMAP Landscape and Enrich, plus a single-cell Clustergram linked to Enrich
Brief Notebooks
Focused examples demonstrating specific features:
- Landscape View Xenium - Basic Landscape visualization of Xenium data
- Landscape from a Local Server - Viewing locally stored DegaFiles in a Landscape with
dega.viz.get_local_server() - Atera Viz - Linked Landscape and Clustergram visualization of a Xenium breast cancer dataset
- Yearbook-Query - Using single-cell Yearbook view
- CellCloud Thick MERFISH - 3D orbit-camera CellCloud view of thick-tissue MERFISH data
- Landscape-Heatmap Visium-HD - Combined Landscape and heatmap visualization
- UMAP-Cluster Pancreas Xenium - UMAP clustering with Xenium pancreas data
- Custom Segmentation - Using custom cell segmentation with Celldega
- NeighborhoodCollection Population Space - Creating a neighborhood collection and calculating a neighborhood-by-population modality
- Gradient Neighborhood Pancreas Islets - Building inward/outward gradient rings around pancreatic islets and profiling cell-type proportion and hormone expression with distance from the islet edge
- DatasetCollection Population Space - Creating toy dataset-level data and calculating dataset-by-population modalities
- SetCollection Cluster Space - Building a SetCollection from a Xenium clustering and clustering its per-set gene-expression signature
Running the Notebooks
Prerequisites
Install Celldega and its dependencies:
pip install celldega
For full analysis workflows, you may also need:
pip install scanpy squidpy
Embedding interactive widgets in the docs
The docs are rendered statically by mkdocs-jupyter, which displays saved widget state but does
not execute notebooks. For an interactive Landscape / Clustergram (anywidget) to appear on the
docs site, the notebook's saved widget state must be complete and its model IDs must match the cell
outputs.
A plain "Run All + Save" in Jupyter Lab is unreliable for this: each Landscape streams a large
message (the embedded JS bundle plus the data parquet), and the state is only captured if the widget
has fully finished rendering in the browser before you save. Editing a cell and saving without a
full re-execution leaves stale or missing state, and the widgets render blank.
The reliable way to (re)build a docs notebook so its widgets embed is to execute it headless with a
raised iopub_timeout so those large messages aren't dropped:
jupyter nbconvert --to notebook --execute --inplace \
--ExecutePreprocessor.timeout=900 \
--ExecutePreprocessor.iopub_timeout=120 \
docs/examples/brief_notebooks/<Notebook>.ipynb
Tips:
- Put each widget as the only expression in its own cell (separate from its construction) — anywidget embeds most reliably that way.
- Don't add
%env ANYWIDGET_HMR=1to a docs notebook. That dev-time hot-reload watches and reloads the widget's frontend module; running it while the frontend bundle is being rebuilt can desync the saved model IDs from the cell outputs. - To confirm a notebook is good, check that every
application/vnd.jupyter.widget-view+jsonmodel_idin the cell outputs also exists inmetadata.widgets["application/vnd.jupyter.widget-state+json"].state.
Online Resources
You can also run Celldega notebooks in the cloud: