Sections and territories¶
Two tools let you draw on the spatial plot and turn the drawing into cell annotations. Define Sections labels separate tissue sections that share one coordinate space, so spatial analyses can keep them apart. Define Territories draws named anatomical regions (proximal and distal, anterior and posterior) whose boundaries are saved with the dataset, and Assign Territories labels cells by the region they sit in.
Where to find it
Analyze → Spatial → Define Sections → Open Define Sections…
Analyze → Spatial → Define Territories → Open Territory tool…
Analyze → Spatial → Assign Territories → Open Assign Territories…
Define Sections¶
Define Sections opens a small floating panel that does not block the plot, so you can pan and draw while it is open.
Run it¶
- Open Analyze → Spatial → Define Sections → Open Define Sections….
- Type a Section column name (default
section) and click Start defining. The view switches to thespatialembedding if there is one and the polygon selection tool is armed. - Click points on the plot to enclose one section. The panel shows how many cells are selected.
- Type a Region name (for example
section_1) and click Add region, or press Enter. - Repeat for each section. Re-arm tool clears the selection and arms the polygon tool again.
- Click Finish. The cells are colored by the new column.
What it writes¶
| Where | What |
|---|---|
obs['section'] (or your name) |
Categorical column of section labels. Cells you did not enclose are unassigned. |
A cell enclosed by two polygons takes the label added last. Cells left unassigned count as one more section when the column is used as a Section column, so enclose every cell that belongs to a section.
Define Sections keeps only the labels. The polygon is discarded, so it cannot be edited or re-applied later. For boundaries that travel with the data, use territories.
Working with multi-section data¶
Several sections can sit side by side in one coordinate space, for example after File → Combine datasets… on spatial inputs (see Combine datasets) or in the bundled toy_spatial_3sections.h5ad (three sections of a limb-bud-like tissue, 900 cells × 76 genes, with obs['section']). Euclidean distance between cells on different sections means nothing, so an analysis that treats the whole plane as one tissue couples sections across the gaps.
These tools take a Section column and keep each section separate:
| Tool | What the section column changes |
|---|---|
| Spatial Neighbors | Drops edges between sections, so the graph is block-diagonal. Spatial Autocorrelation, Smooth and Combine Neighbors, which read that graph, are corrected with it. |
| Contour | Interpolates and smooths each section on its own grid; the multi-set vote uses only same-section neighbors. Normalization and band thresholds stay global. |
| Neighborhood | No neighbor edges cross sections, and labels are shuffled only within their own section for the permutation null. |
| Ligand-Receptor | Neighborhoods and the permutation null stay within a section. |
| Localize (Reference section column) | Each query cell is assigned to one reference section and its coordinate is drawn from that section only. |
| Define Territories | Each section gets its own outer boundary and its own cuts. |
Only Contour preselects a column, choosing one named section or sample if present. Elsewhere, pick it yourself.
Expression-based analyses (PCA, Neighbors, UMAP, Leiden, differential expression, gene clustering) do not use coordinates, so section gaps do not affect them. Batch effects between sections are a separate question.
Define Territories¶
How it works¶
You draw the cuts that divide the tissue. Skopia derives the regions between them. Because a boundary is a single cut referenced by both of its neighbors, neighboring territories share the boundary exactly: two territories cannot overlap and cannot leave a gap, since the representation cannot express either. Move a cut and both neighbors follow.
- Cuts. Each cut is a freehand curve drawn with the smooth-curve draw tool. An open cut's ends are extended along their own direction until they meet the section's boundary, so a cut that stops short of the tissue edge still divides it. A closed loop makes an island, which is how a small region is drawn inside a larger one.
- The outer boundary of each section is a padded bounding box of that section's cells, computed when you click Start drawing and then frozen, so a later cell filter cannot shift a saved boundary.
- Names attach to points. Naming a region drops an anchor point inside it. After a cut moves, each region takes the name of whichever anchor it now contains, so labels survive editing.
- A territory is a multi-polygon. On a slide with several sections, draw
proximalonce per section and give it the same name; it stays one label.
A territory type is one axis of anatomy (for example prox-dist); each type becomes its own .obs column when assigned. A dataset can hold several types.
Run it¶
- Open Analyze → Spatial → Define Territories → Open Territory tool…. A floating panel opens.
- Enter a Territory type name (for example
prox-dist). - Set Section column if the dataset holds several sections.
- Click Start drawing. The view switches to the spatial embedding and the draw tool is armed.
- Draw a line across the tissue. The derived regions appear under the cuts, and the panel lists them under Regions. With several sections, a cut is filed against the section it was drawn across, whichever section button is highlighted.
- Type a name into each region's field. Unnamed regions stay unnamed.
- Remove a cut with its × in the Cuts list if needed.
- Click Save territories (at least one region must be named). Discard drops the draft.
Assign Territories¶
- Open Analyze → Spatial → Assign Territories → Open Assign Territories….
- Tick the territory types to assign. Each row shows the column it will write, the number of sections, and the region names; types copied from a Localize reference are marked imported.
- Optionally tick Also write a combined column (two or more types) to cross them.
- Click Assign cells.
Each cell is labeled by the region whose polygon contains it. Coordinates come from the embedding the type was drawn on, so a type imported through Localize reads the query's predicted coordinates.
What it writes¶
| Where | What |
|---|---|
uns['skopia_territories_json'] |
Every saved territory type (cuts, anchors, per-section boundary, embedding, source) as one JSON string. Written by Save territories. |
obs['territory_<type>'] |
Region name per cell. |
obs['territory_<type1>__<type2>'] |
With the combined option: values like proximal|anterior. |
Two empty states are kept distinct on purpose. A blank value means the cell has no coordinate (for example, left unplaced by Localize). unassigned means it has a coordinate and lies outside every named region. A cell is never snapped to the nearest region, because that would invent an annotation nobody drew. A cell exactly on a shared boundary goes to one of the two regions, deterministically.
Tips and pitfalls¶
Carry territories onto dissociated cells
When you localize a scRNA-seq dataset onto a spatial reference that has saved territories, Localize can import the boundaries against the predicted coordinates and assign cells in the same run. Imported types are stamped imported:<file>@<date>. See Localize.
Cells in sections you did not draw on
A section without cuts or anchors leaves its cells unassigned. On a three-section E11.5 hindlimb, drawing on one section labeled its 9,145 cells (3,233 proximal, 5,912 distal) and left the 15,027 cells of the other two sections unassigned.
Deleting an embedding deletes territories drawn on it
Removing a subset's embedding drops the territory geometry drawn on it. The .obs columns already assigned stay.
Related¶
- Spatial neighbors and autocorrelation
- Contour
- Localize
- Composition barplots (clusters by territory or by section)
- Labels and annotations