Skip to content

Fuse sparse QC/HVG scans, implicit PCA, and parallel markers - #11

Open
jwg054000 wants to merge 1 commit into
mainfrom
cursor/feat-sparse-one-pass-speed-4e58
Open

jwg054000 wants to merge 1 commit into
mainfrom
cursor/feat-sparse-one-pass-speed-4e58

Conversation

@jwg054000

Copy link
Copy Markdown
Owner

Speed up the existing H5 / H5AD / CSV cell-matrix pipeline without changing biology. No new default CLI flags. Does not depend on open PR #10 (H5 CI fixture).

What changed

  1. Fused QC + normalize + HVG stats (two CSR nnz passes)
    Pass 1: QC metrics, cell keep, gene detection counts among kept cells.
    Pass 2: gene filter + normalize_total/log1p (or skip) + per-gene mean/variance.
    Seurat / seurat_v3 ranking uses those stats (no third scan).
    Same thresholds (min_genes, max_pct_mt, min_cells=3) and the same qc_metrics.csv / filtered cells / hvg_genes.csv.

  2. Implicit scale+clip+center PCA
    The HVG matrix is no longer densified by scale_sparse before RSVD. Power-iteration randomized SVD is unchanged. n_pcs is clamped to min(requested, n_cells-1, n_hvg) so a tiny post-QC matrix (e.g. 21 cells) cannot index-OOB.

  3. Wilcoxon markers parallelized per-cluster with rayon
    Same top-N, same ranking. Deterministic (no RNG in the test). Parallel matches serial on a small matrix.

Timings

pipeline_timings.json keeps the same step names: load, qc_filter, normalize, hvg, scale, pca, knn, leiden, markers.
scale is now mean/std only; z-score + clip happen inside the PCA matmuls. Documented in PACKET.md.

Tests

cargo test (no HDF5 in this environment): 127 passed (was 115). New coverage:

  • fused path matches sequential QC / HVG numbers on the existing toy + HVG fixtures (seurat and seurat_v3)
  • PCA n_pcs clamp on a 21×15 post-QC matrix; implicit sparse PCA matches dense scaled PCA
  • parallel markers identical to serial (genes, order, scores within float tolerance)
  • packet artifacts still written

cargo test --features hdf5 was not run here (no system HDF5). CI without hdf5 is the default.

Out of scope

No Cell Ranger / possorted BAM ingest, HNSW, UMAP, GPU, rustqc vendoring, or FASTQ/piscem work.

Open in Web Open in Cursor 

Speed up the existing H5/H5AD/CSV cell-matrix path without changing
QC thresholds, HVG flavors, or packet artifacts. Two CSR nnz passes
replace separate QC, normalize, and HVG scans. PCA applies scale+clip
during sparse matmuls and clamps n_pcs so tiny post-QC matrices do
not panic. Wilcoxon markers run per-cluster on rayon.

Co-authored-by: Josh Garton <jwg054000@users.noreply.github.com>
@jwg054000
jwg054000 marked this pull request as ready for review September 3, 2026 18:39
@jwg054000

Copy link
Copy Markdown
Owner Author

Shared desk — RustPipe-SC #11

Speed lane only: fused sparse QC+HVG nnz passes, implicit-centered PCA, rayon-per-cluster Wilcoxon. H5/H5AD/CSV cell matrix unchanged. Off FASTQ / piscem / prairie-stream-agent. PRs only, never main.

Comment / review / CI here and the SC bot will pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant