SCTransform v2 evaluation#
Abstract#
trackcell implements Seurat-compatible SCTransform v2 (vst.flavor='v2')
with a bundled pure-Python NB offset fitter and an explicitly selectable optional
pyglmGamPoi backend, followed by kernel-smoothed dispersion regularization
and Pearson residual HVG selection. We evaluate parity against
sctransform::vst on three GSE288946 10x samples (GSM8779707–709) under
stringent QC (≥100 cells per gene, ≥50 genes per cell).
The benchmark combines:
Stepwise injection — R exports at each stage feed the next Python step; isolates ksmooth, residuals, and HVG logic from the NB fitter.
End-to-end native Python — full
vst()vs R on identical filtered matrices.Randomness control — six R
set.seedvalues per sample; Python-vs-R HVG Jaccard is compared to the R inter-seed distribution.
Across ref-seed runs on three samples (14724–15297 genes × 15297–15800 cells after QC), native HVG Jaccard median is ~0.98, R fit→Python residuals HVG Jaccard ~1.0, residual matrix correlation 1.0, and step1 θ correlation ~0.93–0.96.
Motivation#
SCT v2 is the default normalization for Seurat 4/5 single-sample workflows and
the front end of SCT + RPCA integration. Users need confidence that a Python
AnnData pipeline reproduces Seurat HVGs and residuals without an R runtime.
Trackcell has no runtime R subprocess path. The default backend is bundled pure
Python; the historical results below use the explicitly selected
pyglmGamPoi backend. Both retain Seurat-compatible uns['sct'] batch
models for integration.
Additional data point (AA/A04, 2026-07-25)#
On a second dataset of 3 × 10x samples (27,129 cells, 36,912 genes, no QC
filtering), the bundled pure Python v2_backend='python' achieves SCT HVG
Jaccard 0.939 vs Seurat R at 1.83× the speed (175s vs 320s). See
SCT + RPCA integration evaluation for the full integration benchmark.
Benchmark design#
- Data
GSE288946 — three GSM replicates, 10x gene symbols (
gene.column = 2).- Filtering (Python and R identical)
CreateSeuratObject(min.cells = 100, min.features = 50)— genes detected in fewer than 100 cells and cells with fewer than 50 genes are removed beforevst().- Tier-B subsampling
Fixed
cells_step1/genes_step1from each R export (n_cells = n_genes = 2000,set.seed(seed)) so stepwise comparisons are not confounded by subsampling RNG when injecting R step-1 parameters.- Seeds (R reference)
1448145(ref),1448146,42,123,999,2024— six independent Rvst()runs per sample for HVG stability analysis.- Stepwise protocol
Handoff
Input
Compared output
R step1 → Py ksmooth
model_pars_step1.csvmodel_pars_fit(θ, Intercept, log_umi)R fit → Py residuals
model_pars_fit.csvResidual matrix +
residual_varianceR step1 golden
step1 + R
genes_log_gmean*Full downstream through HVG
Native Python
Filtered counts only
Full
vst()vs R export- Metrics
Pearson r, median |Δ|, Spearman RV correlation, HVG Jaccard (top 3000), Inf-θ agreement count.
- Implementation notes (fixed during this evaluation)
Issue
Fix
umi[:, cells.isin(cells_step1)]column orderUse
cells.get_indexer(cells_step1)so counts align withcell_attr.loc[cells_step1]offsetScanpy
-Nvs Seurat.Nduplicate gene namesAssign R rownames by position from
ref/{sample}_genes_min_cells.txt
Results#
Sample |
Native HVG J |
R fit→Py HVG J |
θ corr (step1) |
RV Spearman |
Residual corr |
|---|---|---|---|---|---|
GSM8779707 |
0.9802 |
1.0000 |
0.959 |
1.000 |
1.000 |
GSM8779708 |
0.9512 |
1.0000 |
0.931 |
0.997 |
1.000 |
GSM8779709 |
0.9822 |
1.0000 |
0.921 |
0.999 |
1.000 |
Metric |
Value |
|---|---|
R inter-seed HVG Jaccard (median) |
0.9443 |
R inter-seed HVG Jaccard (min – max) |
0.8697 – 0.9646 |
Python vs R (ref seed) HVG Jaccard (median) |
0.9802 |
Py median within R seed min–max |
False |
Py median within R inter-seed IQR |
False |
Interpretation#
Stepwise injection.
When R model_pars_step1 is injected, Python ksmooth + residuals achieve HVG
Jaccard ≈ 1.0 — downstream trackcell code matches R given identical NB
parameters.
Native path.
With input-alignment fixes, pyglmGamPoi batch θ matches R (raw Inf θ 224/224 on
step-1 subsample; after mark_suspicious_theta 277/277). HVG Jaccard ≈ 0.99
vs R ref seed.
Randomness. R inter-seed HVG Jaccard (six seeds, three samples) has median ~0.94 (range ~0.87–0.97). Python-vs-R at the ref seed (median ~0.98) is at or above the R inter-seed envelope — remaining HVG differences are within Seurat subsampling variability, not a systematic Python bias.
Reproduction#
python scripts/run_sct_benchmark.py --export-r --run --threads 3
Outputs:
<benchmark-root>/steps/sct_benchmark/r/seed_*/GSM*/docs/source/_generated/sct_benchmark_results.jsondocs/source/_generated/sct_benchmark_table.rst
- Environment
Python 3.10–3.11, trackcell with pyglmGamPoi ≥ 0.2.1; R reference in conda
st(Seurat 4.4, sctransform, glmGamPoi).
What is not covered here#
RPCA integration (anchors, prep, integrate) — see SCT + RPCA integration evaluation.
Multi-sample merged SCT — per-sample
batch_keypath tested via unit tests; full three-sample merge benchmark is future work.