squidpy.experimental.tl.assign_stitch_groups

squidpy.experimental.tl.assign_stitch_groups(sdata, labels_key, qc_table_key=None, min_confidence=0.7, max_gap=3.0, max_group_size=4, stitch_params=None, inplace=True)[source]

Assign tile-cut cell pieces to stitch groups.

Reads is_outlier=True cells flagged by calculate_tiling_qc(), pairs facing cut edges across tile boundaries, scores each pair via a transparent geometric composite, and assembles high-confidence pairs into stitch groups via union-find. This only annotates which pieces belong together – it does not modify the labels element. Materialising a stitched labels element is opt-in via make_stitched_labels().

The score per pair is the flat (unweighted) mean of five geometric features in [0, 1]: iou (1-D extent overlap), endpoint_match (chord endpoints coincide), merge_compactness (4*pi*A / P^2 of the closed union mask), merge_solidity (union area / convex hull area), and gap_proximity (seam gap relative to the morphological closing reach). No coefficients are fitted or shipped; the features are recorded in .uns["tiling_stitch"].

Parameters:
  • sdata (SpatialData) – SpatialData with a labels element and a QC table from calculate_tiling_qc().

  • labels_key (str) – Key in sdata.labels.

  • qc_table_key (str | None) – Key of the QC table. Defaults to "{labels_key}_qc".

  • min_confidence (float) – Threshold on stitch_confidence. 0.7 (default) is a starting point; raise it for stricter precision, lower for recall. Tune for your data – the score is heuristic, not a calibrated probability.

  • max_gap (float) – Maximum perpendicular distance (px) between facing cut edges for a pair to be considered a candidate. This is a search radius only; it does not scale the score.

  • max_group_size (int) – Cap on group size; oversized groups (likely false merges) collapse to singletons.

  • stitch_params (StitchParams | Mapping[str, Any] | None) – Advanced tuning knobs as a StitchParams instance or a Mapping of its field names to values. See StitchParams for each field’s meaning and default. None (default) uses all defaults.

  • inplace (bool) – If True, write back into sdata.tables[qc_table_key]. Otherwise return the modified AnnData.

Return type:

AnnData | None

Returns:

The QC AnnData with four new .obs columns when inplace=False, otherwise None.