Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Projecting Cells and Measuring Arc Length

Pseudotime and Trajectory Inference · Tutorial 356 of 700

Projecting Cells and Measuring Arc Length

Learn to distinguish a curve parameter from arc-length pseudotime, calculate projections and along-curve distances, and recognize when those calculations are unreliable.

Advanced 12 min read

What You'll Learn

  • Define a cell’s projection onto a fitted curve as a point minimizing embedding-space distance.
  • Compute pseudotime by integrating the curve’s speed from a chosen starting point.
  • Calculate projection and arc length for a parametrized curve.
  • Project cells onto sampled, piecewise-linear curves and accumulate segment lengths.
  • Diagnose ambiguous projections, endpoint effects, and discretization error.
  • Explain why pseudotime is a geometric ordering, not elapsed biological time.

From a Fitted Curve to a Cell’s Pseudotime

A fitted trajectory is a path through an embedding of cells. To assign a location along that path to an observed cell, first find the point on the path closest to the cell, then measure distance along the path to that point. These are two separate operations: projection selects a location on the curve, while arc length gives that location a distance-based coordinate.

Let \(\mathbf{y}_i\) be the embedding coordinate of cell \(i\), and let \(\boldsymbol{\gamma}(u)\) be a fitted curve over a parameter domain \(u\in[a,b]\). For now, regard the fitted curve as fixed. Under Euclidean distance, a projection parameter is any minimizer of the squared distance from the cell to the curve. If the minimizer is unique, denote it by \(\hat u_i\). A pseudotime coordinate can then be measured from the start \(a\) of the parameterized path to that projected location.

Definition: For a curve \(\boldsymbol{\gamma}(u)\), the projection of cell \(i\) is \(\boldsymbol{\gamma}(\hat u_i)\), where \(\hat u_i\) minimizes \(\|\mathbf{y}_i-\boldsymbol{\gamma}(u)\|^2\) over the curve’s domain. If the curve is differentiable and has finite length, the arc-length pseudotime from \(a\) to \(\hat u_i\) is $$ \tau_i=\int_a^{\hat u_i}\|\boldsymbol{\gamma}'(u)\|\,du. $$

This definition uses Euclidean distance in the chosen embedding coordinates. It assumes that the fitted path is specified on a domain over which a minimum exists; a continuous curve on a closed, bounded parameter interval is one sufficient condition. The arc-length integral assumes a piecewise differentiable curve with finite length. For a sampled path, distances are instead accumulated over its line segments.

Arc length is measured in the units of the embedding coordinates. It is not automatically measured in hours, days, or any other biological time unit. Its zero and direction also depend on how the path is parameterized and oriented: reversing the path reverses the ordering, and changing the starting point changes the zero.

Why the Parameter Is Not Usually Pseudotime

