spamosaic.build_graph.build_mnn_graph

spamosaic.build_graph.build_mnn_graph(bridge_ads, test_ads, use_rep, batch_key, knn_base=10, auto_knn=False, auto_thr=0.8, rmv_outlier=False, contamination='auto', seed=1234)[source]

Build a mutual nearest neighbor (MNN) graph across batches in one modality.

This procedure matches cells across batches using approximate kNN (Annoy) on a given embedding, returning a set of matched barcode pairs. It supports (1) bridge–bridge matches (between multi-modal batches) and (2) bridge–test matches (between a bridge batch and a single-modality batch). Optionally, it can remove spatial outliers.

Parameters:
  • bridge_ads (list of AnnData) – AnnData objects from bridge batches.

  • test_ads (list of AnnData) – AnnData objects from test batches.

  • use_rep (str) – Key in .obsm containing the embedding to search.

  • batch_key (str) – Column in .obs used only for logging/batch names.

  • knn_base (int, optional) – Base number of neighbors per side. Default is 10.

  • auto_knn (bool, optional) – If True, use determine_kSize to adapt k based on batch sizes.

  • auto_thr (float, optional) – Size ratio threshold for auto_knn. Default is 0.8.

  • rmv_outlier (bool, optional) – Whether to run remove_outlier. Default is False.

  • contamination ({'auto', float}, optional) – Outlier rate used by Isolation Forest.

  • seed (int, optional) – Random seed for stochastic components.

Returns:

Set of matched barcode pairs across batches.

Return type:

set of tuple of str