SCT + RPCA integration evaluation#
Abstract#
trackcell implements Seurat v4 SCT + reciprocal PCA (RPCA) integration on a
single AnnData: SelectIntegrationFeatures, PrepSCTIntegration,
FindIntegrationAnchors(reduction='rpca'), and IntegrateData with Annoy
MNN anchors and sample-tree merging.
We evaluate parity on three GSE288946 10x samples (GSM8779707–709) under the same QC as the SCT benchmark (≥100 cells per gene, ≥50 genes per cell). After QC, 35,948 cells remain; integration uses 2,000 anchor features and ref seed 1448145.
Headline (ref seed 1448145, regenerated 2026-07-11): with hybrid SCT exports
(R step-1 subsampling + R residuals_hvg cache), end-to-end IntegrateData
gene correlation vs Seurat is ~0.959; stepwise with R prep + R anchors reaches
~0.959 as well. Anchor local-pair Jaccard remains the main identity gap
(~0.72 E2E, ~0.87 stepwise).
Motivation#
SCT + RPCA is the default Seurat v4 integration workflow. Users need confidence
that a Python AnnData pipeline reproduces Seurat integration features, anchor
residuals, and corrected embeddings without an R runtime — or, when R exports are
available, that each Python step is numerically sound.
This benchmark complements SCTransform v2 evaluation: the SCT suite compares against
sctransform::vst() on single samples; the RPCA suite compares against Seurat
SCTransform() inside the full integration pipeline (reference exports under
steps/rpca_benchmark/r/seed_*/).
Benchmark design#
Three tiers of comparison:
Integration SCT stepwise — per-batch native
vst()vs RSCTransform(02_sct); Rmodel_pars_fit→ Python residuals; native SCT + forced R integration feature list → prep (isolates prep formula).RPCA stepwise injection — R export at step N feeds Python step N+1 (features → prep → anchors → integrate).
End-to-end native Python —
run_sct_integration+integrate_rpca(hybrid SCT: Python + R step-1 subsampling + R scale.data overlay) vs full Seurat pipeline.
Anchor metrics use local (dataset, cell) pairs: Seurat exports batch-local
1-based indices; Python uses global 0-based indices after map_anchors_to_global.
Handoff |
Input |
Compare |
|---|---|---|
SCT per batch |
Same filtered UMI as R integration |
Native |
Prep (merged) |
Native SCT + R integration feature list |
|
03 features |
R |
|
04 prep |
R SCT + R features |
Prep residual matrix correlation |
05 anchors |
R prep matrix |
Local anchor-pair Jaccard |
06 integrate |
R prep + R anchors |
Integrated residual correlation |
Python vs Seurat summary (ref seed)#
Component |
Stepwise |
E2E |
Target |
Notes |
|---|---|---|---|---|
|
1.000 |
0.929 |
1.0 |
Stepwise injects R SCT; E2E uses hybrid native SCT |
|
1.000 |
1.000 |
~1.0 |
E2E uses R |
Anchor local-pair Jaccard |
0.868 |
0.720 |
≥0.95 |
Counts match (~39k); identity differs (Annoy / prep drift) |
|
0.959 |
0.959 |
≥0.95 |
Shared features only: 0.977 (E2E) |
SCT HVG Jaccard (per batch, median) |
0.918 native |
0.918 hybrid E2E |
≥0.95 |
R fit→Py HVG ~0.95 per batch |
Detailed tables#
Sample / merged |
Metric |
Value |
Notes |
|---|---|---|---|
GSM8779707 |
Native HVG J |
0.9182 |
native vst vs R SCTransform |
GSM8779707 |
R fit→Py HVG J |
0.9500 |
residual corr 0.994 |
GSM8779708 |
Native HVG J |
0.9133 |
native vst vs R SCTransform |
GSM8779708 |
R fit→Py HVG J |
0.9582 |
residual corr 0.993 |
GSM8779709 |
Native HVG J |
0.9255 |
native vst vs R SCTransform |
GSM8779709 |
R fit→Py HVG J |
0.9324 |
residual corr 0.991 |
merged |
Features J (native) |
0.9231 |
native SCT SelectIntegrationFeatures |
merged |
Prep corr (R features) |
0.9999 |
native SCT + forced R feature list |
Step |
Metric |
Value |
Notes |
|
|---|---|---|---|---|
03 features |
Jaccard |
1.0000 |
R SCT → Py SelectIntegrationFeatures |
|
04 prep |
Gene corr (median) |
1.0000 |
R SCT + R features → Py Prep |
|
05 anchors |
Local pair Jaccard |
0.8679 |
count ratio 1.000 |
|
06 integrate |
Gene corr (median) |
0.9595 |
R prep + R anchors → Py IntegrateData |
|
06 integrate |
Gene corr (Py anchors) |
0.9594 |
R prep + Py anchors → Py IntegrateData |
Metric |
Stepwise |
E2E |
|---|---|---|
Features Jaccard |
1.0000 |
0.9286 |
Prep gene corr |
1.0000 |
1.0000 |
Anchor local-pair Jaccard |
0.8679 |
0.7196 |
Integrate gene corr |
0.9595 |
0.9589 |
Metric |
Value |
|---|---|
SCT HVG Jaccard (median per batch) |
0.9175 |
Integration features Jaccard |
0.9286 |
Shared integration features |
1926 |
Prep gene corr (aligned columns) |
1.0000 |
Prep gene corr (shared features only) |
1.0000 |
Anchor local pair Jaccard |
0.7196 |
Integrated gene corr (aligned) |
0.9589 |
Integrated gene corr (shared features) |
0.9774 |
The generated table above includes a Python vs Seurat quick comparison (stepwise
vs E2E) when produced by scripts/run_rpca_benchmark.py --run.
Conclusions (2026-07-11)#
What is aligned#
Component |
Parity |
Notes |
|---|---|---|
|
~1.0 |
Stepwise and E2E (with R scale.data injection) |
|
~0.959 |
Stepwise 06 and E2E; meets ≥0.95 target |
|
1.0 |
Stepwise 03 |
R |
~0.95 HVG Jaccard |
Per-batch |
Anchor counts |
~1% diff E2E |
39,124 (R) vs ~38,700 (Py E2E) |
Remaining gaps#
Gap |
Magnitude |
Mitigation |
|---|---|---|
Native SCT HVG vs R (historical benchmark) |
~0.92 Jaccard |
Re-run the offline golden benchmark after SCT fitter changes |
E2E feature list vs R |
0.929 Jaccard |
Follows HVG drift; 1926/2000 genes shared |
Anchor local-pair identity |
0.72 E2E / 0.87 stepwise |
Annoy tie order; upstream prep differences in pure-native mode |
Pure-native E2E (no R exports) |
Integrate ~0.89 (pre-P2) |
Hybrid path raises to ~0.959 |
Implementation milestones#
Date |
Change |
|---|---|
2026-07-10 |
Weight formula + sparse |
2026-07-11 |
P0 hybrid E2E: |
2026-07-11 |
Split API: |
2026-07-11 |
P0 perf: vectorised chunked |
Key diagnostic findings#
Prep drives anchor identity, not the anchor algorithm. Decomposition on ref seed 1448145:
Input prep matrix Anchor J vs R
─────────────────────────────────────────
Py prep + Py features 0.61
Py prep + R features 0.60 ← features not the driver
R prep + R features 0.87 ← prep is the driver
Integrate is downstream of prep. With R prep, integrate corr ~0.959 whether anchors are R or Python (0.9595 vs 0.9594 stepwise).
Reference choice matters. Single-sample SCT exports use sctransform::vst();
integration exports use Seurat SCTransform(). Measure RPCA parity against
steps/rpca_benchmark/, not steps/sct_benchmark/.
Deployment modes#
Mode |
API |
Notes |
|---|---|---|
Pure Python (default) |
|
No runtime R dependency; deterministic backend selection |
pyglmGamPoi (optional) |
|
Requires the optional package; selected explicitly |
SCT + Harmony / BBKNN |
|
The former hybrid R-export injection mode is retained here only as a historical benchmark result. It is no longer exposed by the production API; R artifacts are read solely by the offline benchmark suite.
Project AA/A04 benchmark (2026-07-25)#
A second, independent dataset confirms the GSE288946 findings:
Project: AA/A04 — 3 × 10x PBMC-like samples
Scale: 27,129 cells × 36,912 common genes (no QC filtering)
Backend: pure Python (
v2_backend='python',n_trees_weight=50)
Metric |
Trackcell / R |
GSE288946 ref |
Notes |
|---|---|---|---|
SCT HVG Jaccard (median) |
0.939 |
0.918 |
Pure Python backend on 27k cells; no QC filtering |
|
0.933 |
0.929 |
1931/2000 genes shared |
|
0.988 |
~1.0 |
Gene correlation on 27,129 cells |
Anchor count ratio |
0.989 |
~0.99 |
8,004 (Py) vs 8,096 (R) |
SCT runtime (Py vs R) |
175s vs 320s |
— |
1.83× faster |
Phase |
Trackcell |
Seurat R |
Notes |
|---|---|---|---|
SCT (3 batches) |
174.8 s |
319.8 s |
3 × 3,000 HVG; Python 1.83× faster |
Anchor finding |
— (in RPCA) |
35.0 s |
Annoy vs exact NN comparison pending |
IntegrateData |
— (in RPCA) |
100.0 s |
Python total RPCA 1,346.9 s |
SCT + RPCA total |
1,521.7 s |
~455 s |
R faster for RPCA; total includes Python weight construction |
Result files: <benchmark-root>/SCTRPCAbench/report.json.
Memory vs parity#
Seurat RPCA parity is never traded for automatic RAM savings. After prep,
obsm['X_sct_prep'] is sufficient for integrate_rpca; dropping
uns['sct']['batch_models'][*]['scale_data'] (manually or via
release_sct_integration_cache) does not change anchor or integrate metrics.
See Batch integration (SCT + RPCA / Harmony / BBKNN) for explicit one-liners.
Regenerate#
Requires GSE288946 data under <benchmark-root>/data/ and R with
Seurat + sctransform (st conda env recommended; needs glmGamPoi).
# Full: R export + Python comparisons + docs/_generated/*.rst
python scripts/run_rpca_benchmark.py --export-r --run
# Skip slow E2E (~20 min):
python scripts/run_rpca_benchmark.py --run --skip-e2e --seeds 1448145
R-only or Python-only:
python scripts/run_rpca_benchmark.py --export-r
python scripts/run_rpca_benchmark.py --run
Implementation references#
Benchmark runner:
trackcell/benchmark/rpca/Integration SCT stepwise:
trackcell/benchmark/rpca/sct_stepwise.pySplit integration API:
trackcell/tl/integration/sct_integration.py,trackcell/tl/integration/rpca_integration.pyR export:
trackcell/benchmark/rpca/export_rpca_benchmark_r.RCLI:
scripts/run_rpca_benchmark.py