Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Out-of-Sample Cell Placement in Embeddings

Dimension Reduction and Embeddings · Tutorial 229 of 700

Out-of-Sample Cell Placement in Embeddings

You will learn when cell coordinates can be carried into an existing embedding, how to project new cells with a fixed PCA model, and why nonlinear embedding refits can undermine direct reference comparisons.

Intermediate 11 min read

What You'll Learn

  • Project a new cell into PCA coordinates using the reference mean, preprocessing, and fixed loadings.
  • Explain why adding cells and refitting PCA can change even the reference coordinates.
  • Distinguish a fixed-reference placement from an ordinary t-SNE or UMAP refit.
  • Recognize how changing nonlinear embedding coordinates can affect visual reference mapping.
  • Choose an embedding strategy that preserves comparability between reference and new cells.
  • Check preprocessing and feature alignment before projecting new cells.

What Does It Mean to Place a New Cell?

A reference embedding assigns coordinates to a specified collection of cells. Out-of-sample placement asks a different question: given a new cell, can we assign it coordinates that are comparable to the reference coordinates without changing the reference placement? This matters when mapping a new sample onto a reference atlas, comparing successive batches, or locating cells from a later experiment in a previously interpreted visualization.

The answer depends on the embedding method. PCA has a fixed linear projection once the reference preprocessing and loadings are fixed. Ordinary t-SNE and UMAP, in contrast, construct an embedding by optimizing coordinates for a collection of cells and their relationships. Rerunning either method after adding cells is generally a new joint embedding, not simply an extension of the old one.

Definition: A fixed-reference placement assigns coordinates to a new cell using a transformation or embedding model learned from reference cells, while leaving the reference coordinates unchanged. A refit recomputes an embedding using the enlarged collection, so the coordinates of reference cells may change. A method with a defined fixed-reference placement is called inductive in this context; an embedding fitted jointly to the cells under consideration is transductive.

These terms describe how coordinates are obtained, not whether an embedding is biologically correct. A new cell can be projected consistently and still be unusual, poorly represented by the reference, or affected by technical differences.

Projecting a New Cell With Fixed PCA Loadings

Let the reference expression matrix have \(n\) cells and \(p\) features, with one row per cell. Before fitting PCA, the analyst chooses and applies a preprocessing pipeline, such as a normalization, a gene set, and possibly feature scaling. Let \(x_i^*\) be the resulting row vector for reference cell \(i\), and let \(y^*\) be the new cell after applying that same pipeline. Write \(\mu_{\mathrm{ref}}\) for the reference mean vector in the transformed feature space. Let \(V_k\) be the \(p \times k\) matrix whose columns are the first \(k\) reference PCA loading vectors, with orthonormal columns.

Definition: The fixed-reference PCA coordinates of a new cell are its scores $$ z_{\mathrm{new}}=(y^*-\mu_{\mathrm{ref}})V_k. $$ The reference scores are \(Z_{\mathrm{ref}}=(X^*-\mathbf{1}\mu_{\mathrm{ref}})V_k\), where \(X^*\) is the transformed reference matrix and \(\mathbf{1}\) is an \(n\)-vector of ones. Both new and reference cells are therefore expressed in the same centered feature space and along the same loading directions.

The formula is useful only when all ingredients match. The new cell must have the same features in the same order, and the reference normalization and any gene-wise scaling must be applied using the reference-fitted quantities. If the original analysis standardized each gene using a reference mean and standard deviation, the new cell must use those same values; estimating new scaling values from the incoming sample changes the coordinate system. The selected loading columns and their signs must also be retained. PCA loading signs can be reversed without changing the fitted PCA, but scores must use the corresponding fixed signs to compare with the stored reference coordinates.

Worked Example: Projecting a New Cell Into Two PCA Coordinates

Suppose a hypothetical analysis has three transformed features. Its reference PCA center is \(\mu_{\mathrm{ref}}=(2,1,0)\), and the first two fixed loading vectors are \(v_1=(0.6,0.8,0)\) and \(v_2=(-0.8,0.6,0)\). They are orthogonal unit vectors. A new cell has transformed values \(y^*=(5,5,2)\).

First center the new cell using the reference mean: \(y^*-\mu_{\mathrm{ref}}=(3,4,2)\). Its first score is the dot product with \(v_1\), and its second score is the dot product with \(v_2\): $$ z_{\mathrm{new}}=((3,4,2)\cdot(0.6,0.8,0),\ (3,4,2)\cdot(-0.8,0.6,0)) =(1.8+3.2,\ -2.4+2.4)=(5,0). $$

