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 within a single modality.
This function constructs a set of matched cell pairs across batches (MNNs), including both bridge-to-bridge and bridge-to-single relationships, based on specified embeddings. Optionally supports automatic KNN sizing and outlier removal.
- Parameters:
bridge_ads (list of AnnData) – List of AnnData objects from bridge batches (i.e., batches with multiple modalities).
test_ads (list of AnnData) – List of AnnData objects from test batches (i.e., batches with a single modality).
use_rep (str) – Key in .obsm indicating the representation to use for MNN search.
batch_key (str) – Column in .obs used to identify the batch name (for logging purposes).
knn_base (int, default=10) – Base number of neighbors for KNN search.
auto_knn (bool, default=False) – Whether to automatically adjust KNN size based on batch sizes.
auto_thr (float, default=0.8) – Size ratio threshold for determining asymmetric KNNs in auto_knn mode.
rmv_outlier (bool, default=False) – Whether to apply spatial outlier removal using Isolation Forest.
contamination (str or float, default='auto') – Proportion of outliers when using Isolation Forest.
seed (int, default=1234) – Random seed used by the Isolation Forest or other stochastic operations.
- Returns:
A set of MNN cell barcode pairs across batches.
- Return type:
Set[Tuple[str, str]]