Atera kidney: reopen a saved Clerk case¶
Clerk is Celldega's AI tool for interpreting its visualizations. A conversation with Clerk is saved as a case: its questions and answers, the evidence behind them, the cell types it proposed, and the labels it put on the Clustergram. This notebook reopens a saved case about the default Leiden clusters of a human kidney section, reading it straight from Hugging Face.
Reopening a case needs no Claude: the panel shows the whole conversation, and its genes, clusters and cited views change the Landscape and Clustergram. Asking a new question continues the case, and that needs Claude (see Clerk).
The data are the public 10x Genomics Atera WTA FFPE human non-diseased kidney
dataset, from
the same prepared DegaFiles
as the Atera kidney tutorial.
The case is the clerk/atera_kidney
folder of Celldega's supporting data, and the Clerk gallery
page shows the same case without Python.
This example requires Celldega 0.29.1 or later: pip install "celldega>=0.29.1".
from urllib.request import urlopen
import numpy as np
import celldega as dega
SAMPLE = "Atera_v1_WTA_Kidney_non_diseased_FFPE"
DATA_REVISION = "3a46ab4db67821eef3b8ff8d1c3704fb7b3bb48f"
BASE_URL = f"https://raw.githubusercontent.com/broadinstitute/Celldega_{SAMPLE}/{DATA_REVISION}"
# The saved case: a folder with the conversation and the clustered marker Matrix.
CASE_URL = (
"https://huggingface.co/datasets/broadinstitute/Celldega_Supporting_Data/"
"resolve/main/clerk/atera_kidney/"
)
1. Make the views the case was saved with¶
The Landscape streams the tissue from the DegaFiles, and the Clustergram reads the
case's marker Matrix (Leiden clusters × marker genes) from Hugging Face. The
Clustergram shows the case's labels as cell_type column categories and the
marker genes behind them as info row categories.
with urlopen(f"{BASE_URL}/micron_to_image_transform.csv") as response:
transform = np.loadtxt(response)
landscape = dega.viz.Landscape(
technology="Xenium", base_url=BASE_URL, transform=transform,
dataset_name="Atera kidney — default clusters", height=600, max_tiles_to_view=25,
)
cgm = dega.viz.Clustergram(
matrix=dega.clust.Matrix.read_zarr(f"{CASE_URL}kidney_leiden_markers.zarr"),
width=400, height=500, rank_dim=10,
manual_col_cat="cell_type", manual_row_cat="info",
)
2. Reopen the case¶
clerk_files takes the case folder's URL (or a local folder, or a saved
conversation .json). Passing the widgets puts the case's labels on the
Clustergram and each question's view on the Landscape as a pin (PINS).
clerk = dega.viz.Clerk(clerk_files=CASE_URL, landscape=landscape, clustergram=cgm)
print(f"{len(clerk.messages)} messages, {len(landscape.pins)} pins, "
f"{len(clerk.findings)} cell-type proposals")
38 messages, 6 pins, 21 cell-type proposals
linked = dega.viz.spatial_clustergram(landscape, cgm, width="500px", clerk=clerk)
linked
Click a gene or cluster in Clerk's answers to show it in the Landscape and Clustergram, or Show this view under a question to return to the view it was asked about.
3. The cell types¶
One row per cluster: the label on the Clustergram and who set it, and Clerk's latest proposal with its confidence.
clerk.cell_types()
| cluster | label | set_by | clerk_proposal | confidence | |
|---|---|---|---|---|---|
| 0 | 5 | Mesangial / glomerular stromal cell | medium | ||
| 1 | 10 | Thick ascending limb | Clerk | Thick ascending limb | high |
| 2 | 12 | Collecting duct principal cell | Clerk | Collecting duct principal cell | high |
| 3 | 13 | Peritubular capillary endothelium | Clerk | Peritubular capillary endothelium | medium |
| 4 | 14 | Connecting tubule | Clerk | Connecting tubule | medium |
| 5 | 16 | Podocyte | Clerk | Podocyte | high |
| 6 | 18 | Intercalated cell (with PC signal) | Clerk | Intercalated cell (with PC signal) | medium |
| 7 | 20 | Glomerular endothelium | Clerk | Glomerular endothelium | medium |
| 8 | 23 | Thick ascending limb (cortical, incl. macula d... | Clerk | Thick ascending limb (cortical, incl. macula d... | medium |
| 9 | 25 | Arteriolar endothelium | Clerk | Arteriolar endothelium | low |
| 10 | 26 | Intercalated cell | Clerk | Intercalated cell | high |