Lines and trajectories¶
Draw a line on an embedding or a tissue section and find the genes whose expression changes along it, or with distance from it. Use it for a developmental path through a UMAP, a gradient across a tissue axis (proximal to distal, surface to depth), or a boundary you want to test expression against.
Where to find it
Draw with Add → Line in the toolbar. Analyze from the Shapes panel: the gear icon on a line opens Line Tools; ticking several lines shows Find Associated Genes at the bottom of the panel.
How it works¶
Every cell is projected onto the line: Skopia finds the nearest point on the line (the smoothed version, if you smoothed it) and records two numbers for the cell:
- position along the line, from 0 at the start to 1 at the end, by arc length;
- distance from the line, perpendicular, rescaled to 0 to 1 over the tested cells for the analysis.
Find Associated Genes fits, for each gene, a cubic B-spline regression of expression on one of these two variables, and compares it with an intercept-only model by an F-test. P-values are corrected across the tested genes by Benjamini-Hochberg (Benjamini and Hochberg 1995). Interior knots sit at quantiles of the test variable, so each spline segment covers a similar number of cells. For each gene Skopia also reports:
- R²: the share of the gene's variance the spline explains;
- amplitude: the range of the fitted curve (highest minus lowest predicted expression);
- direction: the correlation of the fitted curve with the test variable, positive when expression rises along (or away from) the line.
Significant genes are ranked by −log10(FDR) × amplitude.
The test reads .X as it is
Expression comes straight from .X, without normalization. Run normalization and log transformation first (see Preprocess), or the test will be driven by sequencing depth.
Draw a line and pick its cells¶
- Draw the line on the embedding with Add → Line (Pencil, Smooth Curve or Segmented Line); see Shapes and text labels. Draw it in the direction you want position 0 to 1 to run.
- Decide which cells to test. Select cells (with a lasso, or by clicking a category in the Cells panel) and click + on the line's row in the Shapes panel to project them onto the line. Repeat to add more; a cell is added only once. The row shows the number of projected cells.
- If a line has no projected cells, the analysis uses every active cell (all cells, or those inside the cell mask). If it has projected cells, it uses those, minus any outside the cell mask.
At least 20 cells are needed.
Line Tools¶
Click the gear icon on a line in the Shapes panel. Line Tools has these sections:
| Section | What it does |
|---|---|
| Smoothing | Smooths the drawn path with a moving window (Window 5 points, Iterations 2 by default). The analysis and the projections use the smoothed line once it exists. |
| Appearance | Line color and width, an optional fill, and whether the shape is closed. |
| Projections | Shows how many cells are projected; Clear Projections removes them. |
| Gene Association | Runs the test described above with Find Associated Genes (parameters below). The button becomes Cancel while it runs. |
| Projection Embedding | Create Projection Embedding adds an embedding with position along the line on X and normalized distance from it on Y, obsm['X_<line>_proj']. Cells that are not projected (when the line has projections) get no coordinates. |
Gene Association parameters¶
| Parameter | Default | What it does |
|---|---|---|
| Test against | Position along line | Or Distance from line: does expression change with distance from the line rather than along it? |
| Gene subset | none (every gene not hidden by the gene mask) | Restrict the test to boolean .var columns (such as highly_variable) and gene sets from the Genes panel. Several pills combine with the AND / OR toggle. |
| Spline knots | 5 | Interior knots of the cubic B-spline (2 to 20). More knots fit more complex profiles but can overfit. With 5 knots the spline has 9 basis functions, so the F-test has 8 degrees of freedom beyond the intercept. |
| FDR | 0.05 | Benjamini-Hochberg threshold for significance (0.001 to 0.5). |
| Max genes/direction (Max genes/module when clustering) | blank | Optional cap. Blank returns every gene that passes the FDR threshold; a number keeps the highest-scoring genes in each direction, or in each module. |
| Cluster genes into modules | Off | Groups the significant genes by the shape of their fitted profile (below). Off returns two lists, increasing and decreasing. |
Defaults can be changed in your config file under line_association (see Configure defaults).
Restrict to a gene set to gain power
The FDR correction runs over the genes you test. Testing a 40-gene signature rather than 20,000 genes corrects over 40, so a real gradient that does not survive transcriptome-wide correction can survive in the restricted test. Choose the set before you look at the result, not after.
Gene modules¶
With Cluster genes into modules on, each significant gene's fitted profile is evaluated at 50 points along the line and scaled to 0 to 1. Profiles are clustered hierarchically (average linkage on correlation distance, cut at 0.5), and each module's mean profile is classified:
| Pattern | Rule on the module's mean profile |
|---|---|
| increasing | Correlation with position above 0.7 (or above 0.3 when it is neither a peak nor a trough). |
| decreasing | Correlation below −0.7 (or below −0.3, likewise). |
| peak | Its maximum lies in the interior (outside the first and last 15%) and exceeds the mean of the two ends by more than 0.2. |
| trough | Its minimum lies in the interior and is more than 0.2 below the mean of the two ends. |
| complex | None of the above. |
Within a module, genes are listed by where their profile peaks along the line.
The results window¶
The results open in their own window, titled Line Association: and the line name. It shows the cells and genes tested, the number of significant genes, the FDR threshold, the number of modules, and diagnostics about the expression matrix and the positions.
- Filters narrows what is shown and saved: Min R², Min amplitude and Max FDR (up to the threshold the analysis used). With modules, pattern buttons (increasing, decreasing, peak, trough, complex) show or hide each pattern.
- Add to Gene Sets saves the genes that pass the filters into the Line Association category of the Genes panel, in a new folder named after the line and the time of the run. With modules, each module becomes a set named after its pattern and size (for example
Peak (14)). Without modules, one combined set,Associated genes (N), holds both directions. - Download CSV saves
<line>_line_association.csvwith one row for every gene tested, significant or not, so the file can serve as a ranked list for GSEA or other external analysis:
| Column | Meaning |
|---|---|
gene |
Gene name |
f_stat |
F statistic of the spline model against the intercept-only model |
pval |
P-value of the F-test |
fdr |
Benjamini-Hochberg adjusted p-value |
r_squared |
Variance explained by the spline |
amplitude |
Range of the fitted curve |
direction |
Correlation of the fitted curve with the test variable (−1 to 1) |
The run itself writes nothing to the dataset; the gene sets live in the Genes panel.
Several lines: sections and replicates¶
When the same biological axis appears on several tissue sections or replicates, pool them into one test:
- Draw a line on each section along the same axis.
- For each line, select its cells and click + to project them.
- Tick the checkbox that appears on each line with projected cells. The panel shows the number of lines and cells.
- Click Find Associated Genes at the bottom of the Shapes panel.
- In the multi-line window, check each line's direction and click its arrow to reverse it if it was drawn the other way, so position 0 means the same place on every section. Set Test against and the parameters as for one line.
- Click Find Associated Genes. Positions are computed per line (distances are rescaled per line), then all cells are pooled into a single test with more power than any one line alone.
Cells outside the cell mask are left out of every line.
Ordering heatmap cells by a line¶
The expression heatmap can order its cells by a line: By line position, By distance from line, or Category, then position (grouped by a category, then ordered along the line within each group). These use the same projection, so a heatmap of a module's genes shows the profile the test found. See Expression heatmaps and dot plots.
Tips and pitfalls¶
Lines live on one embedding
A line belongs to the embedding and the pair of dimensions it was drawn on. Cells are projected using those coordinates; a line drawn on a UMAP measures position in that UMAP, which is not a physical or developmental distance.
Position on a UMAP is not pseudotime
Distances in a UMAP are distorted. A line through a UMAP is a convenient way to order cells along a path you can see; for an ordering derived from the data, see Diffusion maps and pseudotime.
Long runs can be cancelled
Gene association runs in the background. Cancelling stops it without changing the dataset.