liana.multi.to_tensor_c2c

Contents

liana.multi.to_tensor_c2c#

liana.multi.to_tensor_c2c(adata=None, sample_key=None, score_key=None, liana_res=None, source_key='source', target_key='target', ligand_key='ligand_complex', receptor_key='receptor_complex', uns_key='liana_res', non_expressed_fill=None, inverse_fun=<function DefaultValues.inverse_fun>, non_negative=True, return_dict=False, **kwargs)#

Function to convert a LIANA result to a tensor for cell2cell analysis.

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

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

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

  • liana_res (DataFrame | None (default: None)) – A dataframe with the LIANA results. If None, it will be taken from adata.uns[uns_key].

  • 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.

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

  • non_expressed_fill (float | None (default: None)) – Value to fill for non-expressed ligand-receptor pairs.

  • 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.

  • non_negative (bool (default: True)) – Whether to make the tensor non-negative.

  • return_dict (bool (default: False)) – Whether to return a dictionary of tensors.

  • **kwargs – keyword arguments to pass to Tensor-cell2cell’s cell2cell.tensor.external_scores.dataframes_to_tensor function.

Returns:

Returns a tensor of shape (n_samples, n_senders, n_receivers, n_interactions) or a dictionary of tensors if return_dict is True.

Raises:
  • AttributeError – If neither liana_res or adata are provided.

  • AssertionError – If uns_key is not provided when given an adata instance.

  • ValueError – If any of the provided keys (sample_key, source_key, target_key, ligand_key or receptor_key) are not found in liana_res.uns[uns_key] or if input data contains duplicates.