scientific-skills/Evidence Insights/cellxgene-census/SKILL.md
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.
npx skillsauth add aipoch/medical-research-skills cellxgene-censusInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
4 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
get_anndata().axis_query() and chunked iteration.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]
The following script is a complete, runnable example that:
import numpy as np
import cellxgene_census
import tiledbsoma as soma
def main():
# Pin a version for reproducibility (replace with a valid release if needed)
census_version = "2023-07-25"
with cellxgene_census.open_soma(census_version=census_version) as census:
# 1) Explore summary info
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:,}")
# 2) Explore obs metadata (always filter primary data unless you want duplicates)
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))
# 3) Small/medium query -> AnnData in memory
adata = cellxgene_census.get_anndata(
census=census,
organism="Homo sapiens",
obs_value_filter=(
"cell_type == 'T cell' and disease == 'COVID-19' and is_primary_data == True"
),
var_value_filter="feature_name in ['CD4', 'CD8A', 'FOXP3']",
obs_column_names=["cell_type", "tissue_general", "disease", "donor_id", "sex"],
)
print(adata)
print("AnnData X shape:", adata.X.shape)
# 4) Large-scale pattern -> out-of-core iteration with axis_query()
# Example: compute mean of non-zero expression values for a few genes in brain.
query = census["census_data"]["homo_sapiens"].axis_query(
measurement_name="RNA",
obs_query=soma.AxisQuery(
value_filter="tissue_general == 'brain' and is_primary_data == True"
),
var_query=soma.AxisQuery(
value_filter="feature_name in ['FOXP2', 'TBR1', 'SATB2']"
),
)
n = 0
s = 0.0
for batch in query.X("raw").tables():
# batch is a pyarrow.Table with at least: soma_data, soma_dim_0, soma_dim_1
values = batch["soma_data"].to_numpy(zero_copy_only=False)
n += values.size
s += float(values.sum())
mean_expr = s / n if n else np.nan
print(f"Out-of-core mean expression (over returned entries): {mean_expr:.6g}")
if __name__ == "__main__":
main()
Opening the Census
with cellxgene_census.open_soma(...) as census: ...census_version="YYYY-MM-DD"; otherwise the latest stable release is used.Data model (high level)
census["census_info"] provides summary tables (e.g., datasets, counts).census["census_data"][organism] provides the experiment for an organism (e.g., homo_sapiens).Filtering semantics
obs_value_filter filters cells (obs); var_value_filter filters genes (var).and / or; use in [...] for multi-value membership.is_primary_data == True to avoid double-counting cells that appear in multiple source datasets.Choosing an access pattern
get_anndata() when the result is expected to fit in memory (commonly < ~100k cells, depending on gene count and sparsity).axis_query() + query.X("raw").tables() for out-of-core iteration and incremental statistics.Expression layers / matrices
X("raw") to access raw expression.soma_data: expression valuessoma_dim_0: obs (cell) coordinatessoma_dim_1: var (gene) coordinatesOptional ML integration
cellxgene_census.experimental.ml utilities provide PyTorch-friendly datasets/dataloaders for training workflows, typically driven by the same obs/var filtering concepts used elsewhere.tools
Generates complete conventional oncology bulk-transcriptome biomarker and hub-gene research designs from a user-provided cancer type and study direction. Always use this skill whenever a user wants to design, plan, or build a tumor bioinformatics study centered on differential expression, prognostic filtering or risk modeling, PPI-based hub-gene prioritization, diagnostic/prognostic evaluation, clinical association, immune infiltration context, methylation context, and optional tissue or cell validation. Covers five study patterns (signature-first prognostic workflow, hub-gene-first biomarker workflow, hybrid signature-to-hub workflow, immune-context biomarker workflow, translational validation workflow) and always outputs four workload configs (Lite / Standard / Advanced / Publication+) with recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, publication upgrade path...
development
Generates complete conventional non-oncology bioinformatics research designs from a user-provided disease context, process-related gene family or biological theme, and validation direction. Use when a study centers on multi-dataset bulk transcriptome integration, DEG analysis, process-gene intersection, enrichment analysis, GSEA, PPI hub-gene prioritization, TF/miRNA regulatory networks, ROC-based biomarker evaluation, and immune infiltration analysis. Covers five study patterns (process-DEG discovery, enrichment/GSEA interpretation, hub-gene prioritization, regulatory-network and immune interpretation, multi-layer public validation) and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.
tools
Plans confounder control, variable adjustment logic, and bias mitigation strategies at the protocol stage for clinical, epidemiologic, translational, observational, and biomarker studies. Always use this skill when a user needs to identify major confounders, decide which variables should or should not be adjusted for, compare matching/stratification/weighting approaches, anticipate selection or measurement bias, or pressure-test a study design before execution. Focus on bias sensing, causal structure awareness, variable-role classification, and critical design review rather than generic statistical advice.
testing
Generates complete comparative network-toxicology research designs from a user-provided exposure pair, shared toxic phenotype, and validation direction. Use when a study centers on two related exposures under one outcome and needs target collection, shared-vs-specific target decomposition, enrichment, PPI hub prioritization, docking, optional transcriptomic cross-checks, and conservative mechanistic synthesis. Covers five study patterns and always outputs Lite / Standard / Advanced / Publication+ with a recommended primary plan, stepwise workflow, figure plan, validation hierarchy, minimal executable version, publication upgrade path, and strictly verified literature retrieval.