liana.mt.inflow.__call__

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.obs containing cell type labels. If provided, a one-hot encoding will be created. Mutually exclusive with obsm_key.

obsm_key str | None (default: None)

Key in adata.obsm containing 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 with groupby.

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 via resource and resource_name.

resource DataFrame | None (default: None)

A pandas dataframe with [ligand, receptor] columns. If provided will overrule the resource requested via resource_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.obsp that 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 .raw attribute 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_prop to 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 AnnData input:

x_name

Name of the x-variable. If passing a resource dataframe, this should match the first column. By default: ‘ligand’.

y_name

Name of the y-variable. If passing a resource dataframe, this should match the second column. By default: ‘receptor’.

For a MuData input:

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 resource dataframe, this should match the first column. By default: ‘x’.

y_name

Name of the y-variable. If passing a resource dataframe, 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.

Return type:

AnnData

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 groupby parameter) 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 via obsm_key instead of groupby, which is what deconvolved spot data calls for.