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)#
Apply latent factor identification (NMF, LDA, or DRVI) to reduce the dimensionality of gene expression data.
- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object with the specified layer containing AnnData.
method (str, optional) – One of
"NMF","LDA", or"DRVI". Defaults to"NMF".layer (str, optional) – The AnnData layer in
sdatato operate on. Defaults to"segmentation_free_table".n_components (int, optional) – Number of latent dimensions (ignored if a pretrained DRVI model is loaded). Defaults to
20.copy (bool, optional) – If truthy, return the modified SpatialData object; otherwise modify
sdatain place and returnNone.random_state (int, optional) – Random seed for
"NMF"and"LDA".drvi_model_path (str, optional) – Path to a pretrained DRVI model to load instead of training a new one.
**kwargs – Additional parameters. For
"NMF"/"LDA"these are forwarded tomodel.fit_transform/model.fit. For"DRVI"the following are popped before constructing/training the model:encoder_dims(list of int),decoder_dims(list of int),n_epochs(int),kl_warmup(int),is_count_data(bool),early_stopping(bool),accelerator(str),devices(int).
- Returns:
spatialdata.SpatialData or None Modified SpatialData object if
copyis truthy; otherwiseNone.