Accessors and Extensions
Use this sub-skill when code needs portable references to arrays inside AnnData objects or a small typed namespace attached to AnnData instances.
Route Here
- Build and inspect
anndata.accreferences such asA.obs["batch"],A.var["symbol"],A.obsm["pca"][:, 0],A.layers["counts"][:, "gene-a"],A.obsp["connectivities"][:, "cell-a"], orA.X[:, :]. - Check whether a reference/accessor is present in an object with
ref in adataorA.obsm in adata, then extract values withadata[ref]. - Parse or serialize references with
A.resolve(...),A.to_json(ref), andA.from_json(data)for validation/configuration layers. - Register a typed extension namespace with
anndata.register_anndata_namespace(name)for library-style helpers onAnnData.
Route Elsewhere
- For
AnnDatashape, view,obs/var,layers,obsm,obsp, and container mutation semantics, use../data-model/SKILL.md. - For
.h5ad, Zarr, lazy/backed reads, or element I/O, use../storage-io/SKILL.md. - For
anndata.concat,concat_on_disk,AnnCollection, or batch-combination choices, use../combining-data/SKILL.md.
References
references/api-reference.mdlists the accessor classes, signatures, object relationships, and extraction contracts.references/accessor-recipes.mdgives practical recipes for membership checks, extraction, JSON/string parsing, and validation-friendly reference handling.references/extension-namespaces.mdcovers the namespace decorator, class shape, validation, caching, and conflict avoidance.references/troubleshooting.mdmaps common accessor and namespace failures to fixes.scripts/demo_anndata_accessor.pyis a tiny runnable demo for refs, extraction, JSON/string parsing, and namespace registration.
Operating Rules
- Treat
AdRefobjects as object-independent references; validateref in adatabefore extraction when user input or optional fields are involved. - Prefer public
AnnDataAPIs and small typed namespace methods; extension namespaces are for library code, not ad-hoc per-notebook state. - Keep plotting/data-selection APIs accepting either
AdRefinstances or parseable strings, then normalize to refs withA.resolve(..., strict=True).