biology2u
Depth
Concept

Clustering gene expression

T-110Home BU-401Threads information · systems
Statement

Finding structure in transcriptomic data.

Why it matters

sequence-alignment and blast-database-search both work on sequence data, finding relationships by comparing strings of nucleotides or amino acids directly. Expression clustering works on a different kind of data entirely — a matrix of quantitative expression levels across many genes and many conditions, samples, or timepoints — where there is no sequence to align at all. It provides a way to generate hypotheses about which genes are functionally related, purely from how their expression rises and falls together, complementing rather than replacing sequence-based homology evidence.

Clustering results are hypotheses to be tested, not conclusions: two genes clustering together indicates correlated expression, which is consistent with (but does not itself prove) co-regulation or shared function, a distinction that matters throughout the Common errors below.

Hypotheses
Genes with similar expression profiles across many conditions are more likely to be co-regulated or functionally related ("guilt by association").This is the core working assumption motivating the whole approach: if two genes are consistently turned up and down together across many different conditions, a shared regulatory mechanism or shared pathway membership is a reasonable, testable hypothesis, though not a certainty. A chosen distance or similarity metric meaningfully captures biological similarity, once the data has been properly normalised.Raw read counts or intensities are affected by technical factors (sequencing depth, array scaling, batch) unrelated to biology; without normalising these out first, a distance metric risks measuring technical variation rather than the biological pattern of interest.
Proof
1
\[ \text{Represent each gene as a vector of expression values across } n \text{ conditions, samples, or timepoints.} \]
This converts the biological question ("which genes behave similarly?") into a geometric one (which vectors lie close together in \(n\)-dimensional space), making the standard machinery of distance and clustering directly applicable. A
2
\[ d(x,y) = \sqrt{\textstyle\sum_i (x_i-y_i)^2} \qquad \text{or} \qquad d(x,y) = 1-\rho(x,y) \]
Euclidean distance treats absolute magnitude of expression difference as the similarity measure; correlation distance instead measures similarity of shape (whether two genes rise and fall together across conditions) regardless of their absolute expression level, and is often preferred specifically because it is insensitive to overall scale differences between genes. A
3
\[ \text{Hierarchical clustering repeatedly merges the two closest clusters (by a chosen linkage rule) into one, building a dendrogram.} \]
Starting from every gene as its own singleton cluster, the algorithm merges the closest pair at each step, using a linkage rule (single, complete, or average distance between cluster members) to define cluster-to-cluster distance once clusters contain more than one gene; the resulting dendrogram encodes a full nested hierarchy of similarity without requiring the number of clusters to be fixed in advance. B
4
\[ \text{k-means clustering minimises } \textstyle\sum_{k}\sum_{x\in C_k}\|x-\mu_k\|^2 \text{ by iterating cluster assignment and centroid update.} \]
Given a chosen number of clusters \(k\), each gene is assigned to its nearest of \(k\) centroids, the centroids are then recomputed as the mean of their assigned genes, and the two steps repeat until assignments stabilise; unlike hierarchical clustering, \(k\) must be specified in advance rather than emerging from the data itself. B
5
\[ \text{Dimensionality reduction (e.g. PCA) is commonly applied before or alongside clustering to reduce noise and enable visualisation.} \]
Because expression datasets typically have far more genes than conditions (high dimensionality relative to sample size), projecting onto a small number of dominant axes of variation both reduces the influence of noisy, low-signal dimensions on the distance calculation of Step 2 and makes the resulting cluster structure visualisable in two or three dimensions. A
Result
\[ \text{Distance metric} + \text{clustering algorithm (hierarchical or } k\text{-means)} \Rightarrow \text{groups of co-expressed genes} \]

Reading. Choosing a distance metric that captures the relevant notion of biological similarity, then applying a clustering algorithm, converts a large expression matrix into a smaller number of groups of genes whose shared expression pattern is a candidate signal of shared regulation or function.

Scope. A hypothesis-generating, exploratory method; cluster membership must be validated by independent evidence (known pathway membership, sequence homology, direct experimental follow-up) before being treated as established biological fact.

Corollaries & converses
  • phylogenetic-tree-construction reuses essentially the same distance-plus-linkage machinery as Step 3 here, but applied to sequence divergence between species rather than expression distance between genes — a direct methodological parallel across two otherwise unrelated biological questions.
  • sequence-alignment and blast-database-search find relatedness by direct sequence comparison; expression clustering finds a complementary, expression-based notion of "functional neighbourhood" that need not correspond to sequence similarity at all (unrelated genes can be co-regulated; homologous genes can be expressed very differently).
  • Hierarchical clustering's dendrogram gives a full nested structure without committing to a single cluster count in advance, whereas k-means forces exactly \(k\) clusters regardless of the data's true structure — the two methods can, and often do, disagree on cluster boundaries for the same dataset.
