[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72B3JDF8CMTHGPYY68802XR":3,"skill-same:01M72B3JDF8CMTHGPYY68802XR":57},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":13,"repositoryHtmlUrl":26,"repositoryHomepageUrl":6,"ownerHtmlUrl":27,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":28,"install":29,"resources":42},"01M72B3JDF8CMTHGPYY68802XR","cellxgene-census",null,"Query CZ CELLxGENE Census (61M+ cells). Filter by cell type\u002Ftissue\u002Fdisease, retrieve expression data, integrate with scanpy\u002FPyTorch, for population-scale single-cell analysis.","Sansar35\u002Fclaude-agent","Sansar35","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F145020281?v=4","01M724CQ2SCC86MGNSD87D0D4K","01M724CQ3965G9WJ3QXE3AJ5YY",1,"MIT","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fcellxgene-census\u002FSKILL.md",[],[],"2026-11-10 18:39:20",false,"---\nname: cellxgene-census\ndescription: \"Query CZ CELLxGENE Census (61M+ cells). Filter by cell type\u002Ftissue\u002Fdisease, retrieve expression data, integrate with scanpy\u002FPyTorch, for population-scale single-cell analysis.\"\n---\n\n# CZ CELLxGENE Census\n\n## Overview\n\nThe CZ CELLxGENE Census provides programmatic access to a comprehensive, versioned collection of standardized single-cell genomics data from CZ CELLxGENE Discover. This skill enables efficient querying and analysis of millions of cells across thousands of datasets.\n\nThe Census includes:\n- **61+ million cells** from human and mouse\n- **Standardized metadata** (cell types, tissues, diseases, donors)\n- **Raw gene expression** matrices\n- **Pre-calculated embeddings** and statistics\n- **Integration with PyTorch, scanpy, and other analysis tools**\n\n## When to Use This Skill\n\nThis skill should be used when:\n- Querying single-cell expression data by cell type, tissue, or disease\n- Exploring available single-cell datasets and metadata\n- Training machine learning models on single-cell data\n- Performing large-scale cross-dataset analyses\n- Integrating Census data with scanpy or other analysis frameworks\n- Computing statistics across millions of cells\n- Accessing pre-calculated embeddings or model predictions\n\n## Installation and Setup\n\nInstall the Census API:\n```bash\nuv pip install cellxgene-census\n```\n\nFor machine learning workflows, install additional dependencies:\n```bash\nuv pip install cellxgene-census[experimental]\n```\n\n## Core Workflow Patterns\n\n### 1. Opening the Census\n\nAlways use the context manager to ensure proper resource cleanup:\n\n```python\nimport cellxgene_census\n\n# Open latest stable version\nwith cellxgene_census.open_soma() as census:\n    # Work with census data\n\n# Open specific version for reproducibility\nwith cellxgene_census.open_soma(census_version=\"2023-07-25\") as census:\n    # Work with census data\n```\n\n**Key points:**\n- Use context manager (`with` statement) for automatic cleanup\n- Specify `census_version` for reproducible analyses\n- Default opens latest \"stable\" release\n\n### 2. Exploring Census Information\n\nBefore querying expression data, explore available datasets and metadata.\n\n**Access summary information:**\n```python\n# Get summary statistics\nsummary = census[\"census_info\"][\"summary\"].read().concat().to_pandas()\nprint(f\"Total cells: {summary['total_cell_count'][0]}\")\n\n# Get all datasets\ndatasets = census[\"census_info\"][\"datasets\"].read().concat().to_pandas()\n\n# Filter datasets by criteria\ncovid_datasets = datasets[datasets[\"disease\"].str.contains(\"COVID\", na=False)]\n```\n\n**Query cell metadata to understand available data:**\n```python\n# Get unique cell types in a tissue\ncell_metadata = cellxgene_census.get_obs(\n    census,\n    \"homo_sapiens\",\n    value_filter=\"tissue_general == 'brain' and is_primary_data == True\",\n    column_names=[\"cell_type\"]\n)\nunique_cell_types = cell_metadata[\"cell_type\"].unique()\nprint(f\"Found {len(unique_cell_types)} cell types in brain\")\n\n# Count cells by tissue\ntissue_counts = cell_metadata.groupby(\"tissue_general\").size()\n```\n\n**Important:** Always filter for `is_primary_data == True` to avoid counting duplicate cells unless specifically analyzing duplicates.\n\n### 3. Querying Expression Data (Small to Medium Scale)\n\nFor queries returning \u003C 100k cells that fit in memory, use `get_anndata()`:\n\n```python\n# Basic query with cell type and tissue filters\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",  # or \"Mus musculus\"\n    obs_value_filter=\"cell_type == 'B cell' and tissue_general == 'lung' and is_primary_data == True\",\n    obs_column_names=[\"assay\", \"disease\", \"sex\", \"donor_id\"],\n)\n\n# Query specific genes with multiple filters\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    var_value_filter=\"feature_name in ['CD4', 'CD8A', 'CD19', 'FOXP3']\",\n    obs_value_filter=\"cell_type == 'T cell' and disease == 'COVID-19' and is_primary_data == True\",\n    obs_column_names=[\"cell_type\", \"tissue_general\", \"donor_id\"],\n)\n```\n\n**Filter syntax:**\n- Use `obs_value_filter` for cell filtering\n- Use `var_value_filter` for gene filtering\n- Combine conditions with `and`, `or`\n- Use `in` for multiple values: `tissue in ['lung', 'liver']`\n- Select only needed columns with `obs_column_names`\n\n**Getting metadata separately:**\n```python\n# Query cell metadata\ncell_metadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"disease == 'COVID-19' and is_primary_data == True\",\n    column_names=[\"cell_type\", \"tissue_general\", \"donor_id\"]\n)\n\n# Query gene metadata\ngene_metadata = cellxgene_census.get_var(\n    census, \"homo_sapiens\",\n    value_filter=\"feature_name in ['CD4', 'CD8A']\",\n    column_names=[\"feature_id\", \"feature_name\", \"feature_length\"]\n)\n```\n\n### 4. Large-Scale Queries (Out-of-Core Processing)\n\nFor queries exceeding available RAM, use `axis_query()` with iterative processing:\n\n```python\nimport tiledbsoma as soma\n\n# Create axis query\nquery = census[\"census_data\"][\"homo_sapiens\"].axis_query(\n    measurement_name=\"RNA\",\n    obs_query=soma.AxisQuery(\n        value_filter=\"tissue_general == 'brain' and is_primary_data == True\"\n    ),\n    var_query=soma.AxisQuery(\n        value_filter=\"feature_name in ['FOXP2', 'TBR1', 'SATB2']\"\n    )\n)\n\n# Iterate through expression matrix in chunks\niterator = query.X(\"raw\").tables()\nfor batch in iterator:\n    # batch is a pyarrow.Table with columns:\n    # - soma_data: expression value\n    # - soma_dim_0: cell (obs) coordinate\n    # - soma_dim_1: gene (var) coordinate\n    process_batch(batch)\n```\n\n**Computing incremental statistics:**\n```python\n# Example: Calculate mean expression\nn_observations = 0\nsum_values = 0.0\n\niterator = query.X(\"raw\").tables()\nfor batch in iterator:\n    values = batch[\"soma_data\"].to_numpy()\n    n_observations += len(values)\n    sum_values += values.sum()\n\nmean_expression = sum_values \u002F n_observations\n```\n\n### 5. Machine Learning with PyTorch\n\nFor training models, use the experimental PyTorch integration:\n\n```python\nfrom cellxgene_census.experimental.ml import experiment_dataloader\n\nwith cellxgene_census.open_soma() as census:\n    # Create dataloader\n    dataloader = experiment_dataloader(\n        census[\"census_data\"][\"homo_sapiens\"],\n        measurement_name=\"RNA\",\n        X_name=\"raw\",\n        obs_value_filter=\"tissue_general == 'liver' and is_primary_data == True\",\n        obs_column_names=[\"cell_type\"],\n        batch_size=128,\n        shuffle=True,\n    )\n\n    # Training loop\n    for epoch in range(num_epochs):\n        for batch in dataloader:\n            X = batch[\"X\"]  # Gene expression tensor\n            labels = batch[\"obs\"][\"cell_type\"]  # Cell type labels\n\n            # Forward pass\n            outputs = model(X)\n            loss = criterion(outputs, labels)\n\n            # Backward pass\n            optimizer.zero_grad()\n            loss.backward()\n            optimizer.step()\n```\n\n**Train\u002Ftest splitting:**\n```python\nfrom cellxgene_census.experimental.ml import ExperimentDataset\n\n# Create dataset from experiment\ndataset = ExperimentDataset(\n    experiment_axis_query,\n    layer_name=\"raw\",\n    obs_column_names=[\"cell_type\"],\n    batch_size=128,\n)\n\n# Split into train and test\ntrain_dataset, test_dataset = dataset.random_split(\n    split=[0.8, 0.2],\n    seed=42\n)\n```\n\n### 6. Integration with Scanpy\n\nSeamlessly integrate Census data with scanpy workflows:\n\n```python\nimport scanpy as sc\n\n# Load data from Census\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"cell_type == 'neuron' and tissue_general == 'cortex' and is_primary_data == True\",\n)\n\n# Standard scanpy workflow\nsc.pp.normalize_total(adata, target_sum=1e4)\nsc.pp.log1p(adata)\nsc.pp.highly_variable_genes(adata, n_top_genes=2000)\n\n# Dimensionality reduction\nsc.pp.pca(adata, n_comps=50)\nsc.pp.neighbors(adata)\nsc.tl.umap(adata)\n\n# Visualization\nsc.pl.umap(adata, color=[\"cell_type\", \"tissue\", \"disease\"])\n```\n\n### 7. Multi-Dataset Integration\n\nQuery and integrate multiple datasets:\n\n```python\n# Strategy 1: Query multiple tissues separately\ntissues = [\"lung\", \"liver\", \"kidney\"]\nadatas = []\n\nfor tissue in tissues:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        obs_value_filter=f\"tissue_general == '{tissue}' and is_primary_data == True\",\n    )\n    adata.obs[\"tissue\"] = tissue\n    adatas.append(adata)\n\n# Concatenate\ncombined = adatas[0].concatenate(adatas[1:])\n\n# Strategy 2: Query multiple datasets directly\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"tissue_general in ['lung', 'liver', 'kidney'] and is_primary_data == True\",\n)\n```\n\n## Key Concepts and Best Practices\n\n### Always Filter for Primary Data\nUnless analyzing duplicates, always include `is_primary_data == True` in queries to avoid counting cells multiple times:\n```python\nobs_value_filter=\"cell_type == 'B cell' and is_primary_data == True\"\n```\n\n### Specify Census Version for Reproducibility\nAlways specify the Census version in production analyses:\n```python\ncensus = cellxgene_census.open_soma(census_version=\"2023-07-25\")\n```\n\n### Estimate Query Size Before Loading\nFor large queries, first check the number of cells to avoid memory issues:\n```python\n# Get cell count\nmetadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"tissue_general == 'brain' and is_primary_data == True\",\n    column_names=[\"soma_joinid\"]\n)\nn_cells = len(metadata)\nprint(f\"Query will return {n_cells:,} cells\")\n\n# If too large (>100k), use out-of-core processing\n```\n\n### Use tissue_general for Broader Groupings\nThe `tissue_general` field provides coarser categories than `tissue`, useful for cross-tissue analyses:\n```python\n# Broader grouping\nobs_value_filter=\"tissue_general == 'immune system'\"\n\n# Specific tissue\nobs_value_filter=\"tissue == 'peripheral blood mononuclear cell'\"\n```\n\n### Select Only Needed Columns\nMinimize data transfer by specifying only required metadata columns:\n```python\nobs_column_names=[\"cell_type\", \"tissue_general\", \"disease\"]  # Not all columns\n```\n\n### Check Dataset Presence for Gene-Specific Queries\nWhen analyzing specific genes, verify which datasets measured them:\n```python\npresence = cellxgene_census.get_presence_matrix(\n    census,\n    \"homo_sapiens\",\n    var_value_filter=\"feature_name in ['CD4', 'CD8A']\"\n)\n```\n\n### Two-Step Workflow: Explore Then Query\nFirst explore metadata to understand available data, then query expression:\n```python\n# Step 1: Explore what's available\nmetadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"disease == 'COVID-19' and is_primary_data == True\",\n    column_names=[\"cell_type\", \"tissue_general\"]\n)\nprint(metadata.value_counts())\n\n# Step 2: Query based on findings\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"disease == 'COVID-19' and cell_type == 'T cell' and is_primary_data == True\",\n)\n```\n\n## Available Metadata Fields\n\n### Cell Metadata (obs)\nKey fields for filtering:\n- `cell_type`, `cell_type_ontology_term_id`\n- `tissue`, `tissue_general`, `tissue_ontology_term_id`\n- `disease`, `disease_ontology_term_id`\n- `assay`, `assay_ontology_term_id`\n- `donor_id`, `sex`, `self_reported_ethnicity`\n- `development_stage`, `development_stage_ontology_term_id`\n- `dataset_id`\n- `is_primary_data` (Boolean: True = unique cell)\n\n### Gene Metadata (var)\n- `feature_id` (Ensembl gene ID, e.g., \"ENSG00000161798\")\n- `feature_name` (Gene symbol, e.g., \"FOXP2\")\n- `feature_length` (Gene length in base pairs)\n\n## Reference Documentation\n\nThis skill includes detailed reference documentation:\n\n### references\u002Fcensus_schema.md\nComprehensive documentation of:\n- Census data structure and organization\n- All available metadata fields\n- Value filter syntax and operators\n- SOMA object types\n- Data inclusion criteria\n\n**When to read:** When you need detailed schema information, full list of metadata fields, or complex filter syntax.\n\n### references\u002Fcommon_patterns.md\nExamples and patterns for:\n- Exploratory queries (metadata only)\n- Small-to-medium queries (AnnData)\n- Large queries (out-of-core processing)\n- PyTorch integration\n- Scanpy integration workflows\n- Multi-dataset integration\n- Best practices and common pitfalls\n\n**When to read:** When implementing specific query patterns, looking for code examples, or troubleshooting common issues.\n\n## Common Use Cases\n\n### Use Case 1: Explore Cell Types in a Tissue\n```python\nwith cellxgene_census.open_soma() as census:\n    cells = cellxgene_census.get_obs(\n        census, \"homo_sapiens\",\n        value_filter=\"tissue_general == 'lung' and is_primary_data == True\",\n        column_names=[\"cell_type\"]\n    )\n    print(cells[\"cell_type\"].value_counts())\n```\n\n### Use Case 2: Query Marker Gene Expression\n```python\nwith cellxgene_census.open_soma() as census:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        var_value_filter=\"feature_name in ['CD4', 'CD8A', 'CD19']\",\n        obs_value_filter=\"cell_type in ['T cell', 'B cell'] and is_primary_data == True\",\n    )\n```\n\n### Use Case 3: Train Cell Type Classifier\n```python\nfrom cellxgene_census.experimental.ml import experiment_dataloader\n\nwith cellxgene_census.open_soma() as census:\n    dataloader = experiment_dataloader(\n        census[\"census_data\"][\"homo_sapiens\"],\n        measurement_name=\"RNA\",\n        X_name=\"raw\",\n        obs_value_filter=\"is_primary_data == True\",\n        obs_column_names=[\"cell_type\"],\n        batch_size=128,\n        shuffle=True,\n    )\n\n    # Train model\n    for epoch in range(epochs):\n        for batch in dataloader:\n            # Training logic\n            pass\n```\n\n### Use Case 4: Cross-Tissue Analysis\n```python\nwith cellxgene_census.open_soma() as census:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        obs_value_filter=\"cell_type == 'macrophage' and tissue_general in ['lung', 'liver', 'brain'] and is_primary_data == True\",\n    )\n\n    # Analyze macrophage differences across tissues\n    sc.tl.rank_genes_groups(adata, groupby=\"tissue_general\")\n```\n\n## Troubleshooting\n\n### Query Returns Too Many Cells\n- Add more specific filters to reduce scope\n- Use `tissue` instead of `tissue_general` for finer granularity\n- Filter by specific `dataset_id` if known\n- Switch to out-of-core processing for large queries\n\n### Memory Errors\n- Reduce query scope with more restrictive filters\n- Select fewer genes with `var_value_filter`\n- Use out-of-core processing with `axis_query()`\n- Process data in batches\n\n### Duplicate Cells in Results\n- Always include `is_primary_data == True` in filters\n- Check if intentionally querying across multiple datasets\n\n### Gene Not Found\n- Verify gene name spelling (case-sensitive)\n- Try Ensembl ID with `feature_id` instead of `feature_name`\n- Check dataset presence matrix to see if gene was measured\n- Some genes may have been filtered during Census construction\n\n### Version Inconsistencies\n- Always specify `census_version` explicitly\n- Use same version across all analyses\n- Check release notes for version-specific changes\n","# CZ CELLxGENE Census\n\n## Overview\n\nThe CZ CELLxGENE Census provides programmatic access to a comprehensive, versioned collection of standardized single-cell genomics data from CZ CELLxGENE Discover. This skill enables efficient querying and analysis of millions of cells across thousands of datasets.\n\nThe Census includes:\n- **61+ million cells** from human and mouse\n- **Standardized metadata** (cell types, tissues, diseases, donors)\n- **Raw gene expression** matrices\n- **Pre-calculated embeddings** and statistics\n- **Integration with PyTorch, scanpy, and other analysis tools**\n\n## When to Use This Skill\n\nThis skill should be used when:\n- Querying single-cell expression data by cell type, tissue, or disease\n- Exploring available single-cell datasets and metadata\n- Training machine learning models on single-cell data\n- Performing large-scale cross-dataset analyses\n- Integrating Census data with scanpy or other analysis frameworks\n- Computing statistics across millions of cells\n- Accessing pre-calculated embeddings or model predictions\n\n## Installation and Setup\n\nInstall the Census API:\n```bash\nuv pip install cellxgene-census\n```\n\nFor machine learning workflows, install additional dependencies:\n```bash\nuv pip install cellxgene-census[experimental]\n```\n\n## Core Workflow Patterns\n\n### 1. Opening the Census\n\nAlways use the context manager to ensure proper resource cleanup:\n\n```python\nimport cellxgene_census\n\n# Open latest stable version\nwith cellxgene_census.open_soma() as census:\n    # Work with census data\n\n# Open specific version for reproducibility\nwith cellxgene_census.open_soma(census_version=\"2023-07-25\") as census:\n    # Work with census data\n```\n\n**Key points:**\n- Use context manager (`with` statement) for automatic cleanup\n- Specify `census_version` for reproducible analyses\n- Default opens latest \"stable\" release\n\n### 2. Exploring Census Information\n\nBefore querying expression data, explore available datasets and metadata.\n\n**Access summary information:**\n```python\n# Get summary statistics\nsummary = census[\"census_info\"][\"summary\"].read().concat().to_pandas()\nprint(f\"Total cells: {summary['total_cell_count'][0]}\")\n\n# Get all datasets\ndatasets = census[\"census_info\"][\"datasets\"].read().concat().to_pandas()\n\n# Filter datasets by criteria\ncovid_datasets = datasets[datasets[\"disease\"].str.contains(\"COVID\", na=False)]\n```\n\n**Query cell metadata to understand available data:**\n```python\n# Get unique cell types in a tissue\ncell_metadata = cellxgene_census.get_obs(\n    census,\n    \"homo_sapiens\",\n    value_filter=\"tissue_general == 'brain' and is_primary_data == True\",\n    column_names=[\"cell_type\"]\n)\nunique_cell_types = cell_metadata[\"cell_type\"].unique()\nprint(f\"Found {len(unique_cell_types)} cell types in brain\")\n\n# Count cells by tissue\ntissue_counts = cell_metadata.groupby(\"tissue_general\").size()\n```\n\n**Important:** Always filter for `is_primary_data == True` to avoid counting duplicate cells unless specifically analyzing duplicates.\n\n### 3. Querying Expression Data (Small to Medium Scale)\n\nFor queries returning \u003C 100k cells that fit in memory, use `get_anndata()`:\n\n```python\n# Basic query with cell type and tissue filters\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",  # or \"Mus musculus\"\n    obs_value_filter=\"cell_type == 'B cell' and tissue_general == 'lung' and is_primary_data == True\",\n    obs_column_names=[\"assay\", \"disease\", \"sex\", \"donor_id\"],\n)\n\n# Query specific genes with multiple filters\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    var_value_filter=\"feature_name in ['CD4', 'CD8A', 'CD19', 'FOXP3']\",\n    obs_value_filter=\"cell_type == 'T cell' and disease == 'COVID-19' and is_primary_data == True\",\n    obs_column_names=[\"cell_type\", \"tissue_general\", \"donor_id\"],\n)\n```\n\n**Filter syntax:**\n- Use `obs_value_filter` for cell filtering\n- Use `var_value_filter` for gene filtering\n- Combine conditions with `and`, `or`\n- Use `in` for multiple values: `tissue in ['lung', 'liver']`\n- Select only needed columns with `obs_column_names`\n\n**Getting metadata separately:**\n```python\n# Query cell metadata\ncell_metadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"disease == 'COVID-19' and is_primary_data == True\",\n    column_names=[\"cell_type\", \"tissue_general\", \"donor_id\"]\n)\n\n# Query gene metadata\ngene_metadata = cellxgene_census.get_var(\n    census, \"homo_sapiens\",\n    value_filter=\"feature_name in ['CD4', 'CD8A']\",\n    column_names=[\"feature_id\", \"feature_name\", \"feature_length\"]\n)\n```\n\n### 4. Large-Scale Queries (Out-of-Core Processing)\n\nFor queries exceeding available RAM, use `axis_query()` with iterative processing:\n\n```python\nimport tiledbsoma as soma\n\n# Create axis query\nquery = census[\"census_data\"][\"homo_sapiens\"].axis_query(\n    measurement_name=\"RNA\",\n    obs_query=soma.AxisQuery(\n        value_filter=\"tissue_general == 'brain' and is_primary_data == True\"\n    ),\n    var_query=soma.AxisQuery(\n        value_filter=\"feature_name in ['FOXP2', 'TBR1', 'SATB2']\"\n    )\n)\n\n# Iterate through expression matrix in chunks\niterator = query.X(\"raw\").tables()\nfor batch in iterator:\n    # batch is a pyarrow.Table with columns:\n    # - soma_data: expression value\n    # - soma_dim_0: cell (obs) coordinate\n    # - soma_dim_1: gene (var) coordinate\n    process_batch(batch)\n```\n\n**Computing incremental statistics:**\n```python\n# Example: Calculate mean expression\nn_observations = 0\nsum_values = 0.0\n\niterator = query.X(\"raw\").tables()\nfor batch in iterator:\n    values = batch[\"soma_data\"].to_numpy()\n    n_observations += len(values)\n    sum_values += values.sum()\n\nmean_expression = sum_values \u002F n_observations\n```\n\n### 5. Machine Learning with PyTorch\n\nFor training models, use the experimental PyTorch integration:\n\n```python\nfrom cellxgene_census.experimental.ml import experiment_dataloader\n\nwith cellxgene_census.open_soma() as census:\n    # Create dataloader\n    dataloader = experiment_dataloader(\n        census[\"census_data\"][\"homo_sapiens\"],\n        measurement_name=\"RNA\",\n        X_name=\"raw\",\n        obs_value_filter=\"tissue_general == 'liver' and is_primary_data == True\",\n        obs_column_names=[\"cell_type\"],\n        batch_size=128,\n        shuffle=True,\n    )\n\n    # Training loop\n    for epoch in range(num_epochs):\n        for batch in dataloader:\n            X = batch[\"X\"]  # Gene expression tensor\n            labels = batch[\"obs\"][\"cell_type\"]  # Cell type labels\n\n            # Forward pass\n            outputs = model(X)\n            loss = criterion(outputs, labels)\n\n            # Backward pass\n            optimizer.zero_grad()\n            loss.backward()\n            optimizer.step()\n```\n\n**Train\u002Ftest splitting:**\n```python\nfrom cellxgene_census.experimental.ml import ExperimentDataset\n\n# Create dataset from experiment\ndataset = ExperimentDataset(\n    experiment_axis_query,\n    layer_name=\"raw\",\n    obs_column_names=[\"cell_type\"],\n    batch_size=128,\n)\n\n# Split into train and test\ntrain_dataset, test_dataset = dataset.random_split(\n    split=[0.8, 0.2],\n    seed=42\n)\n```\n\n### 6. Integration with Scanpy\n\nSeamlessly integrate Census data with scanpy workflows:\n\n```python\nimport scanpy as sc\n\n# Load data from Census\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"cell_type == 'neuron' and tissue_general == 'cortex' and is_primary_data == True\",\n)\n\n# Standard scanpy workflow\nsc.pp.normalize_total(adata, target_sum=1e4)\nsc.pp.log1p(adata)\nsc.pp.highly_variable_genes(adata, n_top_genes=2000)\n\n# Dimensionality reduction\nsc.pp.pca(adata, n_comps=50)\nsc.pp.neighbors(adata)\nsc.tl.umap(adata)\n\n# Visualization\nsc.pl.umap(adata, color=[\"cell_type\", \"tissue\", \"disease\"])\n```\n\n### 7. Multi-Dataset Integration\n\nQuery and integrate multiple datasets:\n\n```python\n# Strategy 1: Query multiple tissues separately\ntissues = [\"lung\", \"liver\", \"kidney\"]\nadatas = []\n\nfor tissue in tissues:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        obs_value_filter=f\"tissue_general == '{tissue}' and is_primary_data == True\",\n    )\n    adata.obs[\"tissue\"] = tissue\n    adatas.append(adata)\n\n# Concatenate\ncombined = adatas[0].concatenate(adatas[1:])\n\n# Strategy 2: Query multiple datasets directly\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"tissue_general in ['lung', 'liver', 'kidney'] and is_primary_data == True\",\n)\n```\n\n## Key Concepts and Best Practices\n\n### Always Filter for Primary Data\nUnless analyzing duplicates, always include `is_primary_data == True` in queries to avoid counting cells multiple times:\n```python\nobs_value_filter=\"cell_type == 'B cell' and is_primary_data == True\"\n```\n\n### Specify Census Version for Reproducibility\nAlways specify the Census version in production analyses:\n```python\ncensus = cellxgene_census.open_soma(census_version=\"2023-07-25\")\n```\n\n### Estimate Query Size Before Loading\nFor large queries, first check the number of cells to avoid memory issues:\n```python\n# Get cell count\nmetadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"tissue_general == 'brain' and is_primary_data == True\",\n    column_names=[\"soma_joinid\"]\n)\nn_cells = len(metadata)\nprint(f\"Query will return {n_cells:,} cells\")\n\n# If too large (>100k), use out-of-core processing\n```\n\n### Use tissue_general for Broader Groupings\nThe `tissue_general` field provides coarser categories than `tissue`, useful for cross-tissue analyses:\n```python\n# Broader grouping\nobs_value_filter=\"tissue_general == 'immune system'\"\n\n# Specific tissue\nobs_value_filter=\"tissue == 'peripheral blood mononuclear cell'\"\n```\n\n### Select Only Needed Columns\nMinimize data transfer by specifying only required metadata columns:\n```python\nobs_column_names=[\"cell_type\", \"tissue_general\", \"disease\"]  # Not all columns\n```\n\n### Check Dataset Presence for Gene-Specific Queries\nWhen analyzing specific genes, verify which datasets measured them:\n```python\npresence = cellxgene_census.get_presence_matrix(\n    census,\n    \"homo_sapiens\",\n    var_value_filter=\"feature_name in ['CD4', 'CD8A']\"\n)\n```\n\n### Two-Step Workflow: Explore Then Query\nFirst explore metadata to understand available data, then query expression:\n```python\n# Step 1: Explore what's available\nmetadata = cellxgene_census.get_obs(\n    census, \"homo_sapiens\",\n    value_filter=\"disease == 'COVID-19' and is_primary_data == True\",\n    column_names=[\"cell_type\", \"tissue_general\"]\n)\nprint(metadata.value_counts())\n\n# Step 2: Query based on findings\nadata = cellxgene_census.get_anndata(\n    census=census,\n    organism=\"Homo sapiens\",\n    obs_value_filter=\"disease == 'COVID-19' and cell_type == 'T cell' and is_primary_data == True\",\n)\n```\n\n## Available Metadata Fields\n\n### Cell Metadata (obs)\nKey fields for filtering:\n- `cell_type`, `cell_type_ontology_term_id`\n- `tissue`, `tissue_general`, `tissue_ontology_term_id`\n- `disease`, `disease_ontology_term_id`\n- `assay`, `assay_ontology_term_id`\n- `donor_id`, `sex`, `self_reported_ethnicity`\n- `development_stage`, `development_stage_ontology_term_id`\n- `dataset_id`\n- `is_primary_data` (Boolean: True = unique cell)\n\n### Gene Metadata (var)\n- `feature_id` (Ensembl gene ID, e.g., \"ENSG00000161798\")\n- `feature_name` (Gene symbol, e.g., \"FOXP2\")\n- `feature_length` (Gene length in base pairs)\n\n## Reference Documentation\n\nThis skill includes detailed reference documentation:\n\n### references\u002Fcensus_schema.md\nComprehensive documentation of:\n- Census data structure and organization\n- All available metadata fields\n- Value filter syntax and operators\n- SOMA object types\n- Data inclusion criteria\n\n**When to read:** When you need detailed schema information, full list of metadata fields, or complex filter syntax.\n\n### references\u002Fcommon_patterns.md\nExamples and patterns for:\n- Exploratory queries (metadata only)\n- Small-to-medium queries (AnnData)\n- Large queries (out-of-core processing)\n- PyTorch integration\n- Scanpy integration workflows\n- Multi-dataset integration\n- Best practices and common pitfalls\n\n**When to read:** When implementing specific query patterns, looking for code examples, or troubleshooting common issues.\n\n## Common Use Cases\n\n### Use Case 1: Explore Cell Types in a Tissue\n```python\nwith cellxgene_census.open_soma() as census:\n    cells = cellxgene_census.get_obs(\n        census, \"homo_sapiens\",\n        value_filter=\"tissue_general == 'lung' and is_primary_data == True\",\n        column_names=[\"cell_type\"]\n    )\n    print(cells[\"cell_type\"].value_counts())\n```\n\n### Use Case 2: Query Marker Gene Expression\n```python\nwith cellxgene_census.open_soma() as census:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        var_value_filter=\"feature_name in ['CD4', 'CD8A', 'CD19']\",\n        obs_value_filter=\"cell_type in ['T cell', 'B cell'] and is_primary_data == True\",\n    )\n```\n\n### Use Case 3: Train Cell Type Classifier\n```python\nfrom cellxgene_census.experimental.ml import experiment_dataloader\n\nwith cellxgene_census.open_soma() as census:\n    dataloader = experiment_dataloader(\n        census[\"census_data\"][\"homo_sapiens\"],\n        measurement_name=\"RNA\",\n        X_name=\"raw\",\n        obs_value_filter=\"is_primary_data == True\",\n        obs_column_names=[\"cell_type\"],\n        batch_size=128,\n        shuffle=True,\n    )\n\n    # Train model\n    for epoch in range(epochs):\n        for batch in dataloader:\n            # Training logic\n            pass\n```\n\n### Use Case 4: Cross-Tissue Analysis\n```python\nwith cellxgene_census.open_soma() as census:\n    adata = cellxgene_census.get_anndata(\n        census=census,\n        organism=\"Homo sapiens\",\n        obs_value_filter=\"cell_type == 'macrophage' and tissue_general in ['lung', 'liver', 'brain'] and is_primary_data == True\",\n    )\n\n    # Analyze macrophage differences across tissues\n    sc.tl.rank_genes_groups(adata, groupby=\"tissue_general\")\n```\n\n## Troubleshooting\n\n### Query Returns Too Many Cells\n- Add more specific filters to reduce scope\n- Use `tissue` instead of `tissue_general` for finer granularity\n- Filter by specific `dataset_id` if known\n- Switch to out-of-core processing for large queries\n\n### Memory Errors\n- Reduce query scope with more restrictive filters\n- Select fewer genes with `var_value_filter`\n- Use out-of-core processing with `axis_query()`\n- Process data in batches\n\n### Duplicate Cells in Results\n- Always include `is_primary_data == True` in filters\n- Check if intentionally querying across multiple datasets\n\n### Gene Not Found\n- Verify gene name spelling (case-sensitive)\n- Try Ensembl ID with `feature_id` instead of `feature_name`\n- Check dataset presence matrix to see if gene was measured\n- Some genes may have been filtered during Census construction\n\n### Version Inconsistencies\n- Always specify `census_version` explicitly\n- Use same version across all analyses\n- Check release notes for version-specific changes\n",{"name":5,"description":7},"main","d046d088ce5a79a083f0abc0fe1b7ded73bc5b1f","claude-config\u002Fskills\u002Fcellxgene-census","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent","https:\u002F\u002Fgithub.com\u002FSansar35","2026-05-10 16:04:53",{"source":8,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add Sansar35\u002Fclaude-agent --skill cellxgene-census",{"tool":35,"command":36},"bunx","bunx skills add Sansar35\u002Fclaude-agent --skill cellxgene-census",{"tool":38,"command":39},"pnpm","pnpm dlx skills add Sansar35\u002Fclaude-agent --skill cellxgene-census","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fcellxgene-census\u002FSKILL.md",true,[43,49,53],{"path":44,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":47,"sourceHtmlUrl":48},".skill-source.json","REFERENCE","参考文档",408,"https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fcellxgene-census\u002F.skill-source.json",{"path":50,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":51,"sourceHtmlUrl":52},"references\u002Fcensus_schema.md",5649,"https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fcellxgene-census\u002Freferences\u002Fcensus_schema.md",{"path":54,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":55,"sourceHtmlUrl":56},"references\u002Fcommon_patterns.md",9935,"https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fcellxgene-census\u002Freferences\u002Fcommon_patterns.md",[58,65,72,79,86,94],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":18},"01M72DVAN1JYEA302MT0C5MGD6","zustand-store-ts","Create Zustand stores following established patterns with proper TypeScript types and middleware.","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":18},"01M72DV8J5NBRRM4RPDFRV95N7","zod-validation-expert","Expert in Zod — TypeScript-first schema validation. Covers parsing, custom errors, refinements, type inference, and integration with React Hook Form, Next.js, and tRPC.","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzod-validation-expert\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M72DV5EMHW0BHP9BZ167MDCB","zinc-database","Access ZINC (230M+ purchasable compounds). Search by ZINC ID\u002FSMILES, similarity searches, 3D-ready structures for docking, analog discovery, for virtual screening and drug discovery.","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzinc-database\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":18},"01M72DV216QY0E693ZPEVQ0DBS","zarr-python","Chunked N-D arrays for cloud storage. Compressed arrays, parallel I\u002FO, S3\u002FGCS integration, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":90,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":18},"01M72DTXQREMCRKA8NHCVKHN4W","zapier-workflows","Manage and trigger pre-built Zapier workflows and MCP tool orchestration. Use when user mentions workflows, Zaps, automations, daily digest, research, search, lead tracking, expenses, or asks to \"run\" any process. Also handles Perplexity-based research and Google Sheets data tracking.","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzapier-workflows\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzapier-workflows\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":18},"01M72DTT17TBSJ0Y8J2XZ4C9TZ","zapier-make-patterns","No-code automation democratizes workflow building. Zapier and Make (formerly Integromat) let non-developers automate business processes without writing code. But no-code doesn't mean no-complexity - these platforms have their own patterns, pitfalls, and breaking points.  This skill covers when to use which platform, how to build reliable automations, and when to graduate to code-based solutions. Key insight: Zapier optimizes for simplicity and integrations (7000+ apps), Make optimizes for power","https:\u002F\u002Fgithub.com\u002FSansar35\u002Fclaude-agent\u002Fblob\u002Fmain\u002Fclaude-config\u002Fskills\u002Fzapier-make-patterns\u002FSKILL.md",[],[]]