scpdac.pp.align_to_genes

Contents

scpdac.pp.align_to_genes#

scpdac.pp.align_to_genes(adata, genes, *, missing='error', layer=None)#

Subset/reindex an AnnData to a fixed gene panel and order.

Ensures the returned object’s var_names exactly match genes (in the given order), which is required so that model inputs always align with the feature order the packaged models were trained on.

Parameters:
  • adata (AnnData) – The input object to align. Not modified in place.

  • genes (list[str]) – The target gene panel, in the desired order.

  • missing (str (default: 'error')) – How to handle genes in genes that are absent from adata: "error" raises a ValueError listing the missing genes; "zeros" inserts all-zero columns for them and emits a warning with the count of imputed genes.

  • layer (str | None (default: None)) – If given, the named layer is realigned alongside X (and any zero-imputed columns are zero in that layer too).

Return type:

AnnData

Returns:

A new AnnData whose var_names equal genes.

Raises:

ValueError – If missing="error" and some requested genes are absent, or if missing is not a recognised option.