Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Vertex Degree and Connectivity in Cell Graphs

Graph-Based Clustering · Tutorial 240 of 700

Vertex Degree and Connectivity in Cell Graphs

Learn to calculate how many neighbors each cell has, how strongly it is connected to them, and whether cells belong to the same connected part of a graph.

Intermediate 10 min read

What You'll Learn

  • Distinguish a cell's degree from its weighted degree.
  • Calculate degrees and weighted degrees from an undirected cell graph.
  • Determine whether a sequence of cells forms a path and count its edges.
  • Identify connected components and decide whether a graph is connected.
  • Check how edge weights and graph construction choices affect structural summaries.

Why Degree and Connectivity Matter

A cell-neighborhood graph represents cells as vertices and selected cell-to-cell relationships as edges. Once the graph has been constructed, its structure can be described with basic quantities: how many neighbors each cell has, how much total edge weight is incident to it, and whether there is a chain of edges connecting two cells. These are structural descriptions of the graph, not direct measurements of cell identity or biological relatedness.

This tutorial considers an undirected, weighted graph without self-loops, as is commonly used after symmetrizing a cell-neighborhood graph. Each edge has a positive weight that records the strength of the relationship under the chosen weighting scheme. The same definitions of paths and connected components apply to an unweighted graph, which can be viewed as having weight 1 on every edge.

Definition: Write a cell graph as \(G=(V,E,w)\), where \(V\) is the set of vertices (cells), \(E\) is the set of undirected edges between distinct vertices, and \(w_{ij}=w_{ji}>0\) is the weight of the edge between cells \(i\) and \(j\) when that edge exists. The neighbors of \(i\) are the vertices joined to \(i\) by an edge. The degree \(d_i\) is the number of neighbors of \(i\). The weighted degree, also called strength, \(s_i\), is the sum of the weights of the edges incident to \(i\).
$$ d_i = \sum_{j\ne i} \mathbf{1}\{(i,j)\in E\}, \qquad s_i = \sum_{j\ne i} w_{ij}\mathbf{1}\{(i,j)\in E\}. $$

Here \(\mathbf{1}\{\cdot\}\) is 1 when the stated condition holds and 0 otherwise. Degree is a count, whereas weighted degree is a sum on the scale of the edge weights. If the graph is unweighted, then \(s_i=d_i\); in a weighted graph, the two quantities need not rank cells in the same order.

Degree and Weighted Degree in a Small Graph

Suppose five hypothetical cells, A through E, form an undirected graph with edges A–B, A–C, B–C, C–D, and D–E. Assign the respective edge weights 0.8, 0.4, 0.6, 0.9, and 0.5. The weights are hypothetical similarities, so a larger value means a stronger edge under this particular weighting scheme.

Worked Example: Counting Neighbors and Summing Weights

Find the degree and weighted degree of each cell in the graph described above.

Cell A. A is connected to B and C, so \(d_A=2\). Its incident edge weights are 0.8 and 0.4, giving \(s_A=0.8+0.4=1.2\).

Cell B. B is connected to A and C, so \(d_B=2\). Its weighted degree is \(s_B=0.8+0.6=1.4\).

Cell C. C is connected to A, B, and D, so \(d_C=3\). Its weighted degree is \(s_C=0.4+0.6+0.9=1.9\).

Cell D. D is connected to C and E, so \(d_D=2\). Its weighted degree is \(s_D=0.9+0.5=1.4\).

Cell E. E has one neighbor, D, so \(d_E=1\), and \(s_E=0.5\).

C has the largest degree and weighted degree in this graph. The comparison also shows why both summaries can be useful: degree records the number of links, while weighted degree additionally reflects their assigned strengths. Neither quantity alone identifies what biological process produced the graph.

Paths and Connected Components

Definition: A path from vertex \(u\) to vertex \(v\) is a sequence of vertices beginning at \(u\) and ending at \(v\), with an edge between every consecutive pair. Its length is the number of edges in the sequence. A graph is connected if a path exists between every pair of vertices. A connected component is a maximal set of vertices in which every pair is joined by a path; maximal means that no additional vertex can be included while preserving this property.

For the five-cell example, A–B–C–D–E is a path from A to E of length 4. There are other paths between some pairs: A–C–D has length 2 from A to D, while A–B–C–D also connects them and has length 3. Since every vertex in this example is reachable from every other vertex, its one connected component is \(\{A,B,C,D,E\}\). Notice that a path depends on which edges are present, not on whether their weights are large or small. With positive weights, changing a weight without removing an edge does not change the graph's connected components.

Worked Example: Finding Paths and Components

Consider eight hypothetical cells with edges A–B, B–C, C–D, E–F, and F–G. Cell H has no incident edge. Identify the components and determine whether a path connects A to D or A to F.

The sequence A–B–C–D uses the edges A–B, B–C, and C–D, so it is a path from A to D of length 3. There is no path from A to F: the vertices A through D have no edge to E, F, or G.

The first component is \(\{A,B,C,D\}\), since every pair in that set can be connected by following the chain of edges, and no edge connects the set to another vertex. The second component is \(\{E,F,G\}\). H forms a component by itself, \(\{H\}\): a vertex with no incident edges has no path to any distinct vertex, but is still included as a one-vertex component. Thus the graph has three components and is not connected.

Useful Identities and a Justification

