Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Cell-Cell Neighborhood Graphs

Graph-Based Clustering · Tutorial 232 of 700

Cell-Cell Neighborhood Graphs

Learn how vertices, edges, and positive affinity weights represent local relationships among cells without treating graph links as cell-type labels.

Intermediate 11 min read

What You'll Learn

  • Define a cell-cell graph and identify what its vertices and edges represent.
  • Distinguish edge presence from an edge’s weight using adjacency matrices.
  • Interpret positive affinity weights without treating them as probabilities or cell-type labels.
  • Work through examples of graph representations and cross-type edges.
  • Recognize how representation choices and technical effects can affect a graph.
  • Compare weighted graphs with binary graphs, edge lists, and embeddings.

Why Represent Cells as a Graph?

A single-cell data set can be represented by a point for each cell in a chosen feature space. A graph provides a different kind of description: it records which pairs of cells are treated as locally related, and optionally how strong each recorded relationship is. This can preserve a useful neighborhood structure without requiring every pairwise distance or every coordinate to be examined directly.

The graph’s links describe a relation defined by the graph-building rule and the chosen representation. They are not, by themselves, declarations of biological identity. In particular, an edge does not guarantee that two cells have the same cell type, share a condition, or have a direct biological interaction. Those claims require evidence and definitions beyond graph structure.

The earlier material on embeddings established that an embedding is a representation of cells whose geometry can be inspected, while its visible geometry has limitations. A cell-cell graph is another representation of relationships. Its meaning depends on how vertices are defined, which pairs receive edges, and what the edge weights mean.

Vertices, Edges, and Weights

Definition: A cell-cell graph is a graph \(G=(V,E)\). Its vertex set \(V\) contains one vertex for each cell being represented. Its edge set \(E\) contains selected pairs of vertices, with an edge indicating that the pair satisfies a specified relationship rule. In a weighted graph, each included edge also has a weight that quantifies that relationship according to a stated convention.

In this tutorial, the primary convention is a simple, undirected cell graph with no self-loops: an edge joins two distinct cells, and the edge from cell \(i\) to cell \(j\) is the same as the edge from \(j\) to cell \(i\). Thus the graph represents a symmetric relationship. Directed graphs are possible when the relationship is asymmetric, but direction must then be retained rather than silently interpreted as mutual connection.

An edge records which pairs are included. A weight records an additional property of an included pair. For example, an affinity weight may be larger for a pair considered more similar under the chosen representation and rule. The numerical scale is a modeling convention: weights need not be probabilities, and a weight of 0.8 does not automatically mean an 80% chance that two cells share a type.

For a nonnegative affinity representation, require every included edge to have a strictly positive weight. This convention makes an absent edge distinguishable from a present edge using the weighted adjacency matrix alone. If an application allows a present edge to have weight zero, the weight matrix cannot mark presence unambiguously; an additional binary adjacency matrix is then needed.

Definition: For an undirected graph, the binary adjacency matrix \(A\) has entries \(A_{ij}=1\) if cells \(i\) and \(j\) are joined by an edge, and \(A_{ij}=0\) otherwise. For a positive weighted graph, the weighted adjacency matrix \(W\) has \(W_{ij}=w_{ij}>0\) for an included edge and \(W_{ij}=0\) for an absent edge. With no self-loops, \(A_{ii}=W_{ii}=0\). In the undirected case both matrices are symmetric.

The zero on the diagonal follows from the no-self-loop convention, not from a claim that a cell is biologically unrelated to itself. For present edges, an affinity weight summarizes the specified pairwise relationship; it does not reveal every cause of that relationship. A graph is therefore a deliberately selective representation, not a complete account of all possible cell-to-cell relations.

Worked Example: Reading a Small Cell Graph

Worked Example: Reading a Small Cell Graph

Suppose a hypothetical analysis represents four cells, \(A\), \(B\), \(C\), and \(D\). Its undirected graph includes edges \(A\)--\(B\), \(B\)--\(C\), and \(C\)--\(D\). The positive affinity weights are 0.90, 0.60, and 0.80, respectively. No other pairs are included.

The vertices are the four cells. The edge set is \(E=\{\{A,B\},\{B,C\},\{C,D\}\}\). Because this is an undirected graph, each pair is written once in the edge set; the relation is symmetric.

In the cell order \(A,B,C,D\), the weighted adjacency matrix is

$$ W= \begin{pmatrix} 0 & 0.90 & 0 & 0\\ 0.90 & 0 & 0.60 & 0\\ 0 & 0.60 & 0 & 0.80\\ 0 & 0 & 0.80 & 0 \end{pmatrix}. $$

