Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Choosing Geometry for Trajectory Inference

Pseudotime and Trajectory Inference · Tutorial 354 of 700

Choosing Geometry for Trajectory Inference

You will learn to compare geometric choices for cell-state data, calculate how they change neighborhoods, and diagnose when a representation may mislead trajectory analysis.

Advanced 11 min read

What You'll Learn

  • Explain how feature scaling changes the relative influence of genes on cell-to-cell distance.
  • Compare Euclidean and cosine dissimilarity and identify when their neighborhood rankings differ.
  • Derive how a linear representation changes squared distances between cells.
  • Assess how truncated low-dimensional representations can collapse distinct cell states.
  • Use neighborhood checks to diagnose geometry that may distort a trajectory.

Why Geometry Matters for Trajectory Inference

Pseudotime is a relative ordering of cells along a proposed biological progression; the introductory material on pseudotime as a relative ordering establishes that interpretation. Before an ordering can be constructed, however, an analysis must decide which cells are close to one another. That decision depends on the geometry assigned to the data: the features included, their scales, the distance or dissimilarity used, and any low-dimensional representation in which cells are compared.

These choices are not merely computational conveniences. If two cells differ substantially in a gene given high weight, the chosen geometry may place them far apart even when their other expression patterns are similar. If a low-dimensional projection discards a direction that distinguishes a transitional state, distinct cells may appear nearly identical. A trajectory method can only work with the relationships supplied to it; it cannot recover biological distinctions that the geometry has erased.

Definition: Represent cell \(i\) by a feature vector \(x_i=(x_{i1},\ldots,x_{ip})\), where the \(p\) features might be selected genes or coordinates in a cell representation. A geometric choice consists of (1) how those features are scaled or weighted, (2) a distance or dissimilarity applied to the resulting vectors, and (3), if used, a transformation into a lower-dimensional representation. The resulting cell neighborhoods are the cells judged closest under those choices.

The feature values should be comparable across cells before their distances are interpreted. In single-cell analysis, this generally means using an appropriate normalized and transformed expression representation rather than comparing raw counts as though they had a common measurement scale. The same cells must be represented on the same features, and technical variation should not dominate the biological differences of interest. These are substantive assumptions: if a feature mainly reflects library size or batch, a distance calculation can faithfully measure that nuisance variation instead.

Scaling Sets the Relative Influence of Features

For vectors \(x_i\) and \(x_j\), Euclidean distance is the square root of the sum of squared feature differences. Consequently, a feature with numerically large variation can dominate the distance, even if its biological importance is no greater than that of other features. Scaling changes the contribution of each feature before distances are calculated.

$$ d_E(x_i,x_j)=\sqrt{\sum_{k=1}^{p}(x_{ik}-x_{jk})^2} $$

One common approach divides each feature by a chosen scale \(s_k>0\), so that the distance becomes \(\sqrt{\sum_k ((x_{ik}-x_{jk})/s_k)^2}\). A scale may be a standard deviation, a robust spread estimate, or a scientifically chosen unit. Dividing by a small \(s_k\) gives that feature more influence; dividing by a large \(s_k\) gives it less. Standardizing every gene to unit variance is therefore not a neutral default: it can amplify noisy, low-variance genes. Conversely, leaving all features unscaled can let a few high-variance genes dominate.

Worked Example: Scaling Reverses the Nearest Neighbor

Suppose three hypothetical cells have values on two transformed expression features, \(g_1\) and \(g_2\): \(A=(0,0)\), \(B=(2,0)\), and \(C=(0,6)\). First use ordinary Euclidean distance.

From \(A\), the distances are \(d_E(A,B)=\sqrt{(2-0)^2+(0-0)^2}=2\) and \(d_E(A,C)=\sqrt{(0-0)^2+(6-0)^2}=6\). Thus \(B\) is closer to \(A\) than \(C\) is.

