COSIE.linkage_construction.compute_linkages
- compute_linkages(data_dict, linkage_indicator, num_hvg=3000)[source]
Construct pairwise linkage triplets across specified tissue sections and modalities using symmetric nearest neighbor matching.
This function supports both strong linkages (between sections sharing the same modality) and weak linkages (between biologically related but distinct modalities such as RNA-Protein). This function allows flexible linkage construction based on a user-defined linkage_indicator dictionary.
Parameters
- data_dictdict
A dictionary where each key is a modality (e.g., ‘RNA’, ‘Protein’) and each value is a list of AnnData objects (one per tissue section). Each AnnData must include:
.X: Feature or expression matrix
.obs, .var: Metadata
.obsm[‘spatial’]: Spatial coordinates
Use None if a modality is missing in a section.
- linkage_indicatordict
A dictionary specifying which tissue section pairs and modality pairs should be linked. Format: {(“s1”, “s2”): [(“RNA”, “RNA”), (“RNA”, “Protein”)],(“s2”, “s3”): [(“ATAC”, “RNA”)]} means: constructing linkage between section s1 and s2 using both RNA-RNA strong linkage and RNA-Protein weak linkage; constructing linkage between section s2 and s3 using ATAC-RNA linkage.
- num_hvgint, optional
Number of highly variable features to retain during feature matching. Default is 3000.
Returns
- linkage_resultsdict
A dictionary mapping each section pair (e.g., ‘s1_s2’) to a NumPy array of triplets. Each triplet has the form:
(anchor_index, positive_index, negative_index),
Example format: {“s1_s2”: np.ndarray of shape (N1, 3), “s2_s3”: np.ndarray of shape (N2, 3)}