liana.ms.to_tensor_c2c#
- liana.ms.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_fn=<function DefaultValues.inverse_fn>, non_negative=True, return_dict=False, **kwargs)#
Function to convert a LIANA result to a tensor for cell2cell analysis.
- Parameters:
- adata
AnnData|None(default:None) Annotated data object.
- sample_key
str|None(default:None) key in
adata.obsto use for grouping by sample or context.- score_key
str|None(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.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_fn
Callable[[Series],Series] (default:<function DefaultValues.inverse_fn at 0x7e3fdb8699e0>) Function applied to scores for which a lower value is the stronger one – p-values and aggregate ranks such as
magnitude_rank– so that “higher is stronger” holds throughout. Defaults to-log10(x + eps). Which scores are inverted is decided byliana.mt.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
object keyword arguments to pass to Tensor-cell2cell’s
cell2cell.tensor.external_scores.dataframes_to_tensorfunction.
- adata
- Return type:
- Returns:
Returns a tensor of shape (n_samples, n_senders, n_receivers, n_interactions) or a dictionary of tensors if
return_dictis True.- Raises:
AssertionError – If
uns_keyis not provided when given anadatainstance.ValueError – If neither
liana_resoradataare provided, or 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.ds.generate_toy_adata() >>> adata.uns["liana_res"] = li.ds.sample_lrs(by_sample=True) >>> tensor = li.ms.to_tensor_c2c(adata, sample_key="sample", score_key="specificity_rank")
The tensor can then be decomposed with Tensor-cell2cell.