Fails without
  • Skip normalisation for sequencing depth or batch effects (Hypotheses): two genes' expression vectors could appear more (or less) similar simply because their samples were sequenced to different depths or processed in different batches, so the resulting clusters could reflect a technical artefact of the experiment rather than a genuine biological co-expression pattern.
  • Choose k arbitrarily in k-means without justification (Step 4): the algorithm will always output exactly \(k\) clusters, whether or not that many genuine groups actually exist in the data, potentially fragmenting one true biological cluster into several, or merging two genuinely distinct ones into one, purely as an artefact of the chosen \(k\).
Common errors
  • Treating cluster co-membership as proof of shared function or direct co-regulation, rather than as a correlational hypothesis requiring independent validation (Result, Scope).
  • Using Euclidean distance on raw, unnormalised expression values, letting very highly expressed genes dominate the distance calculation by absolute magnitude rather than by the shape of their expression pattern across conditions.
  • Assuming hierarchical clustering produces "the" correct tree of gene relationships; different linkage rules (single, complete, average) can produce materially different dendrogram topologies from the identical underlying distance matrix.
  • Forgetting that k-means requires specifying the number of clusters in advance, while hierarchical clustering does not — and then comparing results from the two methods as though they were run under equivalent, method-independent conditions.
Discussion

Hierarchical clustering of gene expression data, together with a dendrogram-ordered heatmap visualisation, became a widely used standard analysis technique once genome-scale expression profiling (microarrays, and later RNA sequencing) made it possible to measure thousands of genes' expression simultaneously across many conditions in a single experiment.

Because the number of genes typically far exceeds the number of samples or conditions in a given expression dataset, clustering results can be sensitive to noise in individual, low-signal genes; combining dimensionality reduction (Step 5) with clustering, and requiring a candidate cluster to be reproducible across independent datasets, are both standard ways of guarding against over-interpreting a pattern that arose from noise alone.

Common misconception: that a gene's cluster assignment is a fixed, objective property of the gene itself. In fact, cluster membership depends on the specific set of conditions profiled, the chosen distance metric, and the clustering algorithm and parameters used; the same gene can plausibly fall into different clusters under a different, equally reasonable set of analysis choices.

Worked examples
1
\[ \text{Gene X: } (2,4,8) \text{ across three conditions; Gene Y: } (1,2,4) \text{; Gene Z: } (8,4,2) \]
Euclidean distance: \(d(X,Y)=\sqrt{1^2+2^2+4^2}=\sqrt{21}\approx4.58\); \(d(X,Z)=\sqrt{6^2+0^2+6^2}=\sqrt{72}\approx8.49\). By Euclidean distance alone, X and Y are closer than X and Z, even though X and Y both rise consistently across the three conditions while Z falls — X and Y share both shape and (roughly, up to a scale factor) magnitude. A
2
\[ \text{Correlation-distance check: } \rho(X,Y)=+1\ (\text{perfectly correlated, same shape}), \quad \rho(X,Z)=-1\ (\text{perfectly anti-correlated}) \]
Correlation distance \(1-\rho\) gives \(0\) for X,Y (identical shape up to scaling) and \(2\) for X,Z (opposite shape) — a sharper separation than the Euclidean distance of Step 1 alone provided, illustrating why correlation distance is often preferred when the pattern of change, not absolute magnitude, is the biologically relevant signal (Step 2 of the Proof). A
\[ \text{X and Y cluster together (correlated pattern); Z is the outlier (anti-correlated)} \]

Reading. Even a toy three-gene, three-condition example shows how the choice of distance metric can sharpen (or blur) a clustering decision; correlation distance specifically isolates genes moving together in pattern, independent of their absolute expression scale.

Scope. The same computation, scaled up to thousands of genes and many conditions, is exactly what a real hierarchical or k-means clustering pipeline performs, using the chosen metric as its fundamental unit of comparison.

Further example. A researcher analyzes the expression of two genes, Alpha and Beta, across three different tissue types (Liver, Kidney, Brain). The raw expression counts (normalized) are given as vectors: Alpha = (10, 20, 30) and Beta = (1, 2, 3). Calculate the Euclidean distance \(d(\text{Alpha}, \text{Beta})\) and the Pearson correlation coefficient \(\rho(\text{Alpha}, \text{Beta})\). Explain why the Euclidean distance suggests the genes are distinct while the correlation suggests they are identical in pattern.

