Preprocess¶
The Preprocess tab of the Analyze modal takes a counts matrix to the log-normalized, gene-selected matrix that PCA, clustering and most other tools expect: quality-control metrics, cell and gene filters, normalization, the log transform, highly variable genes, and smoothing over a neighbor graph.
Where to find it
Analyze → Preprocess, then pick the operation from the dropdown.
The Analyze modal¶
The Analyze button in the top toolbar opens one modal for the scanpy-style operations. It has five tabs: Preprocess, Cells, Genes, Spatial and Multi-genome. Each tab has a dropdown of operations; picking one shows its description and its parameters, with every default taken from the shipped config.yaml or your own config file (see Configure defaults).
- Prerequisites. When an operation needs something that is not there yet, a yellow box names it ("Requires: PCA to be computed first") and Run is disabled. On the Cells tab, Neighbors needs a PCA, and UMAP, Leiden and Diffusion map need a neighbor graph unless you pick one in their kNN graph field.
- Cell mask. With a cell mask active, a banner says how many cells the run will use. The clustering chain (Highly Variable Genes, PCA, Neighbors, UMAP, Leiden, Diffusion map) asks for a subset name and writes to keys suffixed with it; see Named subsets and the subset tree.
- Run history. Below the Run button, Session History lists the last five operations with their times. The full record of every step, with its parameters and the code to reproduce it, is in the analysis record.
- Dataset size. The bottom line gives the current number of cells and genes, so you can see what a filter removed.
Long runs, progress and Cancel
The operations on this page and on PCA, neighbors, UMAP, Leiden run inside the request: Run reads Running... until the result arrives, and they cannot be cancelled. Operations that run as background tasks (in this modal: Gene Neighbors, Spatial Neighbors and Spatial Autocorrelation; the tools opened from it, such as Contour, stemFinder and CNV, have their own) turn Run into Cancel and show a progress strip under it with a message, the percent done when the task reports it, the elapsed time and an estimate of the time left. Cancel discards the result, and the dataset is not changed. The computation already under way still runs to its end on the server, so the next heavy run may wait for it.
Recommended order¶
- QC Metrics (optional): per-cell and per-gene metrics to look at before filtering.
- Filter Cells, on raw counts.
- Filter Genes, on raw counts.
- Exclude Genes, or its Mark variant that removes nothing.
- Normalize Total.
- Log1p Transform.
- Highly Variable Genes.
Then continue on the Cells tab with PCA (PCA, neighbors, UMAP, Leiden). Smooth (kNN) needs a neighbor graph, so it comes after Neighbors or Spatial Neighbors.
Why this order:
- Filter Cells and Filter Genes threshold on the sums and nonzero entries of
.X. Those numbers mean read depth and detected genes only while.Xholds counts. - Filter Cells before Exclude Genes: its % mito threshold needs the mitochondrial genes, and excluding them first makes that threshold unusable (the Exclude Genes panel warns when you tick
mt). - Exclude Genes before Normalize Total: removing genes after normalization leaves cells with unequal totals, and the expression scale check then reports
.Xas log-transformed rather than log-normalized. Mark removes nothing, so it can run at any point.
Check the scale before you transform
Normalize Total and Log1p change .X in place and do not check what .X already holds. Run on data that is already log-normalized, they give a matrix on no standard scale, and nothing errors. Check the scale badge next to the Source dropdown first (Expression scale detection).
QC Metrics¶
Computes scanpy's standard quality-control metrics (sc.pp.calculate_qc_metrics, Wolf et al. 2018) on .X and writes them to .obs and .var. Run it on counts.
| Parameter | Default | What it does |
|---|---|---|
| QC vars (boolean .var columns) | none | Boolean .var columns to compute a share of counts for, such as mt. Make one with Analyze → Genes → Add boolean column (default name mt, pattern ^mt-). |
| Add log1p columns | true |
Also writes log1p_* versions of the count columns. |
| Percent-top (optional) | blank | Comma-separated integers, such as 50,100,200,500: the share of each cell's counts in its top N genes. Blank skips these columns. |
| Where | What |
|---|---|
obs['n_genes_by_counts'], obs['total_counts'] |
Genes detected and total counts per cell |
obs['total_counts_<var>'], obs['pct_counts_<var>'] |
Counts and percent of counts in each QC var (for example pct_counts_mt) |
obs['pct_counts_in_top_<N>_genes'] |
One column per Percent-top value |
var['n_cells_by_counts'], var['mean_counts'], var['pct_dropout_by_counts'], var['total_counts'] |
Per-gene metrics |
Exclude Genes¶
Removes genes from the dataset by exact name, by regular expression, or by gene type. Run removes the union of all three. Mark removes nothing and instead writes a boolean .var column that is False for exactly the genes Run would remove.
By name and by pattern¶
| Parameter | Default | What it does |
|---|---|---|
| Gene names | blank | One gene name per line, exact match. |
| Regex patterns | mouse: ^mt-, ^Gm\d+, ^Rps, ^Rpl |
Comma-separated regular expressions, matched from the start of each gene name. |
The pattern field is preset by species. When the gene names look human, it opens as ^MT-, ^ENS, ^RPS, ^RPL, ^LINC (human mitochondrial and ribosomal genes, bare Ensembl IDs left in a symbol index, and LINC RNAs) instead of the mouse list. Only the stock mouse value is replaced: a value from your config file, or one you typed, stays.
Human data indexed by Ensembl IDs
If your gene names are Ensembl IDs (ENSG...), the human preset's ^ENS matches every gene, and Run removes them all. Delete ^ENS from the field before running, or convert the names to symbols first.
By gene type¶
Below the name and pattern fields, the By gene type box lists GENCODE classes and named gene sets, each with the number of the dataset's genes it holds. Tick any of them to remove those genes too.
- Class (GENCODE biotype):
protein_coding,lncRNA,pseudogene,small_rna,ig_tr(immunoglobulin and T-cell receptor segments),other, andunannotated(names the tables do not know, such as reporters and transgenes). The classes come from shipped GENCODE tables for human and mouse (Frankish et al. 2023). Both an older and a current release are kept, so 10x names that a later release renamed still match, and a renamed gene's sets follow its current symbol. - Named sets (any class): sets that cut across classes, described when you hover them:
mt(mitochondrial genome),ribo(ribosomal proteins),mito_ribo,rrna,45S_ribo,hb(hemoglobins),histone,x_linked,y_linked,sex(Xist, Tsix and expressed Y genes),cell_cycle_sandcell_cycle_g2m(Tirosh et al. 2016),stress(dissociation-induced immediate-early genes, van den Brink et al. 2017), andpredicted(unnamed gene models such as Gm and Rik symbols). - Species. The species is guessed from the gene names and shown as a dropdown. Check it: when none of the names match the chosen table, the box says so, and every gene would count as
unannotated. - A file with its own annotation. If
.varalready has agene_classcolumn (for example from the SJD pipeline), the box reads the classes and set columns from the file instead of the GENCODE tables, and marks sets it had to compute itself as computed.
Protein-coding only ticks lncRNA, pseudogene, small_rna, ig_tr and other, plus the mt, ribo and predicted sets. Biotype alone cannot express "protein-coding only": about 2,000 mouse protein-coding genes are Gm or Rik models, and the ribosomal and mitochondrial genes are protein-coding too. It never ticks unannotated, so reporters and transgenes stay unless you tick it yourself. Clear unticks everything.
The line under the lists gives how many genes the choice removes, computed from the same mask Run uses, and what the name and pattern fields add beyond the types. For example, the stock ^Gm\d+ pattern also takes Gm2a, a protein-coding gene.
Measured
With Protein-coding only and the stock mouse patterns, on the Grosswendt demo (21,133 genes, symbols only): 20,715 names matched the mouse table, and Run removed 3,977 genes, keeping 17,156. The ^Gm\d+ pattern accounted for 123 of the removals beyond the types.
Mark instead of removing¶
Mark instead: write the kept genes to .var as takes a column name (default analysis_genes) and an overwrite box. Mark writes a boolean column that is True for the genes Run would keep. Every gene stays in the dataset and stays plottable; pick the column as the Gene Subset of Highly Variable Genes or PCA to restrict the analysis to the kept genes.
Mark never overwrites a non-boolean column, and overwrites an existing boolean column only with overwrite ticked.
What it writes¶
| Where | What |
|---|---|
| The dataset's genes | Run: the excluded genes are removed from the dataset |
var['analysis_genes'] (or your name) |
Mark: True for the genes Run would keep |
var['gene_type'], var['gene_class'] |
Mark: GENCODE type and class, written only when absent |
The analysis record lists every gene the types removed, so the exported code reproduces the run after the GENCODE tables are rebuilt.
Filter Cells¶
Removes cells by total counts, number of genes detected, or the share of counts from mitochondrial genes. A cell must pass every threshold you set; bounds are inclusive.
Three histograms sit above the inputs: total counts per cell, genes per cell, and mitochondrial counts per cell (%). Drag the red lines to set the cutoffs; the inputs below update and stay the source of truth. Dragging a line to the end of the axis clears that threshold. The line under the charts counts the cells that pass the current thresholds, with the same rule the run uses. The counts and genes charts use a log₁₀(1+x) axis by default (a checkbox turns it off). The histograms are refetched after every run, so they always show the current dataset.
± MAD (one box per chart) places both cutoffs at median ± k × MAD, where MAD is the unscaled median absolute deviation, measured on the axis as drawn: the log axis for counts and genes, linear for the percentage. This follows the QC chapter of Heumos et al. 2023. A cutoff that would fall outside the data is left unset. The box is a shortcut: it fills the same thresholds as the lines and the inputs, is not sent or recorded, and clears itself when you change a cutoff by hand.
"Mitochondrial" means a boolean .var['mt'] column when one exists, else genes whose names start with mt- in either case. The chart says which source it used. When neither applies there is no % mito chart, and a run with a % mito threshold is refused; flag the genes with Analyze → Genes → Add boolean column.
| Parameter | Default | What it does |
|---|---|---|
| Min counts / Max counts | blank | Bounds on total counts per cell |
| Min genes | 10 | Minimum genes detected (nonzero) per cell |
| Max genes | blank | Maximum genes detected per cell |
| Min % mito / Max % mito | blank | Bounds on the percent of a cell's counts from mitochondrial genes |
With a cell mask active, only the active cells are tested; cells outside the mask are kept.
Note
The exported code reproduces a % mito threshold as the same per-cell percentage over the recorded set of mitochondrial genes, since scanpy's filter_cells has no such option.
Filter Genes¶
Removes genes by total counts or by how many cells express them. The panel above the inputs shows two histograms, total counts per gene and cells expressing each gene, with draggable cutoffs and a live count of the genes that pass.
| Parameter | Default | What it does |
|---|---|---|
| Min counts / Max counts | blank | Bounds on a gene's total counts |
| Min cells | 0.1% | Drop a gene unless at least this share of cells express it |
| Max cells | blank | Maximum number of cells expressing the gene |
Min cells is a share of the dataset, so the same setting means the same thing on 2,000 cells and on 200,000: 0.1% keeps a gene present in one cell per thousand. The count it works out to is shown beside the field. That count is what scanpy receives and what the analysis record and the exported code carry. The cells histogram is drawn in cells, and a dragged cutoff converts with the same rounding.
Tip
To change the Min cells default in your config file, set scanpy.filter_genes.min_cells_pct (a percentage). The key min_cells is not read by this field.
Normalize Total¶
Scales each cell's counts to the same total (sc.pp.normalize_total), so cells sequenced to different depths become comparable.
| Parameter | Default | What it does |
|---|---|---|
| Target sum | blank (median) | Counts each cell is scaled to. Blank uses the median total count across cells, scanpy's own default, which keeps values on the dataset's scale. Type 10000 for counts per 10,000. |
.X is changed in place. With a cell mask active, only the active cells are scaled.
Log1p Transform¶
Applies log(x + 1) to .X. It has no parameters. Run it once, after Normalize Total.
Transform the whole dataset
Run Normalize Total and Log1p with no cell mask active. Transforming only some cells leaves .X on two scales at once, and every later comparison between masked and unmasked cells is then wrong.
Highly Variable Genes¶
Flags the genes whose variance across cells is high for their mean expression (sc.pp.highly_variable_genes), so that PCA and clustering work on the genes that carry structure.
| Parameter | Default | What it does |
|---|---|---|
| Top N genes | 2000 | Number of genes to flag. When set, it replaces the mean and dispersion thresholds. |
| Min mean | 0.0125 | Minimum mean expression (thresholds apply when Top N genes is blank) |
| Max mean | 6 | Maximum mean expression |
| Min dispersion | 0.5 | Minimum normalized dispersion |
| Method | cell_ranger |
seurat (Satija et al. 2015), cell_ranger (Zheng et al. 2017) or seurat_v3 (Stuart et al. 2019) |
| Gene Subset | none | Boolean .var columns. Detection runs on those genes alone; see below. |
| Detect within groups of | none | A categorical .obs column. Detection runs inside each group; see below. |
| Add union column | false |
With groups: also write the genes variable in any group |
| Add intersection column | false |
With groups: also write the genes variable in every group |
| Min cells per group | 10 | With groups: smaller groups are skipped and named in the result |
Preview¶
The preview plots mean expression against normalized dispersion for every gene, with the genes the current settings select in color. It recomputes 400 ms after your last edit, and draws the mean and dispersion cutoffs when they apply (no Top N genes, and not seurat_v3). The flags come from the run's own scanpy call on the cells the run would use, with nothing written, so the preview and the run agree. On the Grosswendt demo (700 cells, 21,133 genes, median-normalized and log1p, seurat, no Top N, min dispersion 1) both flagged 1,287 genes.
Genes with no dispersion are left off the plot and counted. cell_ranger can give a gene an infinite normalized dispersion (a bin with zero MAD); those genes are drawn as triangles at the top edge. With Detect within groups of set there is no single selection to preview, and the panel says so.
Gene Subset¶
Pick one or more boolean .var columns, such as the analysis_genes column that Exclude Genes → Mark writes. With two or more, choose AND (intersection) or OR (union). Only these genes compete for Top N genes and fill the dispersion bins; every other gene is written as not variable. The subset applies on the whole dataset, on a cell subset, and within each group of a split run, and the preview uses the same genes.
On the Grosswendt demo (700 cells, normalized and log-transformed, cell_ranger, Top N 2,000) after a Protein-coding only Mark, the run flagged 2,000 genes, none outside the 17,156 in analysis_genes.
Detect within groups of¶
Pooled detection on a multi-sample dataset finds genes that vary between samples as readily as genes that vary within them, so a batch effect scores as biology. Point Detect within groups of at a categorical column (sample, section, donor) and detection runs inside each group separately, writing one column per group.
The pooled highly_variable column is never changed by a split run, since every gene-subset picker in Skopia points at that name. On three E11.5 hindlimb sections with 4,000 HVGs each, the union held 7,530 genes and the intersection 1,030: a quarter of each section's variable genes were variable in all three. The intersection is the conservative input for multi-sample work such as NMF meta-programs; the union is the inclusive one.
What it writes¶
| Where | What |
|---|---|
var['highly_variable'] |
True for the flagged genes, next to scanpy's per-gene statistics for the method (for seurat and cell_ranger: means, dispersions, dispersions_norm) |
var['highly_variable__<group>'] |
A split run: one column per group |
var['highly_variable__union'], var['highly_variable__intersection'] |
A split run with the union or intersection option |
var['highly_variable__<subset>'] |
A run on a named subset; the pooled column is left as it is |
Tips and pitfalls¶
cell_ranger on an unfiltered dataset
When thousands of genes share a mean of zero, scanpy cannot bin them for cell_ranger, and the run fails. The preview says to run Filter Genes first or switch to seurat.
seurat_v3 expects counts
seurat_v3 models raw counts, and Skopia passes it .X as it is. Use it before Normalize Total and Log1p, or use seurat or cell_ranger on log-normalized data.
Smooth (kNN)¶
Averages each cell's expression with its neighbors' over a cell-cell graph and writes the result to a layer. .X is not changed. One step is S ← D⁻¹(A + αI)X, where A is the graph's connectivities, α the self-loop weight and D the row sums; more steps repeat it. Use the smoothed layer as the Source matrix of Gene PCA, Gene Neighbors or Cluster Genes, or as a Localize reference (Localize).
| Parameter | Default | What it does |
|---|---|---|
| kNN graph | none (pick one) | The graph to smooth over: Spatial Neighbors, Neighbors or a Combine Neighbors result |
| Source matrix | .X |
The matrix to smooth. Each layer is labeled with its detected scale. |
| Output layer | smoothed |
Layer to write; an existing layer of that name is overwritten |
| Steps | 1 | Smoothing iterations. More steps reach farther neighbors and smooth more. |
| Self-loop weight | 1.0 | α. 0 is a pure neighbor average; 1 weights the cell like each neighbor; larger values smooth less. |
| After averaging | none |
none keeps the source scale; cp10k normalizes each cell to 10,000; lognorm normalizes, then applies log1p (recommended when the source is counts) |
Which matrix to smooth¶
Averaging does not commute with the log: the mean of logs is not the log of the mean. Smoothing a log-normalized matrix keeps the ordering of values but not their meaning as log expression. On E11.5 limb spatial data, a smoothed log layer sat 70 to 83% below log1p of the smoothed expression, the gap widening with expression level. Normalize Total and Log1p can only write .X, so After averaging applies that transform to the layer in one step: smooth a counts layer and set it to lognorm.
The recommendation rests on held-out molecular cross-validation (Batson and Royer 2019): thin the counts, smooth one half, and score the other by Poisson deviance. On 25,934 spots × 2,000 genes with a spatial graph built from coordinates alone, smoothing counts and normalizing afterward scored best at every setting tested, with a margin over smoothing log values of 0.6% at k = 10 with 1 step and 3.1% at k = 20 with 2 steps. On the lowest-expressed third of genes, smoothing log values was marginally better.
The modal reads the scale of the source matrix and says which case you are in: a warning with these numbers when it is on a log scale, a note when it is counts with After averaging left at none, and a confirmation when it is counts with lognorm.
| Where | What |
|---|---|
layers['smoothed'] (or your name) |
The smoothed matrix. The step, including the transform, is in the analysis record, which is how the scale badge knows what the layer holds. |
Related¶
- PCA, neighbors, UMAP, Leiden: the next steps
- Expression scale detection: what
.Xand each layer hold - Named subsets and the subset tree: running the chain on part of the dataset
- Gene programs and modules: uses the HVG columns and smoothed layers
- Configure defaults: change any default on this page
- Analysis record and notebook export