Skip to content

scdef.tl.compute_within_group_pairwise_dissimilarity

compute_within_group_pairwise_dissimilarity(model: scDEF, layer: Union[int, str], obs_key: str, metric: Literal['jsd', 'euclidean', 'cosine'] = 'jsd', eps: float = 1e-12) -> DataFrame

Compute within-group pairwise cell dissimilarity for one layer.

Cells are represented by normalized factor memberships from model.adata.obsm[f"X_{layer_name}"]. Pairwise distances are computed within each category of obs_key and summarized per group.

Results are cached in model.adata.uns['within_group_pairwise_dissimilarity'].

Parameters:

Name Type Description Default
model scDEF

fitted scDEF model, with annotate_adata (or fit) already run so that adata.obsm['X_<layer>'] exists.

required
layer Union[int, str]

layer whose factor memberships represent each cell, as an index or a name from model.layer_names.

required
obs_key str

column in model.adata.obs defining the groups; distances are computed only between cells sharing a value.

required
metric Literal['jsd', 'euclidean', 'cosine']

distance between two cells' membership vectors — "jsd" (Jensen-Shannon, the default, appropriate for the normalized memberships), "euclidean", or "cosine".

'jsd'
eps float

floor applied when normalizing memberships, so that a cell with no assigned factor does not divide by zero.

1e-12

Returns:

Type Description
DataFrame

One row per group, summarizing the within-group pairwise distances. Groups

DataFrame

with fewer than two cells yield empty distance sets.