1
\[ d(\text{Alpha}, \text{Beta}) = \sqrt{(10-1)^2 + (20-2)^2 + (30-3)^2} \]
Euclidean distance measures the straight-line magnitude of difference between two points in vector space. It is sensitive to both the direction and the magnitude of the difference. A
2
\[ d(\text{Alpha}, \text{Beta}) = \sqrt{9^2 + 18^2 + 27^2} = \sqrt{81 + 324 + 729} = \sqrt{1134} \approx 33.67 \]
The large numerical value reflects the significant difference in absolute expression levels (10-fold difference in scale). In a standard Euclidean clustering, these genes would be considered far apart. A
3
\[ \bar{A} = \frac{10+20+30}{3} = 20, \quad \bar{B} = \frac{1+2+3}{3} = 2 \]
To calculate Pearson correlation, we first center the data by subtracting the mean of each vector. This removes the "offset" or baseline expression level, isolating the shape of the profile. A
4
\[ A' = (10-20, 20-20, 30-20) = (-10, 0, 10) \] \[ B' = (1-2, 2-2, 3-2) = (-1, 0, 1) \]
The centered vectors show the deviation from the mean for each condition. Notice that \(A'\) is exactly 10 times \(B'\). A
5
\[ \rho = \frac{\sum A'_i B'_i}{\sqrt{\sum (A'_i)^2} \sqrt{\sum (B'_i)^2}} = \frac{(-10)(-1) + (0)(0) + (10)(1)}{\sqrt{100+0+100} \sqrt{1+0+1}} \] \[ \rho = \frac{10 + 0 + 10}{\sqrt{200} \sqrt{2}} = \frac{20}{\sqrt{400}} = \frac{20}{20} = 1 \]
The correlation coefficient is 1, indicating a perfect positive linear relationship. Because the vectors are scalar multiples of each other, their relative changes across conditions are identical. A
\[ d \approx 33.67, \quad \rho = 1 \]

Reading. Euclidean distance treats the genes as dissimilar because their absolute expression levels differ by an order of magnitude. Correlation distance treats them as identical because they rise and fall in perfect proportion. In transcriptomics, if the biological question is "do these genes respond to the same stimulus?" (pattern), correlation is the appropriate metric. If the question is "are these genes expressed at the same level?" (magnitude), Euclidean distance is appropriate.

Scope. This distinction holds for any linear scaling. If the relationship were non-linear (e.g., one gene saturates while the other does not), the correlation would be less than 1, and the choice of metric would depend on whether the non-linearity is biologically meaningful or an artifact of measurement range.

