harreman.tools.compute_ct_cell_communication

harreman.tools.compute_ct_cell_communication#

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=device(type='cpu'), verbose=False)[source]#

Computes cell type-aware cell-cell communication (CCC) scores by stratifying communication by interacting cell type pairs. 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 (str or "use_raw", optional) – Data layer to use for parametric test.

  • layer_key_np_test (str or "use_raw", optional) – Data layer to use for non-parametric test.

  • model (str, optional) – Normalization model to use for centering gene expression. Options include “none”, “normal”, “bernoulli”, or “danb”.

  • cell_type_key (str, optional) – Key in adata.obs corresponding to cell type annotations. Required if not stored in uns.

  • center_counts_for_np_test (bool, optional (default: False)) – Whether to center expression counts using the specified model before non-parametric testing.

  • subset_gene_pairs (list, optional) – Subset of gene pairs to consider. If None, uses all pairs.

  • subset_metabolites (list, optional) – Subset of metabolites to include in the analysis.

  • fix_gp (bool, optional (default: False)) – If True, keeps gene pair identity fixed during permutation testing, randomizing cell types only.

  • M (int, optional (default: 1000)) – Number of permutations to use if permutation_test is True.

  • seed (int, optional (default: 42)) – Random seed for permutation reproducibility.

  • test ({'parametric', 'non-parametric', 'both'}, optional (default: 'both')) – Specifies which statistical test(s) to run.

  • mean ({'algebraic', 'geometric'}, optional (default: 'algebraic')) – Averaging method for multi-gene modules.

  • check_analytic_null (bool, optional (default: False)) – Whether to compute Z-scores and p-values under the null distribution for the permutation test.

  • device (torch.device, optional) – PyTorch device to run computations on. Defaults to CUDA if available.

  • verbose (bool, optional (default: False)) – Whether to print progress and status messages.

Returns:

Results are stored in the following adata.uns fields:
  • ct_ccc_results[“p”]: parametric test results (scores, Z, p-values, FDRs) per gene pair and metabolite per cell type pair.

  • ct_ccc_results[“np”]: non-parametric test results (communication scores, empirical p-values, 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”]: null distributions from permutation test Z-scores and p-values.

Return type:

None