Sub-clustering a population¶
Intermediate
10 minutes
Data: bundled toy_spatial.h5ad, after From counts to clusters
Clusters of a whole dataset are shaped by its largest differences. To see the structure inside one population, re-run the clustering on that population alone: new highly variable genes, a new PCA, a new graph. Skopia does this with a named subset, which keeps every result of the sub-analysis under keys of its own, so the dataset's leiden, X_pca and X_umap are never overwritten (Named subsets and the subset tree).
This tutorial sub-clusters the Mesen cells of the toy dataset. It assumes the dataset has been through the first tutorial (normalized and log-transformed, with leiden), though only the normalization is needed.
1. Select the population and save it¶
- In the Cells panel, expand
cell_typewith ▶. It has two labels:Mesen(600 cells) andPrimor(400). - Click the label
Mesen. The header reads 600 cells selected. - Click Set Active in the selection box. The Cell Mask bar appears: 600 of 1,000 cells active.
- Type
mesenin the subset name field of the Cell Mask bar and click Save as subset.
The Subsets list now shows mesen 600 of 1,000, marked Active. Membership is stored as a boolean column, obs['subset_mesen'], so the subset survives a save and reload.
2. Re-run the chain on the subset¶
Open Analyze. With a saved subset active, every step of the clustering chain says it runs on the subset only (Subset mesen: 600 of 1,000 cells) and fills its output name with the subset's suffix.
- Preprocess → Highly Variable Genes, Run: writes
var['highly_variable__mesen']. - Cells → PCA, Run: uses those genes and writes
obsm['X_pca_mesen']. - Cells → Neighbors, Run: builds
obsp['mesen_connectivities']from that PCA. - Cells → UMAP, Run:
obsm['X_umap_mesen']. - Cells → Leiden, Run at resolution 0.5:
obs['leiden_mesen'].
You did not have to pick any inputs: each step defaults to the previous step's output for the same subset.
3. Look at the result¶
Set the Embedding picker to X_umap_mesen and click Color next to leiden_mesen.
Three points to notice:
- The notice over the plot says 400 of 1,000 cells have no coordinates in X_umap_mesen. They are not hidden by a filter; the subset's embedding has nothing for them. Show all cells on X_spatial switches to an embedding that has every cell.
leidenstill has its five clusters. Color by it to check: the sub-analysis wrote nothing over it.- The subset's row in the Cells panel now lists what was computed for it: HVG,
X_pca_mesen, kNN,X_umap_mesen,leiden_mesen. Deleting the subset (✕) offers + results, which removes these with it.
Switch to X_spatial and color by leiden_mesen to see where the three sub-clusters sit in the tissue. Click Reset Mask when you are done, to make every cell active again.
Going deeper¶
Select one of the new clusters, Set Active and save it as another subset: Skopia records it as a child of mesen, because mesen is the smallest saved subset that contains all its cells. The Subsets list shows the tree. Names that the dataset already uses as keys (spatial, pca, leiden and a few others) are refused, since a run on the subset would write over the dataset's own data (Naming rules).
When you export the analysis as a notebook, the subset and every step scoped to it replay on exactly these 600 cells: see From clicks to a notebook.

