liana.multi.lrs_to_views

Contents

liana.multi.lrs_to_views#

liana.multi.lrs_to_views(adata, score_key=None, inverse_fun=<function DefaultValues.inverse_fun>, obs_keys=None, lr_prop=0.5, lr_fill=nan, lrs_per_view=20, lrs_per_sample=10, samples_per_view=3, min_variance=0, min_var_nbatches=1, batch_key=None, lr_sep='^', cell_sep='&', var_sep=':', uns_key='liana_res', sample_key='sample', source_key='source', target_key='target', ligand_key='ligand_complex', receptor_key='receptor_complex', verbose=False)#

Converts a LIANA result to a MuData object with views that represent an aggregate for each entity in adata.obs[groupby].

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

  • score_key (str | None (default: None)) – Column name of the score in liana_res. If None, the score is inferred from the method.

  • inverse_fun (Callable (default: <function DefaultValues.inverse_fun at 0x70889f57c680>)) – Function that is applied to the scores before building the views. Default is lambda x: 1 - x which is used to invert the scores reflect probabilities (e.g. magnitude_rank), i.e. such for which lower values reflect higher relevance. This is handled automatically for the scores in liana.

  • obs_keys (list | None (default: None)) – List of keys in adata.obs that should be included in the MuData object. These columns should correspond to the number of samples in adata.obs[sample_key].

  • lr_prop (float (default: 0.5)) – Reflects the minimum required proportion of samples for an interaction to be considered for building the views.

  • lr_fill (float (default: nan)) – Value to fill in for interactions that are not present in a view. Default is np.nan.

  • lrs_per_view (int (default: 20)) – Reflects the minimum required number of interactions in a view to be considered for building the views.

  • lrs_per_sample (int (default: 10)) – Reflects the minimum required number of interactions in a sample to be considered when building a specific view.

  • samples_per_view (int (default: 3)) – Reflects the minimum required samples to keep a view.

  • min_variance (int (default: 0)) – Reflects the minimum required variance across samples for each interaction in each view. NaNs are ignored when computing the variance.

  • min_var_nbatches (int (default: 1)) – Reflect the minimum number of batches (>=) that must have a variance above min_variance for an interaction to be included in the view.

  • batch_key (str (default: None)) – Key in adata.obs that represents the batch information. Used solely when computing the variance. If batch_key is not None, the variance is computed per batch, and the ``

  • lr_sep (str (default: '^')) – Separator to use when joining ligand and receptor names into interactions.

  • cell_sep (str (default: '&')) – Separator to use for the cell names in the views.

  • var_sep (str (default: ':')) – Separator to use for the variable names in the views.

  • uns_key (str (default: 'liana_res')) – Key in adata.uns that contains the LIANA results. Default is 'liana_res'.

  • sample_key (str (default: 'sample')) – key in adata.obs to use for grouping by sample or context.

  • source_key (str (default: 'source')) – Column name of the sender/source cell types in liana_res.

  • target_key (str (default: 'target')) – Column name of the receiver/target cell types in liana_res.

  • ligand_key (str (default: 'ligand_complex')) – Column name of the ligand in liana_res.

  • receptor_key (str (default: 'receptor_complex')) – Column name of the receptor in liana_res.

  • verbose (bool (default: False)) – Verbosity flag.

Return type:

MuData

Returns:

Returns a MuData object with views that represent an aggregate for each entity in adata.obs[groupby].

Raises:

ValueError – If any of the provided keys are not found in the corresponding adata view.