The new cell is thus placed at \((5,0)\) in this two-dimensional PCA coordinate system. This calculation does not require the new cell to be included in the PCA fit. It does require the same three features and transformed scale used to obtain the reference center and loadings.

Why the PCA Projection Is the Natural Fixed-Basis Placement

The score formula is not an arbitrary convention. For a fixed orthonormal loading matrix, it gives the coordinates whose reconstruction in the loading subspace is closest to the centered cell in squared Euclidean distance. To see this, let \(a=y^*-\mu_{\mathrm{ref}}\) and reconstruct \(a\) using any score row vector \(c\) as \(cV_k^T\). The squared reconstruction error is

$$ \|a-cV_k^T\|^2 =\|a\|^2-2c(aV_k)^T+\|c\|^2. $$

Here \(V_k^TV_k=I_k\), so \(\|cV_k^T\|^2=\|c\|^2\). Completing the square gives

$$ \|a-cV_k^T\|^2 =\|a\|^2-\|aV_k\|^2+\|c-aV_k\|^2. $$

The first two terms do not depend on \(c\), while the last term is minimized at \(c=aV_k\). Thus the fixed-loading PCA score is the least-squares projection onto the reference loading subspace. This geometric result does not say that the retained components capture every biologically relevant difference: the residual \(a-aV_kV_k^T\) can still be large.

Worked Example: Why a PCA Refit Changes Reference Coordinates

Consider a hypothetical one-feature reference with values 0 and 2. Its reference mean is 1, so its centered PCA scores (the feature direction is the sole loading) are \(-1\) and \(1\). A new cell has value 10.

With the reference fixed, the new cell's score is \(10-1=9\), while the old scores remain \(-1\) and \(1\). Now suppose all three cells are used to refit the centering. The enlarged-sample mean is \((0+2+10)/3=4\), so the new scores are \(-4\), \(-2\), and \(6\). The two reference cells have moved from \(-1,1\) to \(-4,-2\).

The values are deliberately simple, but the point holds more generally: refitting PCA can change the centering and the loading directions, either of which can change reference scores. A fixed-reference projection instead answers where the new cell lies relative to the original center and basis.

Why Ordinary t-SNE and UMAP Refits Are Different

PCA obtains coordinates by applying a fitted linear map. Ordinary t-SNE and UMAP instead seek coordinates for the set of cells being embedded. In t-SNE, high-dimensional neighborhood similarities are compared with low-dimensional similarities, and the coordinates are optimized to reduce a divergence between them. In UMAP, a weighted neighborhood graph is constructed and low-dimensional coordinates are optimized against its fuzzy connections. In both cases, adding cells can change the relationships being represented and the optimization problem itself.

For t-SNE, adding cells can change the high-dimensional similarity structure, including which cells are neighbors and the probabilities assigned to pairwise similarities. The low-dimensional similarities also depend on the coordinates of the full set. A new optimization can therefore move old points as it tries to represent the enlarged set. For UMAP, adding cells can change neighborhood connections and edge weights, and an ordinary refit optimizes an embedding for that altered graph. The direction and size of any change are not predictable from the fact that cells were added alone.

Some software provides a transform operation for a fitted UMAP model, or other methods for placing new observations relative to a fixed reference. These are distinct from refitting UMAP on the combined data. Such a transform uses the learned reference representation and implementation-specific rules to place new points while retaining the reference embedding. Its result depends on the transform method and its assumptions; it should not be treated as though it were the result of a full joint refit. Ordinary t-SNE does not, by itself, define a unique fixed map from expression profiles to coordinates. Specialized extensions can provide out-of-sample placement, but that is a different procedure from rerunning ordinary t-SNE.

Worked Example: A Nonlinear Refit Can Change a Mapping Story

Imagine a hypothetical reference embedding in which a reference cell A is at \((0,0)\) and reference cell B is at \((4,0)\). A new cell is embedded near A when placed with a fixed-reference procedure. An analyst might then describe it as visually close to A in that reference coordinate system.

Suppose instead the analyst appends the new sample and reruns ordinary t-SNE or UMAP. In one hypothetical refit, A is now at \((2,1)\), B at \((3,1)\), and the new cell at \((3.2,1)\). These coordinates are illustrative, not a guaranteed numerical outcome of either algorithm. They show why comparing a new coordinate to the old locations \((0,0)\) and \((4,0)\) would be invalid: the refit has changed the reference frame. Even if the new cell appears close to B in the refitted display, that visual relation does not establish a change in biological identity; the full set of coordinates was re-optimized.

A defensible comparison would use the newly refitted reference cells and new cells together, or would place new cells with a documented fixed-reference procedure. In either case, visual proximity is evidence about the embedding representation, not by itself a definitive cell-type assignment.

Practical Choices, Diagnostics, and Limitations

The appropriate method depends on the question. If the purpose is to preserve a reference coordinate system and place later cells within it, fixed PCA projection is direct and reproducible when preprocessing and loadings are retained. A fitted UMAP transform may also serve this purpose when its reference-based procedure is appropriate and documented. If the goal is to explore the geometry of all cells jointly, refitting t-SNE or UMAP can be reasonable, but the result should be treated as a new embedding rather than a stable extension of the old one.

ApproachWhat happens to reference coordinates?Main consideration
Fixed PCA projectionThey remain unchanged when the original center and loadings are retained.Linear projection; check the preprocessing and feature space.
Fitted UMAP transformTypically retained by the transform procedure.Behavior depends on the implementation and fitted model.
Ordinary t-SNE or UMAP refitThey may change because the enlarged data are embedded jointly.Interpret it as a new embedding, not direct placement into old coordinates.

Before interpreting any placement, check that the feature set, feature order, normalization, scaling, and missing-value handling match the reference procedure. For PCA, a useful diagnostic is the new cell's reconstruction residual, \(\|a-aV_kV_k^T\|\), alongside its projected score. A large residual warns that the retained components do not represent the cell well, even if its plotted location looks ordinary. Also check whether the cell lies far beyond the range of reference scores; projection remains mathematically defined, but extrapolation can make the visualization hard to interpret.

For nonlinear methods, keep the fitted reference coordinates and model if future placement is intended. If an ordinary refit is performed, compare only coordinates from that refit, and do not assume that old labels or boundaries can be transferred by reading the old plot. Neither a fixed projection nor a nonlinear transform removes batch effects, resolves incompatible preprocessing, or guarantees that a reference adequately represents a new population.

Common Mistakes

  • Recomputing preprocessing on the new sample. The mistaken reasoning is that each sample should be centered or scaled independently before projection. That changes the values being projected. Apply reference-fitted transformations consistently when the goal is comparison to that reference.
  • Assuming a nonlinear refit only adds points. Ordinary t-SNE and UMAP refits can change the reference coordinates as well. Use the new refit's reference positions for interpretation, or use a documented fixed-reference placement method.
  • Treating embedding proximity as a confirmed label. Nearby coordinates summarize an embedding's representation of relationships; they do not alone establish cell identity or biological equivalence.
  • Confusing a fitted transform with a refit. A transform designed to retain a reference embedding and a joint optimization on the enlarged data answer different questions, even if both produce a plot with old and new cells.
Key takeaway: To place a new cell in a comparable reference coordinate system, preserve the reference-fitted preprocessing and embedding map. Fixed PCA loadings give an explicit projection; ordinary t-SNE and UMAP refits generally create a new joint coordinate system.

Check Your Understanding

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

  1. A reference PCA used a stored center and loading matrix. Should a new cell be centered using the mean of its own batch or the reference center when the goal is fixed-reference placement? Explain.
  2. In a one-feature reference with values 2 and 6, what is the fixed-reference score of a new value 9? What are the reference scores?
  3. Why can adding cells to an ordinary UMAP refit alter reference coordinates?
  4. An analyst has rerun t-SNE after adding a new sample. Can the new coordinates be interpreted directly against the old reference coordinates? What should the analyst do instead?

Solutions. (1) Use the reference center, because using a new batch mean changes the coordinate origin and no longer applies the stored reference transformation. (2) The reference mean is \((2+6)/2=4\). The new score is \(9-4=5\), and the reference scores are \(2-4=-2\) and \(6-4=2\). (3) The enlarged set can have a different neighborhood graph and optimization objective, so the jointly optimized positions of the old cells may change. (4) No. The refit may have moved the reference cells. Compare the new cells with reference cells in the same refitted embedding, or use a documented method that places new cells while keeping the original reference coordinates fixed.

Clinical Biostats