troutpy.tl.latent_factor

Contents

troutpy.tl.latent_factor#

troutpy.tl.latent_factor(sdata, method='NMF', layer='segmentation_free_table', n_components=20, copy=None, random_state=None, drvi_model_path=None, **kwargs)#

Applies latent factor identification (NMF, LDA, or DRVI) to reduce dimensionality of gene expression data.

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object with the specified layer containing AnnData.

  • method (str) – One of “NMF”, “LDA”, or “DRVI”.

  • layer (str) – The AnnData layer in SpatialData to operate on.

  • n_components (int) – Number of latent dimensions (ignored if DRVI model is loaded).

  • copy (bool) – If True, return modified SpatialData. If False, operate in-place.

  • random_state (int or None) – Random seed.

  • drvi_model_path (str) – Path to a pretrained DRVI model.

  • kwargs (dict) – Additional parameters for DRVI: - encoder_dims : list[int] - decoder_dims : list[int] - n_epochs : int - kl_warmup : int - is_count_data : bool - early_stopping : bool - accelerator : str - devices : int

Returns:

sdata : SpatialData or None Modified SpatialData object or None if copy=False.