From counts to clusters¶
Beginner
20 minutes
Data: bundled toy_spatial.h5ad (1,000 cells, 76 genes, raw counts)
This tutorial takes a dataset from raw counts to annotated clusters: normalize, reduce, build a neighbor graph, embed, cluster, then find what makes each cluster different. It is the standard scanpy workflow (Wolf et al. 2018), run from menus, and every step lands in the analysis record so you can export it as code later.
The dataset is the toy tissue that loads when Skopia starts without a file. It is synthetic: 1,000 cells on a 2D section with two cell types, Mesen and Primor, and gene names that say which region expresses them (MesenAnt_3 is a gene of the anterior mesenchyme). You can therefore check whether the clusters are right.
Before you start
Launch Skopia with pixi run backend and pixi run dev (Install) and open http://localhost:5173. The header should read toy_spatial.h5ad, 1,000 cells, 76 genes. If another file is loaded, open File → Load… and pick backend/skopia/data/toy_spatial.h5ad from the Skopia folder.
1. Look at the data first¶
The plot shows X_spatial, the cells' positions in the section. Click Color next to cell_type in the Cells panel: the Primor cells fill a disc in the middle and Mesen surrounds it.
The View box at the bottom of the plot says what .X holds: raw counts here. Skopia detects the scale of every matrix and says so wherever it matters (Expression scale detection), because most of the steps below give wrong answers on the wrong scale.
2. Normalize and log-transform¶
Open Analyze. The modal has a tab per kind of operation; you will use Preprocess and Cells.
- In Preprocess, pick Normalize Total and click Run. Each cell's counts are scaled to the median total count across cells.
- Pick Log1p and click Run.
The View box now reads log-normalized.
Quality control
On real data, start with Filter Cells and Filter Genes in the same tab. Both draw histograms of the per-cell or per-gene QC metric with draggable cutoffs, so you can see what you remove before removing it (Preprocess). The toy data has no low-quality cells, so this tutorial skips filtering.
3. Highly variable genes and PCA¶
- In Preprocess, pick Highly Variable Genes and click Run. Skopia writes a boolean
.var['highly_variable']column, and the Genes panel lists it under .var columns. On this toy dataset thecell_rangerflavor keeps all 76 genes; on a whole-transcriptome dataset you would expect it to keep around 2,000. - Switch to the Cells tab, pick PCA and click Run. PCA uses the highly variable genes and writes
obsm['X_pca']. With 76 genes it reports PCA to 50 components over 76 genes.
PCA leaves the genes unscaled by default, following current single-cell practice (Heumos et al. 2023). The PCA page explains when to turn scaling on.
4. Neighbors, UMAP and Leiden¶
Still in Cells:
- Neighbors, Run. This builds a k-nearest-neighbor graph on the PCA (k = 15 by default) and stores it as
obsp['connectivities']. - UMAP, Run. UMAP (McInnes et al. 2018) lays the graph out in two dimensions as
obsm['X_umap']. - Leiden, Run with Resolution 0.5. Leiden (Traag et al. 2019) partitions the same graph. The modal reports Found 5 clusters, written to
.obs['leiden'].
Close the modal. Switch the Embedding picker in the View box to X_umap and click Color next to leiden.
Now switch the Embedding picker back to X_spatial. Each expression cluster occupies its own region of the section: clustering found the tissue's layout from expression alone, which is what the toy data was built to show.
Resolution is a choice, not a fact
Re-run Leiden at 1.0 and you get more, smaller clusters. Neither answer is wrong. Pick the resolution at which the clusters mean something you can test, and say which one you used.
5. What makes each cluster different¶
- Open Analyze → Cells → DEG. In Select .obs column choose
leiden, and tick all five groups. - Click Run Marker Genes (5). The Find Marker Genes window opens with the five groups ticked.
- Leave Genes on
highly_variable (76)and Top N genes per group at 5, and click Run.
Each group lists its top genes with the log2 fold change, the share of its cells expressing the gene (% in) and the share of all other cells (% out). Cluster 0's markers are MesenAnt_1 to MesenAnt_5: it is the anterior mesenchyme. The full ranking is stored in the dataset as markers_leiden, so changing Top N or the filters later re-selects from it without running the test again (Differential expression and markers).
Click Plot…. The Expression tab opens with the 25 markers as heatmap rows and the cells grouped by cluster.
Save as figure in the heatmap's toolbar keeps this plot, with its inputs and settings, in the dataset (The Figures tab).
6. Name the clusters and save¶
With the markers in hand, give the clusters names: expand leiden in the Cells panel and double-click a cluster's label to rename it: 0 becomes Mesen anterior, and so on (Rename a label).
Then save: File → Export…, choose .h5ad, pick a folder and click Save. The file holds everything this session wrote, including the marker ranking, the saved figure and the analysis record (Save and export).
Where next¶
- Sub-clustering a population continues from this session.
- From clicks to a notebook turns this session into a Jupyter notebook.
- The Cell typing page shows how to classify cells against a reference atlas instead of naming clusters by hand.