For example, \(W_{AB}=W_{BA}=0.90\) because the edge is present with that weight. In contrast, \(W_{AD}=W_{DA}=0\) because that pair has no edge under this graph definition. The zeros do not assert that \(A\) and \(D\) have no biological similarity; they say only that this graph does not include their pair.

Under the stated affinity convention, the graph assigns the largest weight to \(A\)--\(B\), followed by \(C\)--\(D\), then \(B\)--\(C\). This ordering is interpretable only if the weights use a common scale and the stated convention that larger means stronger affinity. It does not establish that the cells have the same annotation or that one caused a change in another.

How the Matrix Encodes Edge Presence

For an undirected graph, the edge set contains unordered pairs. The adjacency matrix stores those same decisions in a square array indexed by cells. The matrix is symmetric because an included pair \(\{i,j\}\) contributes both entries \(A_{ij}\) and \(A_{ji}\), or both \(W_{ij}\) and \(W_{ji}\).

The positive-weight convention gives a direct way to recover edge presence from \(W\). For distinct cells \(i\) and \(j\), an edge is present exactly when \(W_{ij}>0\). If no edge is present, \(W_{ij}=0\). Therefore the binary matrix can be recovered by the indicator rule below.

$$ A_{ij}= \begin{cases} 1, & W_{ij}>0,\\ 0, & W_{ij}=0. \end{cases} \qquad (i\ne j) $$

This rule depends on the assumption that every included edge has a positive weight. If zero is permitted as a weight on a present edge, then \(W_{ij}=0\) has two possible meanings: absent edge or present edge with zero weight. In that setting, the weighted matrix alone is insufficient. Store edge presence separately in \(A\), with the weight recorded as a separate attribute.

Worked Example: Recovering Presence from Positive Weights

Consider three hypothetical cells \(P,Q,R\) with a positive affinity edge \(P\)--\(Q\) of weight 0.35 and an edge \(Q\)--\(R\) of weight 0.72. There is no edge between \(P\) and \(R\). In the order \(P,Q,R\), the weighted matrix is

$$ W= \begin{pmatrix} 0 & 0.35 & 0\\ 0.35 & 0 & 0.72\\ 0 & 0.72 & 0 \end{pmatrix}. $$

Since included edge weights are strictly positive, \(W_{PQ}=0.35>0\) and \(W_{QR}=0.72>0\) each identify a present edge. Since \(W_{PR}=0\), the pair \(P,R\) is absent. Applying the indicator rule gives

$$ A= \begin{pmatrix} 0 & 1 & 0\\ 1 & 0 & 1\\ 0 & 1 & 0 \end{pmatrix}. $$

The weight matrix and binary matrix answer different questions: \(W\) includes both presence and affinity magnitude under the convention, while \(A\) records presence alone. If a present edge had weight zero, this recovery would fail for that pair, so a separate \(A\) would be necessary.

An Edge Is Not a Cell-Type Label

Cell type is an annotation of a cell, whereas an edge is a relation between two vertices. A local similarity rule may link cells with different labels, particularly when cell states vary continuously, labels are coarse, or the chosen representation makes two annotated groups close. Conversely, cells assigned the same label need not all be connected in a graph.

This distinction is logical as well as practical. The graph definition says what qualifies as an edge; it does not include a claim about annotations unless the construction explicitly uses labels. Thus an edge between distinct annotated types is not a contradiction of the graph definition. It is evidence that the pair met the specified graph rule, not proof that the labels are wrong or that the cells are biologically identical.

Worked Example: A Cross-Type Edge

Suppose four hypothetical cells have existing annotations \(U_1,U_2\) of type X and \(V_1,V_2\) of type Y. A graph contains edges \(U_1\)--\(U_2\) with weight 0.70, \(U_2\)--\(V_1\) with weight 0.55, and \(V_1\)--\(V_2\) with weight 0.85. All weights are positive affinities under the same convention.

There are two within-type edges and one cross-type edge. In particular, \(U_2\)--\(V_1\) is an included edge even though its endpoints have different annotations. The valid interpretation is that this pair met the graph’s inclusion rule and has affinity weight 0.55 on the stated scale.

It would be incorrect to conclude that the edge proves \(U_2\) and \(V_1\) are the same type. It would also be incorrect to conclude from the edge alone that the annotations are erroneous. The graph represents a local relationship; interpreting why the cross-type pair is linked requires additional biological and technical context.