Now suppose the analysis divides the \(g_2\) values by 4 while leaving \(g_1\) unchanged. The scaled vectors are \(A=(0,0)\), \(B=(2,0)\), and \(C=(0,1.5)\). The new distances are \(d(A,B)=2\) and \(d(A,C)=1.5\). Now \(C\) is closer to \(A\). The arithmetic is simple, but the interpretation matters: the scaling choice changed the nearest neighbor, and therefore could change the local cell-state relationships used by a trajectory analysis. The scale factor must have a defensible rationale, not be selected because it produces a preferred trajectory.

Distance Choice Encodes What Counts as Similar

Euclidean distance responds to both direction and magnitude. An alternative for nonzero vectors is cosine dissimilarity, defined as one minus the cosine of the angle between them. It focuses on angular alignment and is insensitive to multiplying either vector by a positive constant. This can be useful when relative profiles matter more than overall magnitude, but it can also disregard magnitude differences that carry biological information. Cosine dissimilarity is not always a metric in the strict mathematical sense, so it should not be described as interchangeable with Euclidean distance.

$$ d_{\cos}(x_i,x_j)=1-\frac{x_i^\mathsf{T}x_j}{\|x_i\|_2\|x_j\|_2} $$

Worked Example: Euclidean and Cosine Neighborhoods

Consider hypothetical nonzero feature vectors \(A=(1,0)\), \(B=(10,1)\), and \(C=(0,2)\). Under Euclidean distance, \(d_E(A,B)=\sqrt{(10-1)^2+(1-0)^2}=\sqrt{82}\approx9.055\), while \(d_E(A,C)=\sqrt{(0-1)^2+(2-0)^2}=\sqrt{5}\approx2.236\). Thus \(C\) is the closer cell to \(A\) by Euclidean distance.

For cosine dissimilarity, \(A^\mathsf{T}B=10\), \(\|A\|_2=1\), and \(\|B\|_2=\sqrt{101}\). Therefore \(d_{\cos}(A,B)=1-10/\sqrt{101}\approx0.004963\). Since \(A^\mathsf{T}C=0\), \(d_{\cos}(A,C)=1-0=1\). Under cosine dissimilarity, \(B\) is much closer to \(A\) than \(C\) is.

The rankings differ because \(B\) points almost in the same direction as \(A\) but has much greater magnitude. Euclidean distance treats that magnitude difference as substantial; cosine dissimilarity largely ignores it. Neither result is automatically correct. The appropriate choice depends on whether magnitude or profile direction should define similarity for the intended biological question.

Low-Dimensional Representations Change Distances

A low-dimensional representation maps each original feature vector to a smaller set of coordinates. Principal component analysis (PCA), for example, projects data onto selected directions of variation. The projection may make computation and visualization more manageable, but distances in the projected space are not generally the original distances. In particular, directions omitted from the representation no longer contribute.

This effect can be stated directly for any linear map. Let \(z_i=Ax_i\), where \(A\) is a matrix defining scaling, rotation, or projection. The squared Euclidean distance between represented cells is:

$$ \|z_i-z_j\|_2^2 =\|A(x_i-x_j)\|_2^2 =(x_i-x_j)^\mathsf{T}A^\mathsf{T}A(x_i-x_j) $$

The final equality follows by writing the squared norm of a vector \(v\) as \(v^\mathsf{T}v\), then substituting \(v=A(x_i-x_j)\). Thus the matrix \(A^\mathsf{T}A\) determines how differences in the original features contribute to represented distance. If \(A\) is an orthogonal projection, components perpendicular to the retained subspace contribute zero. If features are scaled before projection, their relative contributions are altered before the projection is applied.

Worked Example: Projection Collapses a Distinct State

Suppose three hypothetical cells have coordinates \(A=(0,0)\), \(B=(1,0)\), and \(C=(0,2.5)\) on two features. Assume the first coordinate varies much more across a larger set of cells, so a one-dimensional representation retains only the first coordinate: \(z_i=(x_{i1})\). In the original space, \(d_E(A,B)=1\) and \(d_E(A,C)=2.5\), so \(B\) is closer to \(A\).

