liana.utils.get_variable_loadings

liana.utils.get_variable_loadings#

liana.utils.get_variable_loadings(adata=None, varm_key=None, view_sep=None, variable_sep=None, pair_sep=None, var_names=None, pair_names=None, drop_columns=True, loadings=None)#

Extract variable loadings from an AnnData object.

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

  • varm_key (str (default: None)) – Key to use when extracting variable loadings from mdata.varm. Ignored when loadings is provided.

  • view_sep (str | None (default: None)) – Separator to use when splitting view:variable names into view and variable

  • variable_sep (str | None (default: None)) – Separator to use when splitting variable names into var_names

  • pair_sep (str | None (default: None)) – Separator to use when splitting view names into pair_names

  • var_names (list (default: None)) – Variable names given to the splitted variable (‘ligand_complex’ and ‘receptor_complex’ by default)

  • pair_names (list (default: None)) – Variable names given to the splitted pair (‘source’ and ‘target’ by default)

  • drop_columns (bool (default: True)) – If True, drop the view:variable column

  • loadings (DataFrame | dict | None (default: None)) – Pre-extracted loadings to use instead of reading from adata.varm. Either a features-by-factors DataFrame, or a dict of per-view features-by-factors DataFrames (e.g. the output of a MOFA-Flex model’s get_weights()), which is concatenated feature-wise. When provided, adata and varm_key are ignored and the existing factor column names are preserved.

Return type:

DataFrame

Returns:

Returns a pandas DataFrame with the variable loadings for the specified index.

Raises:

ValueError – If varm_key not found in .varm (when loadings is not provided)