Repository navigation
M15b: SCTransform's vars.to.regress and the workflow's percent.mt - #21
Merged
Merged
Conversation
…rted - rcompat::linpack: R's LINPACK QR as lm() makes it (dqrdc2, tol 1e-7, limited pivoting and rank) and qr.resid() applies it (dqrrsd -> dqrsl, job 10), through OpenBLAS's dnrm2, dscal, ddot and daxpy (new FFI: daxpy, dscal); bit for bit against R's vectors, rank-deficient models included (tests/fixtures/rcompat/linpack_*.tsv.gz, validation/R/regress_vectors.R). - sctransform::regress: ScaleData's RegressOutMatrix on scale.data's clipped rows, before the centring and ScaleData's NA-to-0; SctParams::vars_to_regress; finish_full. Without it the code path is unchanged. - scio::features: Seurat's row names (make.unique, _ and | to -), the workflow's pattern "(?i)^mt-" as TRE matches it, id lists, Counts::percent_feature_set (PercentageFeatureSet). - cluster::covariates: percent.mt's definition and record, the covariates' rules (names, values read as R reads them); chain::cluster_counts_with (the covariates in memory); chain_params: --vars-to-regress, --mt-genes, --percent-mt and their TOML keys; metadata.tsv and cell_metadata.tsv carry percent.mt when asked; validate: percent.mt, the regressed column, the regression's rank and pivot, scale.data value by value. - scrust sctransform, cluster (--counts; the staged starts refuse the options) and doubletfinder (through --cluster-params/--recluster-params, --cluster-metadata, --recluster-metadata); DoubletFinder's own SCTransform never regresses. - Loaders: percent.mt typed as a double; their not-rebuilt lists; tests. - Validation: the R reference runs' options (validation/R/lib/clustering.R cl_covariates, reference_clustering.R), the cases and their inputs (validation/python/m15b_cases.py, validation/m15b_cases.tsv), the saved objects' percent.mt export (validation/R/export_percent_mt.R), sbatch wrappers, cargo tests and fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rder, the checks' scripts - [clustering.floor.kernel_regressed] (validation/tolerances.toml): R against R across OpenBLAS kernels with SCTransform's vars.to.regress, measured on M15b's 134 cases in both directions with the grader's statistics (validation/python/m15b_floor.py ports scio::grade::stats), each bound the maximum rounded up, as [clustering.floor.kernel] was derived. scrust validate cluster grades against it only when both runs record the same non-empty vars.to.regress (validate::floor_for); every other comparison, the saved object's included, keeps [clustering.floor.kernel]. Reports name the floor. Tests: crates/cluster/tests/m15b_floor.rs. - The validator: percent.mt's features are compared only when both runs define them the same way (R's pattern against scrust's list of features without counts is n/a; the column is compared). - The Seurat loader adds percent.mt with the RNA assay, before the SCT assay's columns, where the workflow's objects hold it. - compare_runs.py --nested-summaries: a nested summary.json's size and digest in its parent's manifest set aside (the file holds timings; it is compared as JSON itself). - The checks' scripts: validation runs, re-validation, percent.mt against the saved objects and how the DoubletFinder objects made theirs (the SCT assay), the defaults against M15's runs, scrust doubletfinder with the options, the loaders' tests, the manifest's section. - The benchmark's tool cluster_regress (the workflow's scripts at 8d34de1^, with vars.to.regress = "percent.mt"; variants n, x and b, the same binary without the regression). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- [clustering.K14] (validation/tolerances.toml): exact against R's run of the same profile on all 134 cases in both profiles (889,756,126 values each, none differing); across kernels 134 of 134 in both directions within [clustering.floor.kernel_regressed]; percent.mt against the saved objects (the 34 clustering objects identical; the DoubletFinder objects' 30 differences are the SCT assay's); the defaults (120 of 120 routes) and scrust doubletfinder with the options (20 of 20). - docs/validation/clustering_m15b.tsv (validation/python/report_m15b.py): every case's four comparisons, scrust's runs (label m15b-25fe846) validated by 390342d's binary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- docs/validation/clustering.md: M15b's outcome and its section: what was built, the regression, the options, how the checks work; the results (exact against R's run of the same profile on all 134 cases in both profiles; across kernels within [clustering.floor.kernel_regressed]; how the floor was measured and the two floors side by side; percent.mt against the saved objects, the 30 DoubletFinder objects' SCT-based column listed with R's checks; the defaults; scrust doubletfinder with the options; the loaders); the tests, findings, corrections, deviations and how to reproduce it. The benchmark's rows follow. - docs/PLAN.md: A3, A5, A5b, C1, C3 (the refused list, the commands, the outputs, C3g, C3h, C3j), C5's K14, C6's M15b row, the order and Step 2. - validation/manifest.toml: M15b's section (validation/python/m15b_manifest.py): R's 268 reference runs and their files, the inputs, the fixtures, the saved objects' percent.mt, the checks, the pinned binaries, the tests. - README.md, docs/output_manifest.md: percent.mt and the options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- docs/benchmarks.md: the chain with SCTransform's vars.to.regress on the seven tier-P clustering objects, against R's scripts as they ran with the regression (the pipeline before 8d34de1): 2.7-6.7x less CPU time at one thread (2.1-3.7x with --export), 8.8-44x less memory, 14-20x sooner at 32 threads. The regression costs Rust nothing measurable (0.98-1.01x on the same node, against the same binary without it); it raises R's peak by up to 12%. Findings and date updated. - docs/validation/clustering.md: M15b's benchmark section and outcome row. - validation/benchmark/: the findings; report.py gives the regression's cost to three decimals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The user decided (2026-11-19) that the workflow computes percent.mt on the RNA assay everywhere, with or without the regression, as scrust does; the saved objects keep the SCT assay's column. The report and the plan (C1, C3j) say so, and say why doubletfinder.R's and scdblfinder.R's call, though it comes before their own SCTransform, reads the SCT assay: their input was transformed by the scripts that built it, which left SCT its default assay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ifest check 25fe846 appended the two linpack fixtures' rows to tests/fixtures/kernels.tsv (now 3,585 bytes, sha256 e509427c...), but its one [[file]] entry, M11's, still recorded 3,294 bytes and sha256 9025993d.... The entry now records the file as it is, keeps milestone M11 and says M15b extended it; the M11 and M15b section headers say so too. validation/python/check_manifest.py checks the whole manifest, not only one milestone's section: it parses, no path twice, every entry complete and its file present, every entry's size, the SHA-256 of every committed file it lists, and with --hash <milestone> (or all) that milestone's entries' too. Before the fix it failed on exactly this entry (size and SHA-256) of 29,339 entries and 551 committed files; after it, none fails (with --hash M11). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
M15b ports SCTransform's
vars.to.regressand Seurat'sPercentageFeatureSet()(docs/PLAN.md C3j). scRust can now regress per-cell covariates out ofscale.data, as the workflow will be able to again. There is no regression by default: without the new options, every output is M15's, byte for byte.vars_to_regress_dev.scrust cluster,scrust sctransform, and the[sctransform]section ofscrust doubletfinder's--cluster-paramsand--recluster-params.--vars-to-regress <name>[,...]:percent.mt,nCount_RNA,nFeature_RNA, or a numeric column of--metadata.--mt-genes <file>: gene IDs, one per line, matched against column 1 offeatures.tsv. Blank lines and#lines are skipped.percent.mtuses the workflow's pattern"(?i)^mt-", matched on Seurat's feature names.--percent-mt: writes the column without regressing it.percent.mtis written only when asked for, so default outputs stay M15's.percent.mtwhen no feature matches the pattern is refused, and the message names--mt-genes.ScaleData→RegressOutMatrix.lm(GENE ~ vars)$qrruns once, thenqr.resid()per row, after clipping and before centring.rcompat::linpackports LINPACK'sdqrdc2(tolerance 1e-7, limited pivoting) anddqrslstatement by statement. They call the same OpenBLAS level-1 routines R calls (dnrm2,dscal,ddot,daxpy).percent.mt= the RNA counts of the mitochondrial features /nCount_RNA× 100.scale.data. Each row'sqr.residsums over all cells, in an order that depends on the kernel. The differences go beyond[clustering.floor.kernel].[clustering.floor.kernel_regressed]is R against R across kernels with the regression, measured on all 134 cases. It applies only when both runs record the same non-emptyvars.to.regress.[clustering.floor.kernel]and every unregressed grading. Exactness against R's run of the same profile stays the main criterion.percent.mtin the saved DoubletFinder objects:doubletfinder.Randscdblfinder.Rcomputed it on their input's default assay, SCT (SCT corrected counts /nCount_SCT).percent.mt. The Seurat loader adds it with the RNA metadata.validation/tolerances.tomlthe tables[clustering.K14]and[clustering.floor.kernel_regressed]and three kernel-gating keys. No existing entry changes.docs/validation/clustering.md, anddocs/validation/clustering_m15b.tsv.validation/manifest.toml.docs/benchmarks.md.docs/output_manifest.md, the README, NOTICE and the commands'--help.Results (the session's)
Main criterion, scrust against R's run of the same profile:
scale.datawas compared value by value in 130 cases.The 31 cases where the pattern finds no mitochondrial gene:
percent.mt(a rank-deficient QR). scrust reproduces it through--mt-geneswith features that have no counts.--mt-genes.Across kernels: 134 of 134 pass in both directions.
percent.mtand the regression's rank and pivot are identical.The two floors (the regressed floor's bounds are R-vs-R maxima over the 134 cases, rounded up):
percent.mtwithout the regression, against the saved objects:Without the options: 120 of 120 of M15's routes are byte-identical, on T and P in both profiles.
scrust doubletfinderwith the options, on 20 of 20 runs:scrust cluster;Benchmark (seven P objects, against the workflow's scripts with the regression):
--export) and 8.8–44× less memory, and finishes 14–20× sooner at 32 threads.Tests (the session's, at
aed8f74):cargo test --workspace316 of 316 in 47 suites, debug and release, no warnings. Loaders: R 87 and Python 14, all passing.Coordinator's verification
From a fresh clone of
m15b_devat0fc4ffd. The final commit,99add46, changes only the manifest and two check scripts, so these results stand for it. Records indata/clustering/logs/verify-m15b/.cargo test --workspace: 316 of 316 in 47 suites, debug and release, none ignored, no warnings (portable kernel).m15b_cluster.sbatch, against the session's R runs:--mt-genes.indep_m15b.py). It uses none of M15b's comparison code and reads the runs' files itself.scale.datawith rows matched by name.summary.json, which differs only in the command line, the output directory, timings, memory and the node.m15_recluster.sbatch, 20 runs).summary.jsondiffers only in timings, memory, the node, and the nested summary's digest.m15b_unchanged.sbatchflags these routes only becausesummary.jsonrecords input paths, and my clone's root differs. With the root swapped back, nothing else differs.scrust doubletfinderwith the options (m15b_recluster.sbatch, T and P, both profiles): 100 of 100 checks identical.percent.mt, read straight from the saved.rdsfiles (my own R script, not M15b's):doubletfinder.R's own call (subset(), thenPercentageFeatureSet()with no assay, so SCT) reproduces the saved column in every cell;scrust cluster --percent-mton the saved singlets).percent.mtin every cell.vars_to_regress_devat1168432):tenx2seuratrds.Randdoubletfinder.Rwere run directly, in the production R env, on10x_mousebrain(11,831 cells), regressingpercent.mtandnCount_RNA.percent.mtby the pattern, and by a gene-ID list with two IDs that aren't features.scrust cluster --counts, thenscrust doubletfinderandscrust clusteron its singlets) is identical in every value: 36.3 million pertenx2seuratrds.Rrun and 31.3 million perdoubletfinder.Rrun, includingscale.data. DoubletFinder kept the same cells.vars.to.regressis non-empty and equals the reference's. An array that floor doesn't list is graded exactly.make.unique,_→-); IDs are matched on column 1.tolerances.toml: additions only; no existing entry is removed or changed.validation/manifest.tomlat99add46parses whole withtomllib: 29,339 entries, no duplicate paths, every file present at its size, and all 10,743 M15b entries match their SHA-256.0fc4ffdone entry was stale:tests/fixtures/kernels.tsv, which M15b extended.99add46updates that entry and adds a whole-manifest check (validation/python/check_manifest.py).data/benchmarks/. All six tables are byte-identical to the shared ones.Notes
vars_to_regress_devwas merged intoversion_harmonize_devas Add vars_to_regress and mt_genes; compute percent.mt on the RNA counts in every step scRNAseq-preprocessing#15. Its scripts agree with scrust, as shown above.features.tsv's column 2, andscrust validate clustermatches R's rows by name. Seurat's row names are unique (make.unique,_→-), so on a raw 10x input with a repeated symbol (10x_mousebrainhas twoPakapgenes), the loadings-features check and the newscale.datacheck report false differences. The validation panel's inputs are exports with unique names, so it is unaffected. The cross-check above matched rows by ID. This is a follow-up.scdblfinder.Rcurrently runs scDblFinder on SCT's corrected counts, becauseas.SingleCellExperiment()makes the default assay (SCT) the main experiment. The user decided to fix this on a separate pipeline branch.🤖 Generated with Claude Code