Problems
  1. Two genes have expression vectors \((1,1,1)\) and \((10,10,10)\) across three conditions. Compute their Euclidean distance and their correlation, and explain the apparent contradiction between the two results.
    SolutionEuclidean distance: \(d=\sqrt{9^2+9^2+9^2}=9\sqrt3\approx15.6\), a large value, suggesting dissimilarity. Correlation: both vectors are constant across conditions, so correlation is technically undefined (zero variance) in the strict sense, but the two genes have an identical, perfectly flat pattern (no relative change across conditions) despite very different absolute expression levels. This illustrates why Euclidean distance can flag genes as "dissimilar" purely due to overall expression magnitude, even when their relative pattern across conditions is identical (Common errors, second bullet).
  2. A researcher runs k-means with \(k=3\) and finds three well-separated clusters. She reruns with \(k=5\) on the identical data and again finds five apparently well-separated clusters. Explain how both results can be internally "valid" outputs of the algorithm.
    Solutionk-means always returns exactly the number of clusters specified as \(k\) (Step 4 of the Proof); it does not test whether that number is actually appropriate for the data's true underlying structure. Both runs are valid in the narrow sense that each converged to a local minimum of the within-cluster sum-of-squares objective for its specified \(k\), but this does not by itself establish which value of \(k\) (if either) reflects genuine biological structure; additional criteria (e.g. comparing against a hierarchical dendrogram, or biological validation) are needed to choose between them.
  3. Explain why finding that two genes cluster together in an expression experiment is not, by itself, sufficient evidence that the two genes are regulated by the same transcription factor.
    SolutionClustering identifies statistical co-expression (correlated expression pattern across the profiled conditions), which is the guilt-by-association hypothesis (Hypotheses) — a candidate for shared regulation, not a proof of it. Two genes could show correlated expression for reasons other than sharing a regulator: coincidental response to the same environmental change via entirely independent regulatory pathways, or an indirect causal chain in which one gene's product regulates the other. Confirming shared regulation requires additional evidence, such as demonstrating both genes bind the same transcription factor directly (e.g. eukaryotic-gene-regulation's promoter/enhancer evidence), beyond the clustering result alone.
  4. A gene expression matrix contains two genes, P and Q, measured under three conditions. The expression vectors are \(P = (2, 4, 6)\) and \(Q = (1, 2, 3)\). Calculate the Euclidean distance \(d(P,Q)\) and the Pearson correlation coefficient \(\rho(P,Q)\). Explain why these two metrics yield different conclusions about the similarity of P and Q.
    Solution Euclidean Distance: \[ d(P,Q) = \sqrt{(2-1)^2 + (4-2)^2 + (6-3)^2} \] \[ d(P,Q) = \sqrt{1^2 + 2^2 + 3^2} = \sqrt{1 + 4 + 9} = \sqrt{14} \approx 3.74 \] Pearson Correlation: First, calculate the means: \[ \bar{P} = \frac{2+4+6}{3} = 4, \quad \bar{Q} = \frac{1+2+3}{3} = 2 \] Calculate deviations: \[ P - \bar{P} = (-2, 0, 2) \] \[ Q - \bar{Q} = (-1, 0, 1) \] Calculate the numerator (sum of products of deviations): \[ \sum (P_i - \bar{P})(Q_i - \bar{Q}) = (-2)(-1) + (0)(0) + (2)(1) = 2 + 0 + 2 = 4 \] Calculate the denominators (sum of squared deviations): \[ \sum (P_i - \bar{P})^2 = (-2)^2 + 0^2 + 2^2 = 4 + 0 + 4 = 8 \] \[ \sum (Q_i - \bar{Q})^2 = (-1)^2 + 0^2 + 1^2 = 1 + 0 + 1 = 2 \] Calculate \(\rho\): \[ \rho(P,Q) = \frac{4}{\sqrt{8} \cdot \sqrt{2}} = \frac{4}{\sqrt{16}} = \frac{4}{4} = 1.0 \] Explanation: The Euclidean distance is \(\sqrt{14} \approx 3.74\), which is a non-zero value indicating a difference in magnitude. However, the correlation coefficient is \(1.0\), indicating a perfect linear relationship. This occurs because \(P\) is exactly twice \(Q\) (\(P = 2Q\)). Euclidean distance penalizes the difference in scale (magnitude), whereas correlation is invariant to linear scaling (shift and scale). In biological terms, if the question is "do these genes change in the same proportion?" the answer is yes (correlation). If the question is "are their absolute expression levels similar?" the answer is no (Euclidean distance).
  5. In a hierarchical clustering analysis using Ward's method, the following linkage distances (squared within-cluster sum of squares) are obtained for merging clusters of genes: 1. Merge Gene A and Gene B: Cost = 10 2. Merge Gene C and Gene D: Cost = 20 3. Merge Cluster (A,B) and Gene E: Cost = 50 4. Merge Cluster (C,D) and Gene F: Cost = 80 5. Merge Cluster (A,B,E) and Cluster (C,D,F): Cost = 200 If the researcher cuts the dendrogram to obtain exactly 3 clusters, what are the clusters, and what is the total within-cluster sum of squares (WCSS) for this partition?
    Solution To obtain \(k=3\) clusters from a hierarchical clustering tree, we must stop the merging process before the final step that reduces the number of clusters from 3 to 2. Let's trace the number of clusters: - Start: 6 genes (A, B, C, D, E, F) \(\rightarrow\) 6 clusters. - Step 1: Merge A and B. Clusters: \(\{A,B\}, C, D, E, F\). Total clusters = 5. - Step 2: Merge C and D. Clusters: \(\{A,B\}, \{C,D\}, E, F\). Total clusters = 4. - Step 3: Merge \(\{A,B\}\) and E. Clusters: \(\{A,B,E\}, \{C,D\}, F\). Total clusters = 3. - Step 4: Merge \(\{C,D\}\) and F. Clusters: \(\{A,B,E\}, \{C,D,F\}\). Total clusters = 2. - Step 5: Merge \(\{A,B,E\}\) and \(\{C,D,F\}\). Clusters: \(\{A,B,C,D,E,F\}\). Total clusters = 1. The researcher wants exactly 3 clusters. This corresponds to the state after Step 3. The clusters are: 1. \(\{A, B, E\}\) 2. \(\{C, D\}\) 3. \(\{F\}\) The total within-cluster sum of squares (WCSS) is the sum of the costs incurred to form these clusters. In Ward's method, the "cost" of a merge is the increase in the total WCSS. The total WCSS of a partition is the sum of the costs of all merges performed to reach that partition. Total WCSS = Cost(Step 1) + Cost(Step 2) + Cost(Step 3) \[ \text{Total WCSS} = 10 + 20 + 50 = 80 \] Note: The cost of Step 4 (80) and Step 5 (200) are not included because those merges would reduce the number of clusters below 3. Answer: The clusters are \(\{A,B,E\}\), \(\{C,D\}\), and \(\{F\}\). The total WCSS is 80.