Skip to content

Expression scale detection

Skopia inspects every expression matrix in a dataset (.X and each layer) and says what scale it is on: raw counts, normalized, log-normalized, z-scored and so on. Files rarely record what was done to them, and the answer decides which steps are safe to run next.

Where to find it

The Source: dropdown in the View box (bottom left of the plot), and the small i button beside it. The same label and button appear next to the layer picker in the UCell and Cell Typing dialogs.

Why it matters

Running the wrong step on the wrong scale usually fails silently:

  • Normalize Total on already-normalized data changes nothing, so it looks like it worked.
  • Log1p on a log-scale matrix applies a second log and compresses the high end.
  • Rank-based methods (UCell, the Cell Typing classifier) and NMF assume non-negative values on a per-cell monotone scale; z-scored values break them.
  • Averaging a log-scale matrix (Smooth) averages logs, which is not the log of the average.

How it works

The verdict comes from the numbers alone; nothing in the dataset is changed. Skopia samples up to 2,000 cells, reading each sampled cell's full row so its library size (row sum) is exact, and checks these signals in order:

  1. Negative values. Only centering produces them, so any negative value means scaled / z-scored. Confidence is high when per-gene means are near 0 and the median per-gene standard deviation is between 0.5 and 2.
  2. Integers. All non-negative integers means counts; only 0 and 1 means binary.
  3. Constant library sizes. normalize_total makes every cell sum to the same target. A coefficient of variation of row sums below 0.01 does not happen by chance.
  4. Constant library sizes after undoing log1p. The same check on expm1 of the values identifies scanpy's default log1p(normalize_total(...)) scale (Wolf et al. 2018).
  5. Dynamic range. Without a constant-sum signal, values that stay at or below 25 are on a log scale.

Verdicts

Verdict Condition Confidence What it means for you
raw counts Non-negative integers, max above 1, library sizes vary High; medium if the max is 2 or less Safe input for Normalize Total, HVG seurat_v3 and count models
raw counts (downsampled) Integers with constant library sizes Medium Counts downsampled to a common depth; flagged in the reasons
normalized (linear) Non-integer, every cell sums to the same total High Normalized but not logged; usually wants Log1p before clustering or DE
log-normalized Non-integer, every cell sums to the same total after undoing log1p High Scanpy's default expression scale; ready for PCA, DE and plotting
log-transformed Non-integer, max at most 25, no constant-sum signal Medium Log scale, but library sizes were never equalized, or genes were removed after normalizing
scaled / z-scored Any negative value High or medium Do not feed to methods that assume non-negative values (UCell, NMF, count models)
binary Only 0 and 1 High Presence/absence matrix
unknown scale Non-integer, max above 25, library sizes vary Low Linear scale, normalization unclear
empty No non-zero values Low Nothing to judge

log-transformed is common after gene filtering: removing genes after Normalize Total breaks the constant row sum, so a log-normalized matrix whose genes were later subset lands here rather than in log-normalized.

Read the badge

The Source: dropdown lists each matrix (.X (default) and every layer) followed by its verdict, for example log-normalized for .X and raw counts for counts, and by how dense it is. Pick a matrix there to color cells by its values. The dropdown appears even when .X is the only matrix, because the label is how you learn its scale.

Click the i next to it for the reasoning:

Section Content
Header Which matrix (adata.X or adata.layers['…']), the verdict, its confidence and a one-line note
Recorded in the file Facts, not inferences: uns['log1p'] left by scanpy's log1p on .X; Skopia's own Normalize Total, Log1p, Scale and Smooth steps that wrote this matrix; whether the counts layer was created by Skopia at load time
Inferred from the values The reasons behind the verdict, with the numbers
Evidence Range, integer-valued, has negatives, non-zero fraction, median row sum, row-sum CV, and how many cells and genes were sampled

Hover the i for a one-line summary with the confidence.

The counts layer snapshot

When a dataset loads, Skopia checks whether .X looks like raw counts. If it does and there is no counts layer yet, it copies .X into layers['counts'] before you run anything. Later steps such as Normalize Total and Log1p change .X in place, and the snapshot keeps the raw counts reachable for tools that need them and in every Source dropdown.

  • The check samples up to 50,000 stored non-zero values and requires all of them to be non-negative integers.
  • It never replaces an existing counts layer.
  • It records uns['skopia']['counts_inferred'] = True, which is why the i popover for counts says the layer was not in the original file.
  • The layer and the record are saved with an .h5ad export, so a reopened export does not snapshot again and still reports where the layer came from.

The snapshot doubles the memory .X takes. It is skipped when .X already holds non-integer values.

Where the verdict is used

Place What it does with the verdict
View box Source: Label and i popover
UCell scoring (Score with UCell… on a gene set) Label and popover beside Source layer; a red warning for a z-scored layer
Cell typing Label and popover beside the layer picker; a red warning for a z-scored layer
Preprocess → Smooth A warning when the source is on a log scale; a note recommending normalize + log1p after averaging when it is raw counts
Gene programs (NMF and meta-programs) Picks the default input transform: log1p for counts, normalized or unknown matrices; none for log-scale or binary ones; a z-scored matrix is flagged as one NMF will reject
Contour Warns when .X is raw counts with log transform off, or already log-scale with log transform on
Localize Warns when the query and reference matrices are on different scales under a transform that does not equalize them

Tips and pitfalls

A verdict is evidence, not a fact

The classifier can be fooled. Counts downsampled to a common depth, a matrix log-transformed without normalizing, or one with genes removed after normalizing all land somewhere plausible but not certain; the confidence and the reasons say so. When the popover lists something under Recorded in the file, that is a fact about the file and outranks the inference.

Check after Combine and after filtering

Combine datasets drops .uns, including scanpy's log1p record, so after a combine the verdict rests on the values alone. Check it before you normalize again.

Layers are judged separately

Each layer gets its own verdict. A dataset whose .X is log-normalized can still hold a counts layer of raw counts, and tools that take a source layer read whichever you pick.