[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7BJXDF0XKPBVDSS3P1W4XYB":3,"skill-same:01M7BJXDF0XKPBVDSS3P1W4XYB":57},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7BJXDF0XKPBVDSS3P1W4XYB","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.","YYC-Cube\u002FYYC3-Knowledge-Base","YYC-Cube","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235006543?v=4","01M79J2PH4SWD2X0825X6PN748","yyc3","01M79J2PHVK3F6ZBYT8K2SCZCW",1,"MIT","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-claude-code-templates-main\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fcellxgene-census\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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","87afe6ce96220accf50a345dea46784c8c9f210e","YYC3-AI-应用工具\u002FYYC3-AI-应用工具-claude-code-templates-main\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fcellxgene-census",0,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base","https:\u002F\u002Fkb.yyc3.top\u002F","https:\u002F\u002Fgithub.com\u002FYYC-Cube","万象归元于云枢 | 深栈智启新纪元","2026-11-10 10:37:32",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill cellxgene-census",{"tool":39,"command":40},"bunx","bunx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill cellxgene-census",{"tool":42,"command":43},"pnpm","pnpm dlx skills add YYC-Cube\u002FYYC3-Knowledge-Base --skill cellxgene-census","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-claude-code-templates-main\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fcellxgene-census\u002FSKILL.md",true,[47,53],{"path":48,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":51,"sourceHtmlUrl":52},"references\u002Fcensus_schema.md","REFERENCE","参考文档",5649,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-claude-code-templates-main\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fcellxgene-census\u002Freferences\u002Fcensus_schema.md",{"path":54,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":55,"sourceHtmlUrl":56},"references\u002Fcommon_patterns.md",9935,"https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-AI-应用工具\u002FYYC3-AI-应用工具-claude-code-templates-main\u002Fcli-tool\u002Fcomponents\u002Fskills\u002Fscientific\u002Fcellxgene-census\u002Freferences\u002Fcommon_patterns.md",[58,65,72,79,86,93],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M7CTDWHERCXPQCP0K03A86AS","vercel-sandbox","Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fvercel-sandbox\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M7CTD8D2BNJY54S65M47HEJA","slack","Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fslack\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M7CTCSSB8ZP3Q58C3YZDZK1W","electron","Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Felectron\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M7CTCBJY76688V4DCZGWFHGQ","dogfood","Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app\u002Fsite\u002Fplatform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fdogfood\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M7CTC4H0FFGVEAQR9PA4GA1A","agent-browser","Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to \"open a website\", \"fill out a form\", \"click a button\", \"take a screenshot\", \"scrape data from a page\", \"test this web app\", \"login to a site\", \"automate browser actions\", or any task requiring programmatic web interaction.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-WebSpec-Web标准\u002FYYC3-WebSpec-Web标准-standards\u002Fbrowser-agent\u002Fskills\u002Fagent-browser\u002FSKILL.md",[],[],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":19},"01M7CTBKVFYBG78FDSABSDJTTQ","shadcn","Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn\u002Fui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for \"shadcn init\", \"create an app with --preset\", \"switch to --preset\", and for building a design system or applying a DESIGN.md or brand spec to shadcn\u002Fui.","https:\u002F\u002Fgithub.com\u002FYYC-Cube\u002FYYC3-Knowledge-Base\u002Fblob\u002Fmain\u002FYYC3-UI-界面组件\u002FYYC3-UI-界面组件-ui\u002Fskills\u002Fshadcn\u002FSKILL.md",[],[]]