mechanochat.tools.cluster_communication#

mechanochat.tools.cluster_communication(adata: AnnData, cluster_key: str, signal: str, prefix: str = 'mechano', n_permutations: int = 100, seed: int = 0)[source]#

Aggregate a cell-level signal matrix into cluster-cluster communication.

The mean signal of every ordered cluster pair is compared against a permutation null obtained by shuffling the cluster labels.

Parameters:
  • adata (Anndata) – AnnData providing the signal matrix in .obsp[<prefix>_<signal>] and the cluster labels in .obs[cluster_key] (must be categorical).

  • cluster_key (str) – Key of the cell grouping in .obs.

  • signal (str) – Name of the signal, such as a ligand-receptor pair, a pathway, a mechanosensitive gene.

  • prefix (str) – Prefix of the signal key in .obsp

  • n_permutations (int) – Number of label permutations used for the p-value.

  • seed (int) – Seed of the random generator used for the permutations.

Returns:

  • None

  • Sets the following fields in adata –

    • .uns[‘<cluster_key>_<prefix>_<signal>’] as a dict with keys ‘communication_matrix’

      (mean signal per cluster pair), ‘communication_pvalue’, ‘adjusted_communication_pvalue’. Both are DataFrames indexed by cluster name, with the same orientation as the underlying .obsp matrix.