Justification: What Does a Positive Weight Add?

In a binary graph, an included pair has the same recorded status as every other included pair: \(A_{ij}=1\). A weighted graph refines that description by assigning an affinity value \(w_{ij}\) to each included pair. If all positive weights share a meaningful scale, pairs can be ordered by the stated convention. For the first example, \(0.90>0.80>0.60\), so the recorded affinity ordering is \(A\)--\(B\), then \(C\)--\(D\), then \(B\)--\(C\).

The conclusion follows from the numeric comparison and the model convention, not from a universal property of graphs. If weights were defined as distances rather than affinities, the interpretation would reverse: a smaller value would mean a closer pair, and zero could be a valid value for an included edge. In that case, retain edge presence separately rather than using a zero in the weight matrix to mean absence. Never interpret the ordering of weights until the weight definition and scale are stated.

Diagnostics, Alternatives, and Limitations

A graph can be represented as an edge list, a binary adjacency matrix, a weighted adjacency matrix, or a visual diagram. An edge list is often compact when relatively few pairs are included; a matrix makes pairwise presence easy to inspect for a small graph. A diagram can make local structure visible, but the drawing layout may introduce visual impressions that are not properties of the graph. These are alternative representations of the same graph, not different biological findings.

A binary graph is appropriate when the intended information is only whether a pair is included. A weighted graph retains an additional strength or distance value, but only if that quantity is clearly defined. A point embedding instead represents cells with coordinates; it can show geometric structure, while a graph explicitly selects relationships among pairs. Neither representation alone proves cell identity, lineage, interaction, or causality.

Useful checks focus on whether the graph matches its stated definition and whether its interpretation is defensible:

  • Confirm that each vertex corresponds to the intended observational unit, usually one cell, and that cell identifiers are not duplicated or mismatched.
  • Check that an undirected graph has symmetric adjacency or weight entries and that the diagonal matches the stated self-loop convention.
  • Verify how absence is encoded. If zero means no edge, ensure included affinity weights are strictly positive; otherwise keep edge presence separately.
  • Inspect the weight definition and range before comparing magnitudes. A value is not a probability unless the method explicitly defines and calibrates it as one.
  • Check whether the local relationships change substantially under reasonable choices of representation or edge rule. Strong dependence can make downstream conclusions fragile.
  • Consider whether batch, quality, or other technical structure may influence the representation and therefore the selected relationships. A graph records the input structure it receives; it does not automatically remove technical effects.

A graph is selective by design. A missing edge does not establish that two cells are biologically unrelated, and an included edge does not establish shared type. In a large graph, a picture may conceal many pairs, and an apparently prominent edge can depend on the weight scale. Local graphs can also omit longer-range relationships that matter for a different scientific question. Graph structure should therefore be reported together with the representation, edge-selection rule, direction convention, and weight meaning.

Common Mistake

Common mistake: “These two cells are connected, so they must be the same cell type.” An edge indicates only that the pair satisfies the graph’s stated relationship rule. A correction is to treat annotations and graph edges as distinct information: report the edge and its weight as local graph structure, then evaluate cell type using appropriate evidence. A second related mistake is interpreting every zero in a weight matrix as biological dissimilarity. Under the positive-affinity convention, zero marks an absent edge; it is not a measured similarity of zero.

A graph is most useful when its interpretation stays close to its definition. State what the vertices represent, what qualifies as an edge, whether the graph is directed, and how weights are scaled. This prevents a concise structural representation from being mistaken for a complete biological conclusion.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. In a cell-cell graph, what do a vertex and an edge represent? Does an edge necessarily imply shared cell type?
  2. An undirected positive-affinity graph has \(W_{ij}=0.42\) and \(W_{ji}=0.42\). What can be concluded about the pair under the convention used here?
  3. Why is a separate binary adjacency matrix needed if a present edge is allowed to have weight zero?
  4. A cell graph has a weight of 0.7 for one edge. Is it correct to say there is a 70% probability that the cells have the same type? Explain.

Solutions. 1. A vertex represents one cell; an edge represents a selected relationship between a pair under the graph’s rule. It does not necessarily imply shared cell type. 2. The pair is included, and its recorded affinity weight is 0.42; the undirected entries agree. 3. A zero in the weight matrix would then represent either an absent edge or a present zero-weight edge, so weight alone cannot identify presence. 4. No. Unless the weight is explicitly defined and calibrated as that probability, 0.7 is an affinity value under the graph’s stated convention, not a probability of matching cell type.

Clinical Biostats