Plot gene expression across the 1,136,218 cells of the Tabula Sapiens atlas The Tabula Sapiens Consortium & Quake, 2024 and save your own cell selection locally, without downloading the count matrix. The atlas covers 28 human tissues from 24 donors, with counts for 60,606 genes and the authors’ labels for 180 cell types. On the authors’ UMAP, the B-cell marker MS4A1 is high in one compact region of the immune compartment and is detected in 93.2% of the 114,495 B cells, 9.0% of the plasma cells and 3.1% of the other immune cells. Saving the B cells as your own selection creates a local directory of 166 MB.
The atlas is a public CyteArc store in a Hugging Face bucket, read through its hf:// URI: each step fetches only the cell metadata and count chunks that it needs. The code needs an internet connection and CyteArc’s extra dependencies, but no credentials.
Open the atlas read-only¶
zarr_mode="r" opens the store without write access, which suits a shared, published dataset, and storage_options={"token": False} reads it anonymously. artifacts.find returns an ArtifactRef, a reference to a saved result, here the UMAP imported from the authors’ dataset; every plot below passes it as layout. I is the boolean column that marks the active cells, the cells that analyses use by default, and key="I" reads the published labels of those cells:
# Import CyteArc and its plot specifications, with libraries for tables and disk size.
from pathlib import Path
import numpy as np
import pandas as pd
import cytearc
from cytearc.plotting import (
CategoricalScale,
CellField,
ColorScale,
FeatureRef,
NormalizationSpec,
)
# Keep progress bars and routine logs out of the saved output.
cytearc.configure_output(level="ERROR", progress=False)Started: 2026-11-18T00:16:06.058039Z | Wall time: 1.423 s
# Open the atlas read-only over hf://, without a Hugging Face login.
source_uri = "hf://buckets/Nygen/cytebase/cytearc_docs/tabula_sapiens/data.zarr"
source = cytearc.DataStore(source_uri, zarr_mode="r", storage_options={"token": False})
# Find the UMAP that the authors published with the dataset.
author_umap = source.artifacts.find("embedding", imported="X_umap", from_assay="RNA")
# Read the published labels of the active cells, and summarize the atlas.
cell_labels = source.cells.to_pandas_dataframe(
["donor_id", "tissue_in_publication", "compartment", "cell_type"], key="I"
)
{
"cells": len(cell_labels),
"genes": source.RNA.feats.N,
"donors": cell_labels["donor_id"].nunique(),
"tissues": cell_labels["tissue_in_publication"].nunique(),
"cell types": cell_labels["cell_type"].nunique(),
}{'cells': 1136218,
'genes': 60606,
'donors': 24,
'tissues': 28,
'cell types': 180}Started: 2026-11-18T00:16:07.485409Z | Wall time: 7.678 s
Plot a marker in one population¶
MS4A1 encodes CD20, a surface protein of B cells. facet_by="cell_type" with groups=["B cell"] draws only the cells that the authors annotated as B cells, without writing anything to the read-only store. NormalizationSpec(transform="log1p") colors each cell by log(1 + x), where x is the number of MS4A1 counts per 1,000 counts in that cell, and quantiles=(0, 0.99) caps the color scale at the 99th percentile of the drawn cells:
# Draw MS4A1 only in the cells that the authors annotated as B cells.
source.plots.embedding(
layout=author_umap,
color_by=FeatureRef("MS4A1", label="MS4A1 in B cells, log(1 + counts per 1,000)"),
facet_by="cell_type",
groups=["B cell"],
normalization=NormalizationSpec(transform="log1p"),
color_scale=ColorScale(cmap="Reds", quantiles=(0, 0.99)),
sort_values=True,
point_size=0.5,
show_titles=False,
figsize=(6, 5),
)
Started: 2026-11-18T00:16:15.169200Z | Wall time: 12.566 s
Nearly all of the 114,495 B cells lie in one region at the lower left of the UMAP, and MS4A1 is high throughout that region.
Compare with the full atlas¶
Draw MS4A1 for all 1,136,218 cells beside the compartments that the authors assigned:
# Draw MS4A1 beside the published compartments for every cell of the atlas.
source.plots.embedding(
layout=author_umap,
color_by=[
FeatureRef("MS4A1", label="MS4A1, log(1 + counts per 1,000)"),
CellField("compartment", kind="categorical", label="Cell compartment"),
],
normalization=NormalizationSpec(transform="log1p"),
color_scale=ColorScale(cmap="Reds", quantiles=(0, 0.99)),
sort_values=True,
point_size=0.2,
n_columns=2,
figsize=(12, 5),
legend_loc="right",
)
Started: 2026-11-18T00:16:27.739069Z | Wall time: 18.221 s
MS4A1 is high in one compact region of the immune compartment, the region that holds the B cells, and faint or absent elsewhere. The color scale tops out lower than in the B-cell plot because its cap is now the 99th percentile of all cells, most of which have no MS4A1 counts.
Measure where MS4A1 is detected¶
get_cell_vals reads one gene’s values, normalized to counts per 1,000, into a NumPy array. It reads the cells in I in the order of the cell table, so the values line up with the labels read above. Group the cells by their published labels and count how often MS4A1 is detected in each group:
# Read MS4A1 for all cells, and group the cells by their published labels.
ms4a1 = source.get_cell_vals(from_assay="RNA", cell_key="I", k="MS4A1")
group = np.select(
[
cell_labels["cell_type"] == "B cell",
cell_labels["cell_type"] == "plasma cell",
cell_labels["compartment"] == "Immune",
],
["B cells", "Plasma cells", "Other immune cells"],
default="Other compartments",
)
# Count each group's cells and the share with at least one MS4A1 count.
detection = (
pd.DataFrame({"group": group, "detected": ms4a1 > 0})
.groupby("group")["detected"]
.agg(Cells="size", share="mean")
.reindex(["B cells", "Plasma cells", "Other immune cells", "Other compartments"])
)
detection["MS4A1 detected (%)"] = (100 * detection.pop("share")).round(1)
detection.index.name = None
detection| Cells | MS4A1 detected (%) | |
|---|---|---|
| B cells | 114495 | 93.2 |
| Plasma cells | 27349 | 9.0 |
| Other immune cells | 450475 | 3.1 |
| Other compartments | 543899 | 0.8 |
Started: 2026-11-18T00:16:45.964671Z | Wall time: 2.916 s
MS4A1 is detected in 93.2% of the 114,495 B cells. Plasma cells derive from B cells but stop expressing CD20: only 9.0% of the 27,349 plasma cells have an MS4A1 count. Detection falls to 3.1% of the 450,475 other immune cells and 0.8% of the 543,899 cells in the other compartments; the scattered cells with a count make up the faint signal outside the B-cell region.
Save the B cells in a mount¶
A read-only store cannot hold your own columns or results. cytearc.mount_datastore creates a mount: a writable store at a new path that copies the source’s cell and feature metadata and records the source’s URI. Count matrices and the source’s saved results, such as the authors’ UMAP, stay in the source and are read from it when a step needs them, while every write goes to the mount. Several people can mount the same source and keep separate analyses.
By default, the first writable open of a store removes the cells with 10 or fewer detected genes from I. min_features_per_cell=-1 turns that filter off, so the mount keeps the source’s active cells as they are. The B cells go into b_cells, a second boolean column. Both are cell keys, columns that an analysis can take as its input cells. Choose a new or empty path for the mount:
# Mount the atlas in a new local directory, keeping every published cell active.
mounted = cytearc.mount_datastore(
source_uri,
at="tabula_analysis.zarr",
storage_options={"token": False},
min_features_per_cell=-1,
)
# Save the author-annotated B cells as a boolean column of the mount, keyed by cell ID.
selected = mounted.cells.fetch_all("cell_type") == "B cell"
assert selected.any()
mounted.cells.insert("b_cells", pd.Series(selected, index=mounted.cells.fetch_all("ids")))
# Count the active and selected cells, and measure the mount on disk.
mount_files = Path("tabula_analysis.zarr").rglob("*")
mount_bytes = sum(file.stat().st_size for file in mount_files if file.is_file())
{
"active cells": int(mounted.cells.fetch_all("I").sum()),
"B cells selected": int(selected.sum()),
"mount size (MB)": round(mount_bytes / 1e6),
}{'active cells': 1136218, 'B cells selected': 114495, 'mount size (MB)': 166}Started: 2026-11-18T00:16:48.884346Z | Wall time: 11.952 s
All 1,136,218 cells stay active, and b_cells marks the 114,495 B cells. The mount takes 166 MB on disk, all of it copied metadata and the new column, while the 1,136,218 × 60,606 count matrix stays in the bucket.
Reopen your work¶
Open the mount’s path with cytearc.DataStore in a later session. The mount records its source’s URI but never saves storage options or credentials, so pass storage_options again. Then reopen the source read-only and check that b_cells is in the mount and not in the source:
# Reopen the mount with the anonymous access that its remote counts need.
reopened = cytearc.DataStore("tabula_analysis.zarr", storage_options={"token": False})
# Open the source again, read-only, as a new session would.
fresh_source = cytearc.DataStore(
source_uri, zarr_mode="r", storage_options={"token": False}
)
# Check that b_cells persisted in the mount and did not appear in the source.
saved = reopened.cells.fetch_all("b_cells")
checks = {
"selection preserved": bool((saved == selected).all()),
"shared source unchanged": "b_cells" not in fresh_source.cells.columns,
}
assert all(checks.values()), checks
checks{'selection preserved': True, 'shared source unchanged': True}Started: 2026-11-18T00:17:00.840916Z | Wall time: 1.487 s
Both checks are True: the mount kept b_cells, and the source has no such column. The author_umap reference found on the source also draws the mount’s own column:
# Draw b_cells on the authors' UMAP, which the mount reads from the source.
reopened.plots.embedding(
layout=author_umap,
color_by=CellField("b_cells", kind="categorical", label="Author-annotated B cells"),
categorical_scale=CategoricalScale(
palette={False: "#d9d9d9", True: "#2166ac"},
labels={False: "Other cells", True: "B cells"},
),
point_size=0.2,
figsize=(7, 5),
legend_loc="right",
)
Started: 2026-11-18T00:17:02.330925Z | Wall time: 10.466 s
The mount draws its own b_cells column on the source’s UMAP: the B cells fill the same lower-left region as in the first figure. Keep tabula_analysis.zarr to return to the analysis, and keep the source reachable. Reopening fails if the source’s counts have changed since the mount was made, and later changes to the source’s annotations never reach the mount’s copy; what a mount preserves lists what the mount records.
Continue with your analysis¶
Analyze the B cells:
reopened.pipeline.rna(cells="b_cells", label="b_cells")runs the RNA recipe on the B cells that pass its quality-control filter and saves the run in the mount. Withoutcells, the recipe starts from every active cell.Find another dataset: CyteBase publishes public datasets as stores that open the same way, by URI; CyteBase datasets shows how to find one and build its URI.
Connect your own storage: Remote storage configuration covers S3 and Google Cloud Storage access, source requirements and local scratch settings.
Work offline: download the prepared Tabula Sapiens sample in the Quick start.
- The Tabula Sapiens Consortium, & Quake, S. R. (2024). Tabula Sapiens reveals transcription factor expression, senescence effects, and sex-specific features in cell types from 28 human organs and tissues. openRxiv. 10.1101/2024.12.03.626516