| name | cellxgene-census |
| description | Programmatically query the CZ CELLxGENE Census (61M+ cells) when you need cross-tissue, disease, or cell-type expression data for population-scale queries and reference atlas comparisons. |
| license | MIT |
| author | AIPOCH |
Source: https://github.com/aipoch/medical-research-skills
When to Use
- Cross-tissue or cross-disease expression comparisons (e.g., macrophages across lung/liver/brain; COVID-19 vs control).
- Reference atlas lookups to contextualize findings from your own single-cell dataset (marker validation, expected expression patterns).
- Population-scale metadata exploration (what tissues/cell types/datasets exist; cell counts by cohort attributes).
- Large-scale expression statistics where results exceed RAM and require out-of-core iteration.
- Model training on curated atlas data (e.g., cell-type classifiers) using the experimental PyTorch integration.
Key Features
- Programmatic access to versioned CZ CELLxGENE Census data (human and mouse).
- Query cell (obs) metadata and gene (var) metadata with expressive filter syntax.
- Retrieve expression as AnnData for small/medium queries via
get_anndata().
- Perform out-of-core expression access via SOMA
axis_query() and chunked iteration.
- Optional experimental ML utilities (PyTorch dataloaders/datasets).
- Works well with scanpy workflows after loading AnnData.
Dependencies
cellxgene-census (latest)
tiledbsoma (latest; required for axis_query() workflows)
pyarrow (latest; used for chunked table batches)
anndata (latest; for get_anndata() results)
scanpy (latest; optional, for downstream analysis)
torch (latest; optional, for experimental ML integration)
Install:
uv pip install cellxgene-census
Optional (experimental ML helpers):
uv pip install cellxgene-census[experimental]
Example Usage
The following script is a complete, runnable example that:
- opens a pinned Census version,
- explores metadata,
- loads a small AnnData slice, and
- runs an out-of-core query to compute a simple statistic.
import numpy as np
import cellxgene_census
import tiledbsoma as soma
def main():
census_version = "2023-07-25"
with cellxgene_census.open_soma(census_version=census_version) as census:
summary = census["census_info"]["summary"].read().concat().to_pandas()
total_cells = int(summary["total_cell_count"].iloc[0])
print(f"Census version: {census_version}")
print(f"Total cells: {total_cells:,}")
obs = cellxgene_census.get_obs(
census,
"homo_sapiens",
value_filter="tissue_general == 'brain' and is_primary_data == True",
column_names=["cell_type", "tissue_general", "disease", "donor_id"],
)
print(f"Brain (primary) cells returned (metadata only): {len(obs):,}")
print("Top cell types:")
print(obs["cell_type"].value_counts().head(10))
adata = cellxgene_census.get_anndata(
census=census,
organism="Homo sapiens",
obs_value_filter=(
),
var_value_filter=,
obs_column_names=[, , , , ],
)
(adata)
(, adata.X.shape)
query = census[][].axis_query(
measurement_name=,
obs_query=soma.AxisQuery(
value_filter=
),
var_query=soma.AxisQuery(
value_filter=
),
)
n =
s =
batch query.X().tables():
values = batch[].to_numpy(zero_copy_only=)
n += values.size
s += (values.())
mean_expr = s / n n np.nan
()
__name__ == :
main()
Implementation Details