genome_spy.anndata.from_anndata¶
- genome_spy.anndata.from_anndata(adata, *, obs=None, genes=(), obsm_keys=())View on GitHub¶
Prepare observation metadata, selected genes, and embedding components.
- Description:
Returns a pandas snapshot with one row per observation in source order. Gene fields use exact
var_namesand readX; embedding fields use Scanpy’s<key>-<component>naming. Only selected expression columns are densified. No analysis, file loading, or AnnData mutation occurs. The index contains observation names; charts omit it unless explicitly exported with pandasreset_index().
- Parameters:
adata – Source AnnData object or view.
obs – Observation columns to include.
Noneincludes all;[]includes none.genes – Exact variable names to extract from
X.obsm_keys – Embedding keys and zero-based integer component indices.
- Returns:
A pandas table accepted by
Chart, Arrow export, and widget updates.- Raises:
ImportError – If AnnData is unavailable; install the
anndataextra.TypeError – If the source is not AnnData or selected arrays are neither NumPy arrays, SciPy sparse arrays/matrices, nor pandas embeddings.
AnnDataProjectionError – If fields are absent or ambiguous, components are invalid, or requested output names collide.
Example
>>> import genome_spy as gs >>> from genome_spy.anndata import from_anndata >>> cells = from_anndata( ... adata, obs=["cell_type"], genes=["MS4A1"], ... obsm_keys=[("X_umap", 0), ("X_umap", 1)], ... ) >>> chart = gs.Chart(cells).mark_point().encode( ... x="X_umap-0", y="X_umap-1", color="MS4A1" ... )