Why Combine Neighborhoods Rather Than Measurements?
A cell can resemble one set of cells in its RNA profile and a different set in its protein measurements. This is not necessarily a contradiction: the modalities record different molecular features, and their usefulness can vary across cells. Weighted nearest neighbors (WNN) combines the evidence from modality-specific neighborhoods to build a joint neighborhood graph. The central operation is local weighting: each cell’s RNA and protein similarities contribute according to modality weights for that cell.
WNN operates on representations of the modalities, such as low-dimensional RNA and protein embeddings, rather than requiring raw counts from different assays to be added together. The earlier material on scaling modalities and canonical correlation provides relevant context: representation and preprocessing affect distances, but WNN’s task is to combine neighborhood evidence after those representations have been chosen.
From Modality-Specific Neighborhoods to a Joint Graph
First, represent every paired cell in each modality. For example, RNA may be represented by selected principal components, while antibody-derived protein measurements may be represented by a normalized and reduced protein embedding. For each modality separately, calculate distances between cells and identify nearby cells. Convert distances or neighbor relations into affinities: a close cell can receive a larger affinity than a more distant cell. Affinity construction may use a distance kernel or a locally scaled distance, and the exact transformation depends on the implementation.
The modalities need not use the same coordinate system or have comparable raw distances. The key requirement is that each modality’s affinity values carry a meaningful within-modality interpretation. A similarity of 0.8 in RNA is not automatically equivalent to a raw distance of 0.8 in protein; the joint calculation uses affinities and weights, not unstandardized cross-modality distances.
In a WNN procedure, local modality weights are estimated from how informative each modality is for each cell. A common principle is to compare how well a cell’s observations in one modality can be predicted using neighbors identified in that modality versus neighbors identified through another modality. A modality that provides more useful local predictive information receives more weight for that cell. Implementations can differ in the prediction-error calculation, distance kernels, and transformations used to obtain normalized weights; those details should be reported when results need to be reproduced.
Here \(S_{ij}\) is the combined score of cell \(j\) as a neighbor of cell \(i\), \(M\) is the number of modalities, \(w_i^{(m)}\) is cell \(i\)'s weight for modality \(m\), and \(A_{ij}^{(m)}\) is the affinity between \(i\) and \(j\) in that modality. A high score means that the combined, locally weighted evidence supports the pair as neighbors. The WNN neighborhood for \(i\) is formed by selecting cells with high joint scores, subject to the graph-construction rule used by the analysis.
This weighted-sum form has a simple justification. Imagine selecting one modality at random for evaluating the pair \((i,j)\), with probability \(w_i^{(m)}\) of selecting modality \(m\). The expected affinity under that selection is
Thus the combined score is the average affinity supported by the modalities, weighted by their local contributions. This does not claim that the cell’s biological state is literally generated by randomly choosing one assay; it explains the arithmetic of the aggregation.
Worked Calculations
Worked Example: Ranking Candidate Neighbors
Suppose a hypothetical paired RNA–protein data set has affinities for cell \(i\) and three candidates as shown below. The WNN procedure has supplied weights \(w_i^{(\mathrm{RNA})}=0.70\) and \(w_i^{(\mathrm{protein})}=0.30\). These weights sum to 1. The table gives affinities, not raw distances.
| Candidate cell \(j\) | RNA affinity | Protein affinity |
|---|---|---|
| A | 0.80 | 0.20 |
| B | 0.50 | 0.90 |
| C | 0.60 | 0.50 |
For A, \(S_{iA}=0.70(0.80)+0.30(0.20)=0.56+0.06=0.62\). For B, \(S_{iB}=0.70(0.50)+0.30(0.90)=0.35+0.27=0.62\). For C, \(S_{iC}=0.70(0.60)+0.30(0.50)=0.42+0.15=0.57\). A and B tie for the largest joint score, so both outrank C; a graph rule would determine how a tie is handled. RNA supports A more strongly, while protein supports B more strongly, and their weighted contributions balance exactly here.
Worked Example: A Protein-Supported Neighbor
Consider another hypothetical cell \(r\), with local weights \(w_r^{(\mathrm{RNA})}=0.40\) and \(w_r^{(\mathrm{protein})}=0.60\). Two candidate affinities are \(A_{rD}^{(\mathrm{RNA})}=0.90\), \(A_{rD}^{(\mathrm{protein})}=0.30\), \(A_{rE}^{(\mathrm{RNA})}=0.40\), and \(A_{rE}^{(\mathrm{protein})}=0.80\).
For D, \(S_{rD}=0.40(0.90)+0.60(0.30)=0.36+0.18=0.54\). For E, \(S_{rE}=0.40(0.40)+0.60(0.80)=0.16+0.48=0.64\). Thus E ranks above D in the joint neighborhood, even though D has the stronger RNA affinity. The protein contribution changes the ranking because it has greater weight for \(r\). This is a calculation about neighborhood construction, not a claim that protein is more useful for every cell.
Worked Example: How Weights Can Change a Ranking
For a third hypothetical cell, compare candidates F and G. Their RNA affinities are 0.80 and 0.50, respectively, while both have protein affinity 0.60. Let \(w_i^{(\mathrm{RNA})}=0.30\) and \(w_i^{(\mathrm{protein})}=0.70\). Then \(S_{iF}=0.30(0.80)+0.70(0.60)=0.24+0.42=0.66\), and \(S_{iG}=0.30(0.50)+0.70(0.60)=0.15+0.42=0.57\). F ranks higher.
Now keep the affinities fixed but use RNA weight 0.90 and protein weight 0.10. The scores become \(S_{iF}=0.90(0.80)+0.10(0.60)=0.72+0.06=0.78\) and \(S_{iG}=0.90(0.50)+0.10(0.60)=0.45+0.06=0.51\). F still ranks higher because it has the stronger RNA affinity and the protein affinities are tied. By contrast, if G’s protein affinity were 0.95, the first weighting would give \(S_{iG}=0.30(0.50)+0.70(0.95)=0.15+0.665=0.815\), above F’s 0.66; with the second weighting it would give \(0.90(0.50)+0.10(0.95)=0.545\), below F’s 0.78. The same modality-specific evidence can therefore yield different joint rankings when the weights change.
Assumptions, Diagnostics, and Alternatives
The construction is meaningful only if its inputs are suitable. Cells must be correctly paired across modalities, and the measurements used to build each representation must be sufficiently reliable for local distances to be informative. The neighborhood size and affinity transformation should not make nearly all cells equally similar or isolate most cells as unconnected. Local weights must be nonnegative and normalized if the stated weighted-average interpretation is used. Before interpreting a joint graph, check that modality-specific neighborhoods are not dominated by technical artifacts, and that the resulting graph is not determined solely by an unintended scale or preprocessing choice.
Useful checks include examining the distribution of modality-specific neighbor counts and affinities, checking whether the joint graph contains plausible connectivity, and comparing joint neighbor rankings with the separate modality rankings for selected cells. If a small preprocessing change radically rearranges the graph, or if many cells have nearly identical affinities to almost every candidate, the neighborhood structure may be unstable or uninformative. These checks identify warning signs; they do not by themselves prove that a graph is biologically valid.
WNN is one choice among several. Separate modality graphs preserve each assay’s neighborhood structure but do not provide one combined graph. Concatenating features or embeddings before calculating neighbors gives modalities influence through the concatenated representation and its scaling; it does not directly use cell-specific neighborhood weights. Canonical correlation can identify paired directions of shared variation, but it is a different operation from weighting modality-specific affinities to construct a graph. The choice depends on the analysis goal, the quality of each modality, and whether a single joint neighborhood is needed.
WNN’s main advantage is flexibility: different modalities can contribute differently from cell to cell, while retaining their own neighborhood calculations. Its limitations follow from the same design. A poor representation or unreliable modality can distort affinities; an unsuitable weight-estimation procedure can then amplify or suppress that distortion. The graph also depends on implementation choices such as neighborhood size, affinity kernel, and graph symmetrization. Report these choices and treat the joint graph as an analysis representation whose sensitivity should be checked, rather than as a uniquely determined account of cellular similarity.
Check Your Understanding
Answer each question, then compare with the solutions.
- For a cell with RNA weight 0.60 and protein weight 0.40, candidate J has affinities 0.50 and 0.90. What is its joint score?
- Why should raw RNA and protein distances not automatically be added together?
- If one candidate has a higher RNA affinity but another has a sufficiently higher protein affinity, can the second candidate rank higher? Explain.
- Name one diagnostic warning sign for a poorly informative modality-specific neighborhood.
- How does WNN differ from concatenating modality embeddings before neighbor search?
Solutions. (1) \(0.60(0.50)+0.40(0.90)=0.30+0.36=0.66\). (2) The representations can have different scales and meanings; WNN combines within-modality affinities with weights rather than assuming the raw distances are commensurate. (3) Yes. Its weighted protein contribution can outweigh the other candidate’s RNA advantage, so compare the full joint scores. (4) For example, nearly all cells may have almost identical affinities, leaving no informative local structure. (5) WNN combines modality-specific affinities using cell-specific weights; concatenation first creates a joint feature representation and finds neighbors in that representation.