Skip to content

Named subsets and the subset tree

A named subset is a saved group of cells that analyses can run on without touching the dataset's own results. It is the way to sub-cluster in Skopia: mask a population, save it under a name, and run HVG → PCA → Neighbors → UMAP → Leiden on it. Every result goes to a key suffixed with the subset's name, so X_umap and leiden for the whole dataset stay as they were. Subsets can nest, and Skopia records the hierarchy in the AnnData file.

Where to find it

Cells panel → Cell Mask → Save as subset creates one; the Subsets section of the Cells panel lists them. Scoped runs start from Analyze as usual.

Why a name matters

Without a subset, a run on masked cells would have to write somewhere. Writing over X_pca, the kNN graph, X_umap and leiden with values only for the masked cells destroys the dataset's own clustering. A named subset gives each result its own key, and because membership is stored in .obs, the subset survives a reload and travels with the file. An unsaved mask does neither.

Create a subset

  1. Select the cells and click Set Active (or Mask the others) so they are the cell mask.
  2. In the Cell Mask bar, type a name and click Save as subset.

The subset's parent is inferred: it is the smallest saved subset that contains every one of its cells. Sub-clustering a cluster of a subset therefore nests under that subset without you saying so. Skopia also records which embedding the cells were selected on.

Naming rules

The name becomes part of .obs, .obsm and .obsp keys, so it must be safe there:

  • Any run of characters other than letters, digits and _ becomes one _, and leading or trailing _ are dropped (Chondro cells! becomes Chondro_cells).
  • unassigned, nan, none and null are refused, because they are cell labels.
  • spatial, neighbors, pca, umap, leiden and hvg are refused, as is any name whose keys the dataset already uses (for example bulk when the dataset has obsp['bulk_connectivities'] or uns['bulk']): a run on the subset would write over the dataset's own data.
  • A name already used by another subset is refused.
  • A selection that covers every cell is refused; that is the dataset itself.

Run the clustering chain on a subset

  1. Make the subset the mask: Activate on its row in the Subsets list (or save the mask you have).
  2. Run Analyze → Preprocess → Highly Variable Genes, then Analyze → Cells → PCA, Neighbors, UMAP and Leiden, as for the whole dataset (Preprocess, PCA, neighbors, UMAP, Leiden).

With a saved subset active, the Analyze modal says that the run is on that subset only and that results go to keys suffixed with its name. If the mask is not saved, the modal asks for a name and saves the subset before running.

Each step defaults to the previous step's output for the subset: PCA uses the subset's HVGs, Neighbors its PCA, UMAP and Leiden its graph. The output name is filled in with the suffixed key.

Step Writes
Highly variable genes var['highly_variable__<name>'] (two underscores)
PCA obsm['X_pca_<name>'], varm['PCs_<name>'], uns['pca_<name>']
Neighbors obsp['<name>_connectivities'], obsp['<name>_distances'], uns['<name>']
UMAP obsm['X_umap_<name>']
Leiden obs['leiden_<name>']
Diffusion map obsm['X_diffmap_<name>']

Rows outside the subset are empty: NaN in X_pca_<name> and X_umap_<name>, unassigned in leiden_<name>, and no graph edges leave the subset.

Run UMAP or Leiden on a graph other than the subset's own and the graph's name is appended (leiden_<name>_<graph>). Whatever graph you pick, the output always carries the subset's name, so a subset run can never land on leiden or X_umap.

PCA Loadings and PC subsets also work on a subset: a PC subset made with a subset active is X_pca_<name>_<suffix> and is offered first by the Neighbors PC-source picker. Diffusion maps and pseudotime computed on a subset are recorded under it as well (Diffusion maps and pseudotime).

A subset's embedding hides the other cells

X_umap_<name> has coordinates only for the subset's cells, so the rest are not drawn on it. A notice over the plot says how many cells are hidden and offers Show all cells on …, and Reset Mask switches back to an embedding that shows every cell. See Cells with no coordinates.

Other analyses run with the mask set (marker genes, for example) use the active cells too, but they do not write suffixed keys.

The Subsets list

The Subsets (N) section of the Cells panel shows every saved subset as a tree: a subset nested in another is indented under it with └. Each row has the subset's name, its cell count out of the total, Activate (make it the mask; Active when it already is) and ✕ (delete). Hovering a row shows its .obs column, its parent and the embedding it was saved on.

Under each row, chips show what has been computed on the subset:

Chip Click to
HVG, kNN (information only)
An embedding (X_pca_<name>, X_umap_<name>, X_diffmap_<name>, a PC subset) show that embedding
A Leiden column color by it; its ⋯ offers Refine <parent clustering> with this…, which opens Refine with subcluster labels with the column as the source and the parent's clustering as the target
A pseudotime column (listed)
N shapes, N territories switch to the embedding they were drawn on

Delete a subset

Click ✕ on the subset's row. The confirmation offers:

  • Subset only: removes obs['subset_<name>'] and the registry entry, and keeps everything computed on the subset.
  • + results: also removes everything the subset owns, listed under the buttons before you confirm: its HVG column, PCA (with loadings and variance), graph, PC subsets, UMAPs, Leiden columns, diffusion maps and pseudotime columns. Shapes, text labels and territory types drawn on the removed embeddings go with them (a territory's .obs columns stay).
  • Cancel.

Children of a deleted subset move up to its parent, so nothing below it is lost or hidden.

A subset counts as owning a key only when that key's data covers the subset's cells alone. A dataset-wide result that happens to share the name is never deleted with the subset.

What it writes

Where What
obs['subset_<name>'] Boolean membership. In scanpy: adata[adata.obs['subset_<name>']].
uns['skopia_cell_subsets'] The registry: per subset its .obs key, creation time, parent, origin (the embedding it was saved on) and a derived record of each scoped step (the key it produced and the parameters it ran with).
Suffixed keys The results in the table under Run the clustering chain on a subset.

Renaming a subset's leiden_<name> (or pseudotime) column in the .obs manager updates the registry, so the column stays listed under its subset. A subset's own subset_<name> column can be deleted (which deletes the subset) but not renamed or converted.

The exported notebook reproduces scoped steps with Skopia's Python API, for example xa.create_cell_subset(…) and xa.run_pca(…, cell_subset='<name>'); see Analysis record and notebook export.