Degree totals and weighted-degree totals provide simple consistency checks when summarizing a graph. Let \(m\) be the number of edges and let \(W\) be the sum of the weights over all edges, counting each undirected edge once.

Result: In an undirected graph without self-loops, the sum of all vertex degrees is twice the number of edges. The sum of all weighted degrees is twice the total edge weight.
$$ \sum_{i\in V}d_i=2m, \qquad \sum_{i\in V}s_i=2W. $$

To see why the first identity holds, count incidences of vertices with edges. Each edge has exactly two endpoints, so contributes 1 to the degree of each endpoint and contributes 2 to the total degree. Counting all edges therefore gives \(\sum_{i\in V} d_i=2m\). For the weighted identity, each edge of weight \(w_{ij}\) contributes \(w_{ij}\) to the weighted degree of each of its two endpoints. Its total contribution across vertices is \(2w_{ij}\); summing over edges gives \(\sum_{i\in V}s_i=2\sum_{(i,j)\in E}w_{ij}=2W\). These arguments rely on undirected edges with no self-loops; conventions for self-loops or directed edges would change the accounting.

Worked Example: Checking Degree Totals

Use the five-cell graph with edges A–B, A–C, B–C, C–D, and D–E, weighted 0.8, 0.4, 0.6, 0.9, and 0.5 respectively. Check both identities using the values calculated earlier.

There are \(m=5\) edges. The degrees are 2, 2, 3, 2, and 1, so their sum is \(2+2+3+2+1=10\). The identity gives \(2m=2(5)=10\), which matches.

The total edge weight is \(W=0.8+0.4+0.6+0.9+0.5=3.2\). The weighted degrees sum to \(1.2+1.4+1.9+1.4+0.5=6.4\). The identity gives \(2W=2(3.2)=6.4\), again matching. A mismatch would suggest an arithmetic error, a duplicated or omitted edge, or inconsistent counting of undirected edges.

Choosing and Interpreting Structural Summaries

Degree and weighted degree answer different questions. Degree asks how many neighbors a cell has. Weighted degree asks for the total weight of those connections. For example, a cell with two edges of weight 0.9 has degree 2 and weighted degree 1.8; a cell with four edges of weight 0.2 has degree 4 and weighted degree 0.8. The first has fewer neighbors but greater summed edge weight. The interpretation of a weighted-degree value depends on how edge weights were defined and scaled.

Paths and components answer a different, more global question: which cells can be reached from which others by following edges? An undirected graph can have many components even when every cell has a positive degree, and a component can consist of one isolated vertex. Conversely, a graph can be connected despite having vertices with low degree. Degree alone therefore cannot establish connectivity.

In a directed k-nearest-neighbor graph, one could count outgoing and incoming edges separately. After symmetrization, the undirected degree defined here counts each neighboring cell once. For an undirected graph, storing both directions of an edge in a data structure must not cause that edge to be counted twice. Also, a zero-weight pair is not an edge under the convention used here; if an implementation retains zero-weight entries, distinguish the stored entries from the positive-weight edges when determining components.

Common Mistakes, Diagnostics, and Limits

  • Confusing degree with weighted degree. A high weighted degree does not necessarily mean many neighbors. Count distinct adjacent vertices for degree; sum incident weights for weighted degree.
  • Using weights as path lengths without defining that choice. In this tutorial, a path is defined by the presence of edges. A positive similarity weight does not shorten or lengthen the path, and does not affect component membership.
  • Leaving out isolated vertices. The vertex set comes from all cells in the graph, not just cells appearing in the edge list. A cell with no incident edges has degree and weighted degree zero and forms a one-vertex component.
  • Double-counting undirected edges. An edge between A and B contributes once to \(d_A\) and once to \(d_B\), but is only one edge when counting \(m\).

Before interpreting summaries, check that the graph is using the intended vertex set, that undirected edges are handled consistently, and that weights are nonnegative and interpreted on their stated scale. The degree-sum identities offer a quick arithmetic check, while a component calculation can be cross-checked by verifying that no edge joins two supposedly separate components. These checks can expose bookkeeping problems, but they do not establish that the chosen graph construction is biologically appropriate. Degree and connectivity depend on which edges were retained and how edge weights were assigned; they are descriptions of that graph, not causal or biological conclusions on their own.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A vertex has edges to three distinct neighbors with weights 0.2, 0.5, and 0.7. What are its degree and weighted degree?
  2. Can two vertices be in the same connected component if the only path between them uses a low-weight edge? Explain under the definitions in this tutorial.
  3. An undirected graph has 7 edges. What must the sum of its vertex degrees be?
  4. A graph has vertices P, Q, R, and S, with edges P–Q and R–S. List its components and state whether it is connected.
  5. Why can a cell with a greater weighted degree have fewer neighbors than another cell?

Solutions. (1) Its degree is 3, and its weighted degree is \(0.2+0.5+0.7=1.4\). (2) Yes. A path is determined by edges, and a low but positive weight does not remove an edge under these definitions. (3) The sum is \(2m=2(7)=14\). (4) The components are \(\{P,Q\}\) and \(\{R,S\}\); there is no path between the sets, so the graph is not connected. (5) Weighted degree sums the strengths of incident edges, whereas degree counts neighbors. A few strong edges can have a larger total weight than many weak edges.

Clinical Biostats