scviva.tools.harreman.tools.compute_ct_cell_communication#

scviva.tools.harreman.tools.compute_ct_cell_communication(adata, layer_key_p_test=None, layer_key_np_test=None, model=None, cell_type_key=None, center_counts_for_np_test=False, subset_gene_pairs=None, subset_metabolites=None, fix_gp=False, M=1000, seed=42, test='both', mean='algebraic', check_analytic_null=False, device='auto', verbose=False)[source]#

Compute cell type-aware cell-cell communication scores.

Communication is stratified by interacting cell type pairs and supports parametric and non-parametric statistical inference.

Parameters:
adata AnnData

Annotated data object. Required fields include:
  • uns["gene_pairs"]: gene pairs involved in communication.

  • uns["gene_pairs_per_metabolite"]: maps metabolites to gene pairs.

  • uns["gene_pairs_per_ct_pair"]: gene pairs per cell type pair.

  • obsp["weights"]: sparse cell-cell proximity matrix.

  • obs[cell_type_key]: categorical cell type annotations.

  • uns["cell_type_pairs"]: list of interacting cell type pairs.

  • (Optional) uns["LR_database"]: for metabolite/pathway annotation.

layer_key_p_test Union[Literal['use_raw'], str, None]

Data layer to use for parametric test.

layer_key_np_test Union[Literal['use_raw'], str, None]

Data layer to use for non-parametric test.

model str

Normalization model to use for centering gene expression. Options include “none”, “normal”, “bernoulli”, or “danb”.

cell_type_key str | None

Key in adata.obs corresponding to cell type annotations. Required if not stored in uns.

center_counts_for_np_test bool | None

Whether to center expression counts using the specified model before non-parametric testing.

subset_gene_pairs list | None

Subset of gene pairs to consider. If None, uses all pairs.

subset_metabolites list | None

Subset of metabolites to include in the analysis.

fix_gp bool | None

If True, keeps gene pair identity fixed during permutation testing, randomizing cell types only.

M int | None

Number of permutations to use if permutation_test is True.

seed int | None

Random seed for permutation reproducibility.

test Union[Literal['parametric'], Literal['non-parametric'], Literal['both'], None]

Specifies which statistical test(s) to run.

mean Union[Literal['algebraic'], Literal['geometric'], None]

Averaging method for multi-gene modules.

check_analytic_null bool | None

Whether to compute Z-scores and p-values under the null distribution for the permutation test.

device device | str

PyTorch device to run computations on. Defaults to CUDA if available.

verbose bool | None

Whether to print progress and status messages.

Return type:

None

Returns:

None Results are stored in the following adata.uns fields:

  • ct_ccc_results["p"]: parametric results per gene pair, metabolite, and cell type.

  • ct_ccc_results["np"]: non-parametric scores, empirical p-values, and FDRs.

  • gene_pair_dict: dictionary mapping metabolites to relevant gene pairs.

  • gene_pairs_ind, gene_pairs_ind_per_ct_pair: index-referenced gene pair representations.

  • D: spatial node degree for each cell per cell type pair.

  • cells, genes: ordered list of cells and genes used in analysis.

  • (optional) ct_ccc_results["np"]["analytic_null"]: permutation null outputs.