drvi.utils.tools.set_latent_dimension_stats#
- drvi.utils.tools.set_latent_dimension_stats(model, embed, inplace=True, vanished_threshold=0.5)[source]#
Set the latent dimension statistics of a DRVI embedding into var of an AnnData.
This function delegates to the model’s
set_latent_dimension_stats()method. It is provided for backward compatibility; prefer callingmodel.set_latent_dimension_stats(embed, ...)directly.- Parameters:
model (
DRVI) – DRVI model object that has been trained and can compute reconstruction effects.embed (
AnnData) – AnnData object containing the latent representation (embedding) of the model. The latent dimensions should be in the.Xattribute.inplace (
bool(default:True)) – Whether to modify the input AnnData object in-place or return a new copy.vanished_threshold (
float(default:0.5)) – Threshold for determining if a latent dimension has “vanished” (become inactive). Dimensions with max absolute values below this threshold are marked as vanished.
- Return type:
- Returns:
AnnData or None If
inplace=True(default), modifies the input AnnData object and returns None. Ifinplace=False, returns a new AnnData object with the statistics added.
Notes
The function adds the following columns to
embed.var:original_dim_id: Original dimension indicesreconstruction_effect: Reconstruction effect scores from the DRVI modelorder: Ranking of dimensions by reconstruction effect (descending)max_value: Maximum absolute value across all cells for each dimensionmean: Mean value across all cells for each dimensionmin: Minimum value across all cells for each dimensionmax: Maximum value across all cells for each dimensionstd: Standard deviation of absolute values across all cells for each dimensiontitle: Dimension titles in format “DR {order+1}”vanished: Boolean indicating if dimension is considered “vanished” (max_value < threshold)
Examples
>>> # Backward-compatible usage >>> latent_adata = model.get_latent_representation(adata, return_anndata=True) >>> set_latent_dimension_stats(model, latent_adata, inplace=True) >>> # Preferred: call on the model directly >>> model.set_latent_dimension_stats(latent_adata, inplace=True)