scviva.tools.vision.compute_latent_space#
- scviva.tools.vision.compute_latent_space(adata, norm_data_key=None, filters=('threshold', 'fano'), threshold=10, num_mad=2.0, max_components=30, use_permutation_wpca=False, projection_genes=None, obsm_key='X_pca')[source]#
Filter genes, log-transform, and compute PCA; store result in
adata.obsm.Mirrors R VISION’s
computeLatentSpace, which orchestrates gene filtering,matLog2transform, and eitherapplyPCAorapplyPermutationWPCA.- Parameters:
- adata
AnnData Annotated data matrix.
- norm_data_key
str|None Key in
adata.layersto use as expression input. IfNone,adata.Xis used.- filters
Sequence[Literal['novar','threshold','fano']] Gene filters to apply before PCA, by default
("threshold", "fano"). Ignored when projection_genes is provided.- threshold
int Minimum number of cells for threshold / fano filters, by default 10.
- num_mad
float MAD multiplier for the fano filter, by default 2.0.
- max_components
int Maximum number of PCs to compute, by default 30.
- use_permutation_wpca
bool If
True, run permutation WPCA to select only statistically significant PCs. IfFalse(default), return all max_components PCs (mirrors R’sperm_wPCA=FALSEdefault).- projection_genes
Sequence[str] |None Explicit list of gene names to use. When provided, filters are skipped. Genes not found in
adata.var_namesare silently dropped.- obsm_key
str Key under which to store the PC coordinates in
adata.obsm, by default"X_pca".
- adata
- Return type:
- Returns:
AnnData The input adata modified in-place with:
adata.obsm[obsm_key]: ndarray (n_cells × n_sig_pcs)adata.uns["pca"]["variance_ratio"]: proportion variance per PCadata.uns["pca"]["gene_loadings"]: ndarray (n_genes × n_sig_pcs)adata.uns["pca"]["projection_genes"]: list of gene names used
- Raises:
ValueError – If no genes remain after filtering / intersection.