harreman.hotspot.compute_local_correlation

harreman.hotspot.compute_local_correlation#

harreman.hotspot.compute_local_correlation(adata, genes=None, permutation_test=False, M=1000, seed=42, check_analytic_null=False, device=device(type='cpu'), verbose=False)[source]#

Computes pairwise local correlation between selected genes using a spatial weight matrix.

Parameters:
  • adata (AnnData) – Annotated data object (AnnData). Required keys in adata.uns: - ‘gene_autocorrelation_results’ (if genes is None) - ‘layer_key’: layer in adata to extract counts from - ‘model’: statistical model to use for centering (e.g., ‘DANB’, ‘normal’) - ‘umi_counts’: per-cell UMI counts - optionally ‘sample_key’: key in adata.obs to use for per-sample normalization

  • genes (list, optional) – List of genes to include in the correlation analysis. If None, selects genes with FDR < 0.05 from adata.uns[‘gene_autocorrelation_results’], ordered by Z-score.

  • permutation_test (bool, optional (default: False)) – Whether to compute an empirical p-value and null distribution by permuting the data.

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

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

  • check_analytic_null (bool, optional (default: False)) – Whether to compute an analytic null distribution for the local correlation scores.

  • 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 keys in adata.uns: lcs, lc_zs, lc_z_pvals, and lc_z_FDR.

Return type:

None