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 inadata.obsto use for grouping by sample or context.score_key (
str(default:None)) – Column name of the score inliana_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 fromadata.uns[uns_key].source_key (
str(default:'source')) – Column name of the sender/source cell types inliana_res.target_key (
str(default:'target')) – Column name of the receiver/target cell types inliana_res.ligand_key (
str(default:'ligand_complex')) – Column name of the ligand inliana_res.receptor_key (
str(default:'receptor_complex')) – Column name of the receptor inliana_res.uns_key (
str(default:'liana_res')) – Key inadata.unsthat 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 islambda x: 1 - xwhich 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_tensorfunction.
- Returns:
Returns a tensor of shape (n_samples, n_senders, n_receivers, n_interactions) or a dictionary of tensors if
return_dictis True.- Raises:
AttributeError – If neither
liana_resoradataare provided.AssertionError – If
uns_keyis not provided when given anadatainstance.ValueError – If any of the provided keys (
sample_key,source_key,target_key,ligand_keyorreceptor_key) are not found inliana_res.uns[uns_key]or if input data contains duplicates.