Add sort-free Rust FDR kernels (q-values, keep-best, fused finalize) - #130
Add sort-free Rust FDR kernels (q-values, keep-best, fused finalize)#130GeorgWa wants to merge 1 commit into
Conversation
Adds an fdr module with three PyO3 functions used to accelerate the pandas-heavy FDR pipeline in alphadia/fdr/fdr.py: - fdr_q_values: parallel multi-key argsort + cumsum + reverse-cummin, an exact drop-in for get_q_values returning (order, qvalues). - fdr_keep_best: per-group arg-min over proba (sort-free). - fdr_finalize: fused sort-free finalization. Keeps the best PSM per group and assigns q-values by histogramming target/decoy counts over proba bins (cumsum + reverse running minimum), avoiding any O(N) sort or ordering array. q-values are quantized to bin resolution (1/n_bins), far below any FDR threshold. Unit tests cover argsort ordering, exact q-values, histogram q-values, and keep-best selection. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Context: the tie-break argument, and why the signature is not frozenDraft for now — this wants to be reviewed together with MannLabs/alphadia#841, which is the only consumer. Why
|
Adds
src/fdr.rswith array kernels for the FDR hot spots, mirroring the pandas implementations inalphadia/fdr/fdr.py:fdr_q_values: lexicographic argsort by (proba, decoy, tiebreak) plus the running target/decoy FDR and reverse running minimum. Parallel sort via rayon.fdr_keep_best: per-group arg-min over the score, ties broken by lowest original index.fdr_finalize: fused and sort-free — a per-group arg-min for keep-best, then a fixed-bin histogram of target/decoy counts over proba whose cumulative sums give the q-value per bin. Replaces a chain of up to four O(N log N) sorts.Motivation is the pandas multi-key sort / cumsum / groupby overhead, which dominates FDR at ~10M+ candidates.
Python side: MannLabs/alphadia#841.
🤖 Generated with Claude Code