Clustering gene expression
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
Proof
Result
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
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.
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
- 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.
Solution
Euclidean 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). - 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.
Solution
k-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. - 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.
Solution
Clustering 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. - 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). - 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.