After projection, the coordinates are \(z_A=0\), \(z_B=1\), and \(z_C=0\). Therefore \(d(z_A,z_B)=|0-1|=1\), but \(d(z_A,z_C)=|0-0|=0\). Cells \(A\) and \(C\), distinct in the original feature space, are now indistinguishable in this representation.

This is not an arithmetic error. The projection discarded the second coordinate. If that coordinate represented a meaningful transitional state, the one-dimensional representation erased a biologically relevant distinction. High overall variance explained by retained components does not guarantee that every local cell-state distinction is preserved.

Checks for a Defensible Trajectory Geometry

A useful geometry is not simply the one that produces a visually smooth arrangement. It should preserve neighborhoods that are meaningful for the question, while avoiding dominance by technical effects or arbitrary measurement scales. Diagnostics should therefore examine the consequences of the chosen representation, not just its appearance.

1
Inspect feature contributions.
Check whether a small number of genes or coordinates dominate distances because of scale or extreme variability. Consider whether standardization would amplify noisy features, and whether an explicit weighting has a biological rationale.
2
Compare neighborhood stability.
For cells of interest, compare nearest neighbors under plausible scaling choices, distance measures, and representation dimensions. Extensive changes indicate that the inferred local structure is sensitive to analytical choices.
3
Check biological and technical structure.
Ask whether expected related cell states remain close and whether neighborhoods instead group cells by batch, library size, or another nuisance variable. A representation can be mathematically consistent yet scientifically unhelpful.
4
Report the geometry.
State which features and representation were used, how they were scaled, and what distance or dissimilarity defined closeness. Without these details, the resulting trajectory geometry is difficult to interpret or reproduce.

There is no universal choice that is optimal for every dataset. Euclidean distance is transparent and has a direct interpretation in the chosen coordinates, but is sensitive to feature scales and magnitude. Cosine dissimilarity emphasizes profile direction but may discard meaningful magnitude differences. A low-dimensional representation can reduce irrelevant variation and simplify analysis, yet can also eliminate directions that separate rare or transitional states. Conclusions should be treated cautiously when plausible alternatives produce substantially different neighborhoods.

Common Mistake: Treating the Embedding as the Data

A common mistake is to reason, “These cells overlap in the two-dimensional plot, so their original expression profiles are the same.” The correction is that a projection can map distinct cells to the same or nearby coordinates by omitting directions of variation. A two-dimensional visualization is evidence about the chosen representation, not proof that all original feature differences have disappeared. Likewise, a smooth-looking arrangement does not establish that the chosen scale or distance is biologically appropriate.

The geometry matters because downstream trajectory methods inherit it. If a scale exaggerates noise, a distance ignores meaningful magnitude, or a projection collapses distinct states, local relationships may be distorted before any trajectory is fitted. Sensitivity checks across defensible alternatives help distinguish stable structure from conclusions that depend heavily on one geometric choice.

Check Your Understanding

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

  1. For \(A=(0,0)\), \(B=(3,0)\), and \(C=(0,4)\), which cell is closer to \(A\) by Euclidean distance? If the second feature is divided by 2, which cell becomes closer?
  2. Why can cosine dissimilarity and Euclidean distance rank neighbors differently?
  3. A projection retains only the first coordinate. What happens to the distance between \((2,1)\) and \((2,5)\) after projection?
  4. Name two checks that could reveal whether a chosen representation is distorting local cell-state neighborhoods.

Solutions. (1) Originally, \(d_E(A,B)=3\) and \(d_E(A,C)=4\), so \(B\) is closer. After dividing the second feature by 2, \(C\) becomes \((0,2)\); its distance from \(A\) is 2, while \(B\)'s remains 3, so \(C\) is closer. (2) Euclidean distance uses both direction and magnitude, whereas cosine dissimilarity depends on angular alignment and is unchanged by positive rescaling of a vector. (3) The projected coordinates are both 2, so the projected distance is \(|2-2|=0\), although the original distance is \(\sqrt{(2-2)^2+(5-1)^2}=4\). (4) Examples include comparing nearest-neighbor sets across plausible scales or dimensions, checking whether neighborhoods are organized by technical variables, and assessing whether biologically expected states remain nearby.

Clinical Biostats