liana.mt.inflow.__call__#
- inflow.__call__(adata, groupby=None, obsm_key=None, resource_name=None, resource=None, interactions=None, nz_prop=0.001, connectivity_key='spatial_connectivities', complex_sep='_', x_transform=None, y_transform=None, use_raw=False, layer=None, xy_sep='^', verbose=False, **kwargs)#
A method for trivariate (source cell type, ligand, receptor) local spatial metrics.
- Parameters:
- adata
AnnData|MuData Annotated data object.
- groupby
str|None(default:None) Column name in
adata.obscontaining cell type labels. If provided, a one-hot encoding will be created. Mutually exclusive withobsm_key.- obsm_key
str|None(default:None) Key in
adata.obsmcontaining a pre-computed cell type matrix (pandas DataFrame) of shape (n_obs, n_celltypes). Column names will be used as cell type labels. Can contain binary (one-hot) or continuous (probabilities/scores) values. Mutually exclusive withgroupby.- interactions
list[tuple[str,str]] |None(default:None) List of tuples with ligand-receptor pairs
[(ligand, receptor), ...]to be used for the analysis. If passed, it will overrule the resource requested viaresourceandresource_name.- resource
DataFrame|None(default:None) A pandas dataframe with [
ligand,receptor] columns. If provided will overrule the resource requested viaresource_name- resource_name
str|None(default:None) Name of the resource to be used for ligand-receptor inference. See
li.rs.show_resources()for available resources.- connectivity_key
str(default:'spatial_connectivities') Key in
adata.obspthat contains the spatial connectivity matrix. Default is'spatial_connectivities'.- layer
str|None(default:None) Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.
- use_raw
bool(default:False) Whether to use the
.rawattribute of adata. Defaults to False (uses.X).- nz_prop
float(default:0.001) Minimum proportion of non-zero values for each features. For example, if working with gene expression data, this would be the proportion of cells expressing a gene. Both features must have a proportion greater than
nz_propto be considered in the analysis.- complex_sep
str|None(default:'_') Separator to use for complex names.
- xy_sep
str(default:'^') Separator to use for interaction names.
- x_transform
Callable[...,NDArray[number] |csc_matrix|csr_matrix|csc_array|csr_array] |None(default:None) Function used to transform the source-ligand values. If None, no transformation is applied.
- y_transform
Callable[...,NDArray[number] |csc_matrix|csr_matrix|csc_array|csr_array] |None(default:None) Function used to transform the receptor values. If None, no transformation is applied.
- verbose
bool(default:False) Verbosity flag.
- **kwargs
object Additional keyword arguments.
For an
AnnDatainput:- x_name
Name of the x-variable. If passing a
resourcedataframe, this should match the first column. By default: ‘ligand’.- y_name
Name of the y-variable. If passing a
resourcedataframe, this should match the second column. By default: ‘receptor’.
For a
MuDatainput:- x_mod
Name of the modality to use for the x-axis.
- y_mod
Name of the modality to use for the y-axis.
- x_name
Name of the x-variable. If passing a
resourcedataframe, this should match the first column. By default: ‘x’.- y_name
Name of the y-variable. If passing a
resourcedataframe, this should match the second column. By default: ‘y’.- x_use_raw: bool
Whether to use raw counts for x modality.
- y_use_raw: bool
Whether to use raw counts for y modality.
- x_layer: str
Layer to use for x modality.
- y_layer: str
Layer to use for y modality.
For either input:
- x_transform_kwargs: dict
Keyword arguments to pass to x_transform function.
- y_transform_kwargs: dict
Keyword arguments to pass to y_transform function.
- adata
- Return type:
- Returns:
An AnnData object of shape (n_cell_type_ligand_receptor_combinations, n_observations), where n_cell_type_ligand_receptor_combinations corresponds to the combinations of cell types (as defined by the
groupbyparameter) with ligands and receptors expressed in the data and covered by the resource, and n_observations is the number of observations.
Examples
For each cell, scores how much of a given ligand reaches it from a given neighbouring cell type, against its own receptor expression:
>>> import liana as li >>> adata = li.ds.generate_toy_spatial() >>> lrdata = li.mt.inflow(adata, groupby="bulk_labels", resource_name="consensus")
The result is cells by
'source^ligand^receptor'triplets, e.g.'CD4+/CD25 T Reg^HLA-DRA^CD4'. Cell-type proportions per spot can be given viaobsm_keyinstead ofgroupby, which is what deconvolved spot data calls for.