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 0x760ec1da6520>)) – Function applied to scores for which a lower value is the stronger one – p-values and aggregate ranks such asmagnitude_rank– so that “higher is stronger” holds throughout. Defaults to-log10(x + eps). Which scores are inverted is decided byliana.method.get_method_scores, so this is handled automatically for liana’s own scores.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.
Examples
Expects a by-sample ligand-receptor result, as written by any method’s
.by_sample. A toy result stands in here:>>> import liana as li >>> adata = li.testing.generate_toy_adata() >>> adata.uns['liana_res'] = li.testing.sample_lrs(by_sample=True) >>> tensor = li.mu.to_tensor_c2c(adata, ... sample_key='sample', ... score_key='specificity_rank')
The tensor can then be decomposed with Tensor-cell2cell.