liana.mt.compute_global_specificity

liana.mt.compute_global_specificity#

liana.mt.compute_global_specificity(adata, groupby, lr_sep='^', n_perms=1000, seed=1337, n_jobs=-1, verbose=False, use_raw=False, layer=None, uns_key='global_interactions')#

Computes group-specific ligand-receptor means and permutation-based p-values.

This function performs a one-sided permutation test to assess whether the observed group-specific means are significantly higher than expected by chance. P-values are computed using the formula (k + 1) / (n_perms + 1), where k is the number of permutations with values greater than or equal to the observed statistic.

Parameters:
adata AnnData

Annotated data object.

groupby str

Key to be used for grouping.

lr_sep str | None (default: '^')

Separator to use when joining ligand and receptor names into interactions.

n_perms int (default: 1000)

Number of permutations for the permutation test. If None, no p-values are computed.

seed int (default: 1337)

Random seed for reproducibility.

n_jobs int (default: -1)

Number of parallel jobs. Defaults to -1 (all available cores).

verbose bool (default: False)

Verbosity flag.

use_raw bool (default: False)

Whether to use the .raw attribute of adata. Defaults to False (uses .X).

layer str | None (default: None)

Layer in anndata.AnnData.layers to use. If None, use anndata.AnnData.X.

uns_key str (default: 'global_interactions')

Key in adata.uns that contains the LIANA results. Default is 'liana_res'.

Return type:

None

Returns:

None. The result with ‘lr_mean’ and ‘pval’ is stored in adata.uns["global_interactions"].

Examples

Takes the output of liana.mt.inflow, whose var_names are the 'source^ligand^receptor' triplets that lr_sep splits back apart:

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> lrdata = li.mt.inflow(adata, groupby="bulk_labels", resource_name="consensus")
>>> li.mt.compute_global_specificity(lrdata, groupby="bulk_labels", n_perms=10, use_raw=False, n_jobs=1)

One row per sender, ligand, receptor and receiver group, sorted by p-value. Use many more permutations than the 10 here – the smallest attainable p-value is 1/(n_perms+1). n_jobs=1 avoids the process-spawn overhead that the default -1 costs at this size.