spamosaic.build_graph.remove_outlier
- spamosaic.build_graph.remove_outlier(mnn_set, ad1, ad2, contamination='auto')[source]
Remove outlier cell pairs from an MNN set based on spatial distance patterns.
This function uses an Isolation Forest model to detect and remove spatial outlier cell pairs from a set of mutual nearest neighbors (MNNs). It constructs a feature matrix based on spatial coordinates from both datasets and their differences, then filters out pairs classified as outliers.
- Parameters:
mnn_set (set of tuple[str, str]) – Set of MNN cell pairs represented by (cell_id_1, cell_id_2).
ad1 (AnnData) – First AnnData object containing ‘spatial’ in .obsm.
ad2 (AnnData) – Second AnnData object containing ‘spatial’ in .obsm.
contamination (str or float, default='auto') – The amount of contamination (i.e., expected proportion of outliers) used to define the threshold in the Isolation Forest. Follows scikit-learn’s format.
- Returns:
Filtered MNN set with spatial outliers removed.
- Return type:
set of tuple[str, str]