gedi2py.tools.impute

gedi2py.tools.impute(adata, *, samples=None, key='gedi', layer_added=None, copy=False)[source]

Compute imputed expression values from GEDI model.

Imputed values are computed as the expected expression under the GEDI model: Y_imputed = Z @ Q_i @ D @ B_i + o + o_i + s_i for each sample.

Parameters:
  • adata (AnnData) – Annotated data matrix with GEDI results.

  • samples (list[int] | None, default: None) – List of sample indices to impute. If None, imputes all samples.

  • key (str, default: 'gedi') – Key in adata.uns where GEDI results are stored.

  • layer_added (str | None, default: None) – Layer name to store imputed values. If None, defaults to {key}_imputed.

  • copy (bool, default: False) – If True, return the imputed matrix instead of storing in adata.

Return type:

AnnData | ndarray | None

Returns:

  • If ``copy=True``, returns imputed expression matrix (n_cells, n_genes).

  • Otherwise, stores in ``adata.layers[layer_added]`` and returns ``None`.`

Notes

The imputed expression is computed sample-by-sample to preserve the sample-specific components (Q_i, o_i, s_i).

Examples

>>> import gedi2py as gd
>>> gd.tl.gedi(adata, batch_key="sample", n_latent=10)
>>> gd.tl.impute(adata)
>>> adata.layers["gedi_imputed"]