liana.multi.nmf

Contents

liana.multi.nmf#

liana.multi.nmf(adata=None, df=None, n_components=None, k_range=range(1, 11), use_raw=False, layer=None, inplace=True, verbose=False, **kwargs)#

Fits NMF to an AnnData object.

Parameters:
  • adata (AnnData (default: None)) – Annotated data object.

  • df (DataFrame (default: None)) – Alternative input for data as a DataFrame, only used if adata is None.

  • n_components (int | None (default: None)) – Number of components to use. If None, the number of components is estimated using the elbow method.

  • k_range (range (default: range(1, 11))) – Range of components to test. Default: range(1, 10).

  • use_raw (bool (default: False)) – Use raw attribute of adata if present.

  • layer (str | None (default: None)) – Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.

  • inplace (bool (default: True)) – Whether to store results in place, or else to return them.

  • **kwargs – Keyword arguments to pass to sklearn.decomposition.NMF.

Return type:

tuple[ndarray, ndarray, DataFrame | None, int] | None

Returns:

If inplace is True, it will add NMF_W and NMF_H to the adata.obsm and adata.varm. If n_components is None, it will also add nfm_errors and nfm_rank to adata.uns.

If inplace is False, it will return W and H, and if n_components is None, it will also return errors and n_components. If n_components is None and inplace, errors and n_components will be assigned to adata.uns. If df is provided, inplace is always False.

Raises:

ValueError – If adata is provided but it’s not a valid instance of an AnnData object or neither an AnnData or DataFrame intance is provided as input