Skip to content
Skillpedia
Analysis & spreadsheets51k · #1832

anndata

Lets your agent work with single-cell data in specific formats. It's useful for organizing and analyzing complex biological research information.

What it does

AnnData is a package that helps organize and analyze scientific data, especially from single-cell genomics. It stores the main measurements (X) along with information about the samples (obs) and the measured features (var).

When to use it

  • ✓When creating or reading scientific data files like .h5ad or .zarr.
  • ✓When working with single-cell genomics data.
  • ✓When combining multiple datasets or experimental batches.

Example of what to ask your AI

“How can I read a data file named 'my_data.h5ad'?”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/anndata/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/anndata/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

AnnData organizes your data into a main structure (X) and adds descriptive metadata (obs, var). It allows you to read and write this data efficiently in common formats like .h5ad and .zarr.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add K-Dense-AI/scientific-agent-skills --skill anndata

Or download just the file:

curl -L https://raw.githubusercontent.com/K-Dense-AI/scientific-agent-skills/main/skills/anndata/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

AnnData

Overview

AnnData is a Python package for handling annotated data matrices, storing experimental measurements (X) alongside observation metadata (obs), variable metadata (var), and multi-dimensional annotations (obsm, varm, obsp, varp, uns). Originally designed for single-cell genomics through Scanpy, it now serves as a general-purpose framework for any annotated data requiring efficient storage, manipulation, and analysis.

When to Use This Skill

Use this skill when:

  • Creating, reading, or writing AnnData objects
  • Working with h5ad, zarr, or other genomics data formats
  • Performing single-cell RNA-seq analysis
  • Managing large datasets with sparse matrices or backed mode
  • Concatenating multiple datasets or experimental batches
  • Subsetting, filtering, or transforming annotated data
  • Integrating with scanpy, scvi-tools, or other scverse ecosystem tools

Installation

Targets AnnData 0.13.4 (current PyPI release reviewed 2026-09-30), requiring Python 3.12+. Small synthetic checks cover dense/sparse matrices, native I/O, metadata, concatenation, and lazy reads. File paths, biological analysis, remote stores, and third-party integration examples are illustrative unless stated otherwise.

uv pip install "anndata==0.13.4"

# Lazy I/O and dask-backed operations
uv pip install "anndata[dask,lazy]==0.13.4"

Use unpinned installs only when intentionally tracking the latest compatible release.

Current API notes:

  • Use anndata.io for non-native read_* and write_* helpers. Top-level anndata.read_h5ad and anndata.read_zarr remain supported.
  • Use ad.concat; AnnData.concatenate() was removed in 0.13. Avoid old ad.read, deprecated AnnData.*_keys() helpers and anndata.__version__; prefer explicit readers, mapping .keys(), and importlib.metadata.version("anndata").
  • In 0.13, .X is also layers[None]; layer iteration includes None. Use key is not None when selecting named layers. View .X writes now use copy-on-write.
  • Zarr v3 and automatic sharding are the defaults; the Python dependency is Zarr >=3. Dense H5AD X remains writable with backed="r+", but backed sparse item assignment is unsupported in 0.13.
  • AnnLoader and Loom reading/writing are deprecated. AnnCollection and other experimental APIs need the caveats in the references.

These changes are documented in the official release notes. The live docs header still displayed 0.13.3.post0 at review; behavior below was also checked against installed 0.13.4 source.

Quick Start

Creating an AnnData object

import anndata as ad
import numpy as np
import pandas as pd

# Minimal creation
X = np.random.rand(100, 2000)  # 100 cells × 2000 genes
adata = ad.AnnData(X)

# With metadata
obs = pd.DataFrame({
    'cell_type': ['T cell', 'B cell'] * 50,
    'sample': ['A', 'B'] * 50
}, index=[f'cell_{i}' for i in range(100)])

var = pd.DataFrame({
    'gene_name': [f'Gene_{i}' for i in range(2000)]
}, index=[f'ENSG{i:05d}' for i in range(2000)])

adata = ad.AnnData(X=X, obs=obs, var=var)

Reading data

# Native formats (read_h5ad/read_zarr remain at top-level)
adata = ad.read_h5ad('data.h5ad')
source = ad.read_h5ad('large_data.h5ad', backed='r')  # X backed; metadata/layers can load
try:
    subset = source[:100, :].to_memory()
finally:
    source.file.close()
adata = ad.read_zarr('data.zarr')

# Other formats: prefer anndata.io (top-level imports are deprecated)
from anndata.io import read_csv, read_loom, read_mtx

adata = read_csv('data.csv')
adata = read_loom('data.loom')

# 10X Genomics: use scanpy (not anndata) — see scanpy skill
import scanpy as sc
adata = sc.read_10x_h5('filtered_feature_bc_matrix.h5')
adata = sc.read_10x_mtx('filtered_feature_bc_matrix/')

Writing data

# Write h5ad file
adata.write_h5ad('output.h5ad')

# Write with compression
adata.write_h5ad('output.h5ad', compression='gzip')

# Write other formats
adata.write_zarr('output.zarr')
adata.write_csvs('output_dir/', skip_data=False)  # Lossy; may densify X

Basic operations

# Subset by conditions
t_cells = adata[adata.obs['cell_type'] == 'T cell']

# Subset by indices
subset = adata[0:50, 0:100]

# Add metadata
adata.obs['quality_score'] = np.random.rand(adata.n_obs)
adata.var['highly_variable'] = np.random.rand(adata.n_vars) > 0.8

# Access dimensions
print(f"{adata.n_obs} observations × {adata.n_vars} variables")

…
FAQ

What are 'obs' and 'var'?

'obs' contains information about the observations (like cells), and 'var' contains information about the measured variables (like genes).

Can I use AnnData with large datasets?

Yes, AnnData supports 'backed mode' for working with large files that don't fit entirely in memory.

How do I install AnnData?

You can install it using pip with the command: `uv pip install anndata`.

Details

Original description by the author

Handles annotated matrices in single-cell analysis, .h5ad and Zarr files, and integration with the scverse ecosystem. This is the data format skill—for analysis workflows use scanpy; for probabilistic models use scvi-tools; for population-scale queries use cellxgene-census.

repo: K-Dense-AI/scientific-agent-skills

Popularity

GitHub stars
51k
Ranking position
#1832
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills