Skip to content

Diffusion maps and pseudotime

A diffusion map gives smooth axes along continuous processes such as differentiation, and diffusion pseudotime (DPT) orders cells along them from a root cell you choose. Use them to ask which cells sit early or late on a trajectory and which genes change along it. Both run on any cell-cell graph, including the spatial graph, where the leading components become smooth axes across the tissue.

Where to find it

Analyze → Cells → Diffusion map, then Analyze → Cells → Pseudotime (DPT) → Open Pseudotime tool…

How it works

A diffusion map (Haghverdi et al. 2015) treats the graph as a random walk and takes the leading eigenvectors of its transition matrix as coordinates. Cells that are many short steps apart along a continuous path end up far apart, so the components follow the path rather than straight-line distance in gene space. Diffusion pseudotime (Haghverdi et al. 2016) measures, for every cell, a diffusion distance from a root cell, using the map's components.

The computation is scanpy's (sc.tl.diffmap, sc.tl.dpt; Wolf et al. 2018), run on a throwaway copy that holds only the graph, so on a symmetric, connected kNN graph the result equals scanpy's. Skopia adds handling for the graphs that are not a scanpy kNN graph (spatial, combined, a subset's slice):

  • DC0 is the stationary state, as in scanpy: a component that carries no information about the trajectory. The plot opens on the first informative pair, DC1 × DC2 for a connected graph, and the axis pickers name the components DC0, DC1, ….
  • Isolated cells and small pieces get no coordinates. Cells with no edges, and connected pieces of fewer than 10 cells, are left out (NaN) rather than placed at 0 on every component, which is what scanpy does silently.
  • An asymmetric graph is symmetrized as (W + Wᵀ)/2 before the eigen-decomposition. squidpy's kNN spatial graph is asymmetric (being among a cell's k nearest is not mutual), and an asymmetric matrix gives wrong eigenvectors without an error.
  • A disconnected graph is reported. Each connected piece adds its own stationary component, and the map is computed piece by piece; the result lists the piece sizes.
  • A graph in too many pieces is refused when it has as many pieces as components requested, since every component would then only say which piece a cell is in. The message suggests running on a subset that is one piece, running Neighbors on the subset first so it has its own graph, using a more connected graph, or asking for more components.
Method details

Two-cell pieces, trees and four-neighbor grids are bipartite and have eigenvalues of −1. scanpy picks eigenpairs by largest magnitude, so those can push informative components out of the result; Skopia retakes them by largest value when that happens. Eigenvalues of 0.9994 or more count as stationary (scanpy's own cut). A disconnected graph is decomposed per piece because ARPACK misses repeated eigenvalues of 1 on a block-diagonal matrix and could stall for minutes on a graph in many pieces.

Diffusion map

Run it

  1. Build a graph: Neighbors (PCA, neighbors, UMAP, Leiden), Spatial Neighbors (Spatial neighbors and autocorrelation), or a Combine Neighbors result.
  2. Open Analyze → Cells → Diffusion map.
  3. Pick the kNN graph and, if you want, an Embedding name.
  4. Click Run. The plot switches to the new embedding on its first informative pair of components.

With a cell mask active, the run asks for a subset name and uses that subset's own graph when it has one (Named subsets and the subset tree).

Parameters

Parameter Default What it does
kNN graph the dataset default graph The graph to diffuse over: the expression kNN, the spatial graph, a Combine Neighbors result, or a subset's own graph. Picking one removes the need for Neighbors.
Embedding name blank (from the graph) obsm key for the result
Components 15 Diffusion components to compute, including DC0; at least 3

What it writes

Where What
obsm['X_diffmap'] Diffusion components of the default graph (cells × components, NaN for cells without coordinates)
obsm['X_diffmap_spatial'], obsm['X_diffmap_<graph>'] The same on another graph
obsm['X_diffmap_<subset>'] A run on a named subset; NaN outside it
uns['skopia_diffmaps'][<name>] The graph, eigenvalues and number of stationary components of each map
uns['diffmap_evals'] scanpy's eigenvalue slot, written for X_diffmap

Pseudotime (DPT)

Run it

  1. Compute a diffusion map.
  2. Open Analyze → Cells → Pseudotime (DPT) and click Open Pseudotime tool….
  3. Pick the Diffusion map and the number of Components used (default 10, scanpy's default, or every component when the map has fewer).
  4. Pick a Root (below).
  5. Optionally change the Output column name.
  6. Click Compute pseudotime. The result line names the column, the rule that chose the root, the root cell, how many cells it covers and how many components it used; the embedding is colored by the new column.

The cell mask is not used: pseudotime covers the cells of the diffusion map. To scope it, run Diffusion map on a subset.

Root choices

Root How the root cell is chosen
Most potent cell (stemFinder) The least differentiated cell by a stemFinder score: the lowest stemfinder, or the highest diffometer (Noller and Cahan 2024). Offered when a stemFinder score exists; see Differentiation (stemFinder).
Lowest value of a column The cell with the smallest value of a numeric .obs column
Highest value of a column The cell with the largest value of a numeric .obs column
A cell group The cell nearest the center of one category of a column, measured the way DPT measures distance
The current selection One selected cell is the root; for several, the one nearest their center, measured the same way
Tip of a diffusion component The Low end of or High end of a chosen component. The usual choice when nothing is annotated.

The analysis record keeps the root cell that was resolved, so the exported code starts from the same cell whatever rule picked it.

What it writes

Where What
obs['dpt_pseudotime'] Pseudotime on X_diffmap
obs['dpt_pseudotime_spatial'], obs['dpt_pseudotime_<subset>'] Named after the map, so each map's pseudotime sits beside it
uns['skopia_dpt'][<column>] The map, components used, root cell and the rule that chose it
uns['iroot'] scanpy's root slot, written for dpt_pseudotime on X_diffmap

Running again into the same column overwrites it.

Tips and pitfalls

Cells the root cannot reach

On a graph in several pieces, cells outside the root's piece get no pseudotime (scanpy would give them infinity). The tool warns before the run when the map has more than one piece, and the result says how many cells were left out.

Choosing a root

Pseudotime is only as meaningful as the root. A tip of a diffusion component is a reasonable start on an unannotated trajectory, but check which end is which against known markers. On data with a progenitor population, the most potent cell by stemFinder, or a known early cluster as A cell group, ties the root to biology rather than to the geometry of one component.

Changing the graph afterward

Pseudotime is computed on the graph the map was built on. If that graph is deleted or rebuilt after the map was computed, DPT refuses to run and asks you to re-run the diffusion map.