The parameter \(u\) is a label for positions on a curve. Unless the curve has been parameterized by distance, equal changes in \(u\) need not correspond to equal travel distances. The speed \(\|\boldsymbol{\gamma}'(u)\|\) accounts for how quickly the curve moves through the embedding as \(u\) changes.

A simple justification comes from approximating a short piece of a differentiable curve. For a small increment \(\Delta u\), the displacement is approximately \(\boldsymbol{\gamma}'(u)\Delta u\), so the distance traveled is approximately \(\|\boldsymbol{\gamma}'(u)\|\Delta u\). Adding these short distances and taking the limit gives the integral of speed in the definition. This is why arc length measures distance along the path, rather than merely recording its parameter value.

The coordinate is invariant to a smooth, increasing change of parameter. If the same path is written as \(\tilde{\boldsymbol{\gamma}}(v)=\boldsymbol{\gamma}(\phi(v))\), with \(\phi\) increasing, then its speed is \(\|\boldsymbol{\gamma}'(\phi(v))\|\phi'(v)\). Substitution into the arc-length integral gives the same distance along the path. Thus, changing the parameterization alone changes the parameter values, but not arc length to a given point on the geometric path.

Worked Example: Projecting onto a Quarter-Circle

Suppose a fitted curve is the quarter-circle \(\boldsymbol{\gamma}(\theta)=(3\cos\theta,3\sin\theta)\), for \(0\leq\theta\leq\pi/2\), and a hypothetical cell has embedding coordinate \(\mathbf{y}=(2,2)\). Find its projection and arc-length pseudotime measured from \(\theta=0\).

The squared distance at angle \(\theta\) is $$ D^2(\theta)=(2-3\cos\theta)^2+(2-3\sin\theta)^2 =17-12(\cos\theta+\sin\theta). $$ On this interval, \(\cos\theta+\sin\theta\) is largest at \(\theta=\pi/4\). Therefore \(D^2(\theta)\) is smallest there, and the projected point is $$ \boldsymbol{\gamma}(\pi/4)=\left(\frac{3}{\sqrt{2}},\frac{3}{\sqrt{2}}\right)\approx(2.121,2.121). $$ The distance from the cell to that projection is \(3-2\sqrt{2}\approx0.1716\) embedding units. The speed of the parameterized curve is $$ \|\boldsymbol{\gamma}'(\theta)\| =\|(-3\sin\theta,3\cos\theta)\|=3. $$ Consequently, the pseudotime from the start of the arc is $$ \tau=\int_0^{\pi/4}3\,d\theta=\frac{3\pi}{4}\approx2.356 $$ embedding units along the curve. The cell’s projection distance, about \(0.1716\), is not its pseudotime: one measures distance off the curve, the other distance along it.

Arc Length on a Parametrized Curve

For a curve in two dimensions, \(\boldsymbol{\gamma}(u)=(x(u),y(u))\), its speed is \(\sqrt{x'(u)^2+y'(u)^2}\). The same definition extends to higher-dimensional embeddings by taking the Euclidean norm of the derivative vector. In practice, the integral may have a closed form, be evaluated numerically, or be approximated from sampled points on the curve.

Worked Example: Arc Length Along a Parabola

Consider the hypothetical fitted curve \(\boldsymbol{\gamma}(u)=(u,u^2)\), for \(0\leq u\leq1\). A cell at \(\mathbf{y}=(0.5,0.25)\) lies exactly on the curve, so its unique projected parameter is \(\hat u=0.5\). Compute its arc-length pseudotime from \(u=0\), and compare it with the parameter value.

The derivative is \(\boldsymbol{\gamma}'(u)=(1,2u)\), giving speed \(\sqrt{1+4u^2}\). Hence $$ \tau=\int_0^{0.5}\sqrt{1+4u^2}\,du =\left[\frac{u}{2}\sqrt{1+4u^2}+\frac{1}{4}\operatorname{asinh}(2u)\right]_0^{0.5}. $$ Substitution gives $$ \tau=\frac{\sqrt{2}}{4}+\frac{\operatorname{asinh}(1)}{4} =\frac{\sqrt{2}+\ln(1+\sqrt{2})}{4} \approx0.5739. $$ The parameter value is \(0.5\), while the arc length is approximately \(0.5739\) embedding units. They differ because the curve’s speed is not constant. The cell has zero projection residual because it lies on the curve, but that does not make its pseudotime zero.

Projecting Cells onto a Sampled Path

A fitted curve may be stored as an ordered sequence of points rather than as a formula. Connecting consecutive points with straight segments gives a piecewise-linear path. For a segment from \(\mathbf{v}_j\) to \(\mathbf{v}_{j+1}\), define its direction vector \(\mathbf{d}_j=\mathbf{v}_{j+1}-\mathbf{v}_j\). The closest point on the infinite line has segment coordinate $$ r=\frac{(\mathbf{y}_i-\mathbf{v}_j)\mathbin{\cdot}\mathbf{d}_j}{\|\mathbf{d}_j\|^2}. $$ To restrict the projection to the segment, replace \(r\) by the nearest value in \([0,1]\): values below zero become zero, and values above one become one. The projected point is \(\mathbf{v}_j+r\mathbf{d}_j\). Compare candidate distances across segments and choose a minimum. The pseudotime is the sum of lengths of all completed segments before the selected segment, plus the distance traveled along that segment.

This calculation assumes the sampled points are ordered along the fitted path and that straight segments are an adequate approximation between them. Repeated consecutive points give a zero-length segment, for which the displayed fraction is undefined; such segments should be removed or handled separately.

Worked Example: Projecting Cells onto a Three-Vertex Path

Take a hypothetical sampled path with ordered vertices \(\mathbf{v}_0=(0,0)\), \(\mathbf{v}_1=(2,0)\), and \(\mathbf{v}_2=(2,2)\). Its two segments each have length \(2\). Project cells \(\mathbf{y}_A=(0.7,0.8)\), \(\mathbf{y}_B=(2.5,1.5)\), and \(\mathbf{y}_C=(0.5,-0.2)\) onto the path and measure pseudotime from \(\mathbf{v}_0\).

For cell A, projection onto the first segment uses \(\mathbf{d}_0=(2,0)\): $$ r_A=\frac{(0.7,0.8)\mathbin{\cdot}(2,0)}{(2,0)\mathbin{\cdot}(2,0)} =\frac{1.4}{4}=0.35. $$ This gives projected point \((0,0)+0.35(2,0)=(0.7,0)\), at distance \(0.8\) from the cell. Its pseudotime is \(0.35(2)=0.70\) embedding units. Its distance to the second segment is at least \(1.3\), so the first-segment projection is nearer.

For cell B, the first-segment line projection lies beyond the endpoint \(\mathbf{v}_1\), so its restricted projection there is \((2,0)\). On the second segment, \(\mathbf{d}_1=(0,2)\), and $$ r_B=\frac{(0.5,1.5)\mathbin{\cdot}(0,2)}{4} =\frac{3}{4}=0.75. $$ The projected point is \((2,0)+0.75(0,2)=(2,1.5)\), only \(0.5\) embedding units from the cell. Its pseudotime is the first segment’s length plus \(0.75\) of the second segment’s length: \(2+0.75(2)=3.50\) embedding units.

For cell C, the first-segment fraction is \(r_C=((0.5,-0.2)\cdot(2,0))/4=0.25\). The projection is \((0.5,0)\), at distance \(0.2\) from the cell, and pseudotime is \(0.25(2)=0.50\) embedding units. Its distance to the vertical segment is greater, so the first segment is the nearest. This example illustrates why the projection distance and along-path pseudotime must be reported as distinct quantities.

Diagnostics, Alternatives, and Limits

A projection assigns each cell a location, but it does not guarantee that the cell lies close to the fitted path or that the assigned location is unambiguous. Useful checks include examining the projection residual \(\|\mathbf{y}_i-\boldsymbol{\gamma}(\hat u_i)\|\), plotting cells with their projected points, and checking whether neighboring cells receive abrupt jumps in pseudotime. Large residuals indicate that the path may poorly represent those cells in the chosen embedding. They can also arise for cells that are genuinely off the trajectory.

Several conditions can make the assigned coordinate fragile:

  • Multiple nearest points. A curve that folds close to itself can give a cell two equally close projections at different positions. The minimizing point, and therefore pseudotime, is then not unique without an additional convention.
  • Endpoint projections. A cell beyond the end of a fitted path may project to the endpoint. Many such cells can indicate that the fitted path does not extend far enough; the endpoint assignment alone does not establish that they belong at that position.
  • Coarse sampling. Straight segments can poorly approximate a highly curved path. Increasing the sampling density or comparing with a smoother representation can reveal sensitivity to this approximation.
  • Embedding and scaling choices. Euclidean projection depends on the coordinates and their scales. Rescaling dimensions can change which point is nearest and can change distances along the curve.

Arc-length pseudotime is often preferable to using the raw curve parameter because it removes arbitrary differences in speed caused by parameterization. It also describes distance along the fitted path, unlike Euclidean distance from a chosen start point, which can cut across bends. However, arc length is not a substitute for a biologically calibrated time scale. Nor does it express uncertainty in the fitted curve or in a cell’s projection. Alternative representations can be useful when the intended geometry is not a single smooth path, but a geometric coordinate should always be interpreted in light of the path and metric used to define it.

Common pitfall: Treating \(\hat u_i\) as pseudotime because it labels the projected position. This is only justified when the curve is parameterized at constant unit speed from the chosen origin. In general, compute \(\tau_i=\int_a^{\hat u_i}\|\boldsymbol{\gamma}'(u)\|\,du\), or accumulate segment lengths for a sampled path.

Check Your Understanding

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

  1. What does a projection residual measure, and how is it different from arc-length pseudotime?
  2. A straight fitted segment runs from \((0,0)\) to \((4,0)\). A cell is at \((3,1)\). Find its projected point, projection residual, and pseudotime from \((0,0)\).
  3. Why can a curve parameter change while arc length to the same geometric point stays unchanged?
  4. Give one reason a cell can have an ambiguous pseudotime even when the fitted curve is fixed.

Solutions. (1) The residual is the distance from the cell to its nearest point on the curve; pseudotime is distance along the curve from its designated start to that projected point. (2) The point \((3,0)\) is the projection, the residual is \(1\) embedding unit, and the pseudotime is \(3\) embedding units. (3) A change of parameter alters the labels and speed, but integrating speed over the corresponding parameter interval gives the same geometric distance. (4) For example, if the curve folds close to itself, two distinct points on it may be equally near the cell, producing different along-curve distances.

Clinical Biostats