metachat.pp.compute_costDistance

metachat.pp.compute_costDistance(adata, LRC_type=None, LRC_strength=None, LRC_source='marker', dis_thr=50.0, k_neighb=5, barrier=False, barrier_segments=None, spatial_3d=False, use_parallel=True, n_jobs=-1, copy=False)[source]

Compute LRC-embedding cost distance based on visibility and local connectivity, supporting both 2D and 3D spatial coordinates.

Parameters

adata

AnnData object containing spatial coordinates and LRC annotations.

LRC_type

List of long-range communication (LRC) types to process, e.g. [“CSF”, “Blood”].

LRC_strength

List of reweighting strengths corresponding to each LRC type (same length as LRC_type).

LRC_source

Labeling source in adata.obs, either “marker” (default) or “manual”.

dis_thr

Distance threshold for defining neighborhood around each LRC (default: 50.0).

k_neighb

Number of nearest neighbors for within-cluster graph construction (default: 5).

barrier

Whether to include visibility barriers (default: False).

barrier_segments

List of ((x1, y1), (x2, y2)) tuples describing physical barriers.

spatial_3d

Use 3D spatial coordinates (adata.obsm[“spatial_3d”]) instead of 2D (default: False).

use_parallel

Whether to parallelize shortest-path computation (default: True).

n_jobs

Number of parallel jobs; -1 uses all CPUs (default: -1).

copy

Return a copy instead of modifying in place (default: False).

Returns

anndata.AnnData or None

If copy=True, returns a new AnnData with updated distances. Stores: - adata.obsp['spatial_distance_LRC_base'] - adata.obsp['spatial_distance_LRC_<type>']