scviva.tools.vision.compute_signatures_anndata#

scviva.tools.vision.compute_signatures_anndata(adata, norm_data_key, signature_varm_key, signature_names_uns_key=None, sig_norm_method='znorm_columns', device='auto', batch_size=1200)[source]#

Compute per-cell signature scores.

For sparse expression matrices the computation is performed entirely without densifying the n_cells x n_genes matrix. A NormData object is built from the expression data and _batch_sig_eval_norm() is called, selecting CUDA -> MPS -> scipy automatically.

For dense inputs the existing VISION z-score formula is retained.

Parameters:
adata AnnData

AnnData object.

norm_data_key Union[Literal['use_raw'], str, None]

Key in adata.layers for the expression matrix, or "use_raw" to read from adata.raw.X. Pass None to use adata.X.

signature_varm_key str

Key in adata.varm for the (n_genes x n_sigs) signature weight matrix (+1 up-regulated, -1 down-regulated, 0 absent).

signature_names_uns_key str | None

Key in adata.uns for column names. When None (or when the stored names don’t match the number of signatures), column names are read from the DataFrame index (if applicable) or auto-generated.

sig_norm_method str

Normalisation method passed to get_normalized_copy_sparse() for the sparse path. Matches R VISION’s sig_norm_method parameter; default "znorm_columns" (z-normalise each cell across genes).

device str

Compute device for _batch_sig_eval_norm(); "auto" by default. "cpu" forces the deterministic scipy sparse path (see _resolve_torch_device()).

batch_size int

Signatures processed per batch, by default 1200.

Return type:

DataFrame

Returns:

pd.DataFrame of shape (n_cells, n_sigs) Per-cell signature scores. Also stored via adata.obsm["vision_signatures"]; adata.uns["norm_data_key"] and adata.uns["signature_varm_key"] record the keys used.