scpdac.pp.align_to_genes#
- scpdac.pp.align_to_genes(adata, genes, *, missing='error', layer=None)#
Subset/reindex an
AnnDatato a fixed gene panel and order.Ensures the returned object’s
var_namesexactly matchgenes(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 ingenesthat are absent fromadata:"error"raises aValueErrorlisting 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 alongsideX(and any zero-imputed columns are zero in that layer too).
- Return type:
- Returns:
A new
AnnDatawhosevar_namesequalgenes.- Raises:
ValueError – If
missing="error"and some requested genes are absent, or ifmissingis not a recognised option.