Contour¶
Contour turns the spatial expression of a gene set into zones on the tissue. With one gene set it answers "where is this program high, medium or low?"; with several it answers "which tissue does each spot belong to?" and writes one annotation column.
Where to find it
Analyze → Spatial → Contour → Open Contour tool…
How it works¶
For each gene set Skopia builds a smooth expression field over the tissue and cuts it into bands:
- Each gene is optionally log-transformed (
log1p), clipped to its own 1st to 99th percentile, and rescaled to 0 to 1. The gene set's score per spot is the mean over its genes. This normalization is global, so "high" means the same thing everywhere in the tissue. - The scores are interpolated onto a square grid (Grid resolution points per axis, cubic interpolation, empty grid cells set to 0) and smoothed with a Gaussian filter of width Smoothing sigma, measured in grid pixels.
- Each spot reads the smoothed value at its nearest grid point.
- Contour levels thresholds are spaced evenly between 0 and the field's maximum. Each spot takes the highest threshold it reaches.
Genes in a set that are absent from the dataset are dropped and listed in an amber warning. The run fails only if a set has no genes present.
One gene set produces an ordered categorical column whose values are the band thresholds (0 for the lowest band).
Two or more gene sets produce a fused tissue annotation in two steps:
- Review & bin: every set is scored as above. For each one a histogram shows how many spots fall in each band, and you choose the band at or above which a spot counts as "high". The default is the top band.
- Finalize: a spot high in exactly one set gets that set's name. A spot high in several is resolved by a vote: among its spatial neighbors that are high in exactly one set, the Profile k closest in expression (Euclidean distance in
X_pca) vote, and the majority label wins. A tie, or no eligible neighbors, leaves the spotunassigned. Spots high in no set areunassigned. The vote is a single pass over the original single-set labels.
The neighbors for the vote come from obsp['spatial_connectivities'] when Spatial Neighbors has been run, and otherwise from a 15-nearest-neighbor graph on the coordinates.
Run it¶
- Open Analyze → Spatial → Contour → Open Contour tool….
- Click Choose gene sets… and tick sources: any saved gene set, or Current Gene Panel selection.
- Check Grid resolution and Smoothing sigma, which are prefilled from the data, and read any advice the tool shows below the form.
- If the dataset holds several sections, set Section column.
- One set: optionally name the column, then click Run contour. Two or more: click Compute (N sets).
- For two or more sets, pick each set's cutoff in the review step, set Profile k, the output Column name and Save QC columns, then click Finalize.
- Click Color by the new column to see the zones.
Parameters¶
| Parameter | Default | What it does |
|---|---|---|
| Contour levels | 3 | Number of thresholds (2 to 8), giving that many bands above the lowest. More levels give finer control over where "high" starts; they do not change the field. |
| Grid resolution | about √(number of spots), clamped to 50 to 600 | Interpolation grid points per axis. |
| Smoothing sigma | chosen so the smoothing reaches about two spot spacings, clamped to 1 to 6 | Gaussian width in grid pixels. |
| Log transform | off | Apply log1p to each gene before clipping. Meant for raw counts. |
| Section column | auto-detected section or sample column, else none |
Interpolate and smooth each section on its own grid. |
| Column name (one set) | contour_<first gene>_<n genes> |
Name of the banded .obs column. |
| Profile k (several sets) | 15 | How many single-set neighbors vote on a spot high in several sets. |
| Column name (several sets) | tissue |
Name of the fused annotation column. |
| Save QC columns (several sets) | off | Also write a status column and one high/low column per set. |
The non-suggested defaults can be changed in config.yaml under contour: (see Configure defaults).
Choosing grid resolution and sigma¶
Click Show how to choose these in the tool for starting recipes per platform. The points that matter most:
Grid resolution and smoothing sigma are one setting. Sigma is measured in grid pixels, and a pixel is extent / grid resolution, so the physical smoothing radius is sigma × extent / grid resolution. Doubling the grid halves the real smoothing. If you change the grid alone, the tool reports the new smoothing radius in spot spacings and which sigma would restore it. Raising the grid to sharpen a blurry map removes smoothing; it does not add resolution.
Everything is judged in spot spacings. Below about 1 spot spacing the filter never reaches the neighboring spot and the bands speckle. Above about 6 it spans a whole zone and neighboring tissues merge. The prefilled values aim for about 2.
| Data | Starting point |
|---|---|
| Visium (55 µm spots, 2,000 to 5,000 spots) | The prefilled grid and sigma, 3 levels, cutoff at the top band. |
| Visium HD, or data binned to a fine grid | The prefilled grid; raise sigma with it so the smoothing still reaches about 2 spot spacings. |
| Xenium or other single-cell resolution | Spacing is irregular, so trust the radius the tool reports rather than sigma itself. |
| Several sections on one slide | Set the section column. |
Bands are equal-width, not equal-count. Thresholds are spaced evenly between zero and the field's maximum. A program high in one corner of the tissue gives a skewed field, so the top band holds few spots. That is the shape of the field, not weak expression.
Log transform and the percentile clip overlap. Each gene is already clipped at its 99th percentile, so a single hot spot is handled without the log. Use the log when the bulk of the distribution is multiplicative, which is the case for raw counts. The tool reads the detected scale of .X (see Expression scale detection) and warns when Log transform is off on raw counts, on for an already-logged matrix, or on for z-scored values, where log1p of a negative number is undefined.
Choosing cutoffs¶
The cutoff is where the tissue call happens: everything before it is a continuous field. The review step shows the spot count for each choice and warns when a cutoff selects no spots, or more than half of them (a set that is high almost everywhere wins conflicts by size rather than signal), and when two sets overlap so broadly that most labels would come from the neighbor vote rather than the contours you are reviewing.
What it writes¶
| Where | What |
|---|---|
obs['<column name>'] (one set) |
Ordered categorical; values are band thresholds, 0 for the lowest band. |
obs['tissue'] (several sets, or your name) |
Categorical: one category per gene set, plus unassigned. |
obs['<name>_status'] |
With Save QC columns: single, resolved or unassigned. |
obs['<set>_high'] |
With Save QC columns: high or low per gene set. |
Tips and pitfalls¶
Several gene sets need PCA
The fused annotation needs X_pca for the neighbor vote. Run Analyze → Cells → PCA first; the tool refuses otherwise.
Sections without a section column
Without a section column the grid spans the gap between sections and expression bleeds across it. With one, interpolation and smoothing run per section, the vote only uses neighbors in the same section, and normalization and band thresholds stay global so bands mean the same thing in every section.
Profile k and the spatial graph
Only a spot's spatial neighbors can vote. With a 6-neighbor spatial graph from Spatial Neighbors, at most six spots vote, so a Profile k above 6 changes nothing. A large Profile k on a wider graph reaches past the local neighborhood and votes for whatever is regionally dominant.
Do not compare thresholds between runs
The field's maximum is computed per run, so the same threshold value means different things in two runs. Do not choose cutoffs by which map looks cleanest: a clean map is also what you get when a set is high nearly everywhere.
A small gene set is one gene's map
The tool warns before the run when a gene set is small enough that its score is essentially a single gene's spatial pattern.
Predicted coordinates
A single gene set contours over whichever array is chosen as the dataset's coordinates, including a Localize map. The multi-set path currently reads .obsm['spatial'] or .obsm['X_spatial'] only.
Related¶
- Spatial neighbors and autocorrelation
- Sections and territories
- Gene sets
- Labels and annotations (rename or merge the resulting categories)