Repository navigation
[PERFORMANCE] Direct FLASH MS1 work to precursor hypotheses - #10533
Conversation
timosachsenberg
left a comment
There was a problem hiding this comment.
Reviewed d95b21c7df6f against #10532. One [P3] helper-contract question, with a reproduced behavior change, remains.
At RNAPrecursorCorrector.cpp:180, the parent is now passed directly to FLASH. #10532 first copied it and called sortByPosition(). With the same synthetic isotope envelope, reversing only the interior peaks changes the result:
sorted=1 status=corrected isotope=1 corrected_mz=1253.18
sorted=0 status=no_envelope isotope=-1 corrected_mz=1253.68
The normal NASE mzML loader sorts peaks by default, so this reproduction does not establish a failure of that normal CLI path. It concerns direct use of the helper, whose documented input only specifies acquisition order for spectra.
@poshul, is sorted m/z order an intended precondition of RNAPrecursorCorrector::correct? If it is, documenting/enforcing it would resolve the contract question; if unsorted helper input should remain supported, the removed sorting needs preserving. Please confirm whether this merits a fix or is outside the supported contract.
Focused helper reproducer
Compile with this branch's NASE helper implementation and headers:
#include "RNAPrecursorCorrector.h"
#include <OpenMS/CHEMISTRY/NASequence.h>
#include <OpenMS/CHEMISTRY/ISOTOPEDISTRIBUTION/CoarseIsotopePatternGenerator.h>
#include <OpenMS/CONCEPT/Constants.h>
#include <algorithm>
#include <iostream>
using namespace OpenMS;
int main()
{
MSSpectrum parent;
parent.setMSLevel(1);
parent.setNativeID("scan=1");
const auto formula = NASequence::fromString("ACGUACGU").getFormula();
const auto isotopes = formula.getIsotopeDistribution(CoarseIsotopePatternGenerator(8));
for (Size i = 0; i < isotopes.size(); ++i)
{
parent.emplace_back((formula.getMonoWeight() + i * Constants::C13C12_MASSDIFF_U) / 2 - Constants::PROTON_MASS_U,
isotopes[i].getIntensity() * 10000);
}
MSSpectrum child;
child.setMSLevel(2);
child.setNativeID("scan=2");
Precursor precursor;
precursor.setMZ(parent[1].getMZ());
precursor.setCharge(2);
child.getPrecursors().push_back(precursor);
for (bool sorted : {true, false})
{
MSSpectrum input = parent;
if (!sorted) std::reverse(input.begin() + 1, input.end() - 1);
MSExperiment experiment;
experiment.setSpectra({input, child});
RNAPrecursorCorrector corrector(10, 1, 5, false, 8000);
const auto result = corrector.correct(experiment)[0];
std::cout << "sorted=" << sorted << " status=" << result.status << " isotope=" << result.isotope
<< " corrected_mz=" << result.corrected_mz << '\n';
}
}Validation: the changed corrector and SpectralDeconvolution implementation were compiled for this focused test against existing supporting OpenMS build libraries. The complete FLASH/NASE test matrix was not rerun. Earlier-layer MVH/bedRMod concerns remain tracked on #10526/#10529.
Review performed with Codex.
|
Addressed in 1a92d49. Sorted parents keep the direct path; an unsorted parent is sorted in a temporary copy, preserving the original scan and arrays. The existing NASE class test compares all correction fields and corrected MS2 output against the sorted case in both ionization modes. Local validation: 11 C++/TOPP tests and 115 Python FLASH cases pass. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Change: Refactor Merge Risk: ⚪ Minimal · up to
|
2b67f60 to
b0ba101
Compare
timosachsenberg
left a comment
There was a problem hiding this comment.
Placement review. Restricting construction inside SpectralDeconvolution is a defensible layer: cropping the MS1 in the caller would lose SNR and competition evidence. Existing three-argument callers and FLASHDeconv look unaffected: the cursor write-back is equivalent and the parallel region is if(directed). My concerns are about the API shape and the evidence for the speed-up:
- API: a query setter mirroring
setTargetMasses()would fit better than a fourth-argument overload that takes an unusedPeakGroupand ignores queries for MS2 (inline). - Reproducibility: the directed result for one scan depends on which other MS2 scans share its parent. That is worth a co-batching equivalence test (inline).
- Benchmark: the 2.44× figure is historical and unpaired. The comment about profile samples creating "millions of duplicate bands" suggests profile MS1 is the real cost. Centroiding the MS1 (PeakPickerHiRes), or reusing FLASH's own peak filtering in the caller, might give a similar gain with no new library API. A paired benchmark on this branch against that alternative would settle whether the directed path is worth its complexity.
- Separable improvement: removing the
omp criticalfrom scoring benefits every FLASH user and could go in on its own.
Smaller items: a redundant audit counter, seed groups built and scored twice, and a Python test placed after the __main__ guard (inline).
Suggested split: (a) the scoring omp critical removal on its own; (b) the directed restriction, with a neutral API, a co-batching test and a paired benchmark, merged only if it beats caller-side peak reduction.
Generated by Claude Code
| /** @brief Restrict MS1 envelope construction to precursor hypotheses and their competitors. | ||
|
|
||
| The complete spectrum remains available for isotope recruitment, noise, | ||
| and harmonic checks. Candidate mass bin selection retains its global | ||
| intensity competition. An empty list uses ordinary untargeted FLASH. | ||
| Unlike setTargetMasses(), this does not prioritize or protect hypotheses. | ||
| @param[in] spec Complete parent MS1 spectrum. | ||
| @param[in] scan_number Scan number from the input spectrum. | ||
| @param[in] precursor_peak_group Precursor peak group (unused for MS1). | ||
| @param[in] precursors Selected ions sharing this parent MS1; charge zero | ||
| considers every configured charge. Reported charges are interpreted by magnitude. | ||
| */ | ||
| void performSpectrumDeconvolution(const MSSpectrum& spec, int scan_number, | ||
| const PeakGroup& precursor_peak_group, | ||
| const std::vector<Precursor>& precursors); |
There was a problem hiding this comment.
Restricting inside the library is defensible: the caller can't crop the MS1 without losing SNR, noise and other-charge evidence. The API shape doesn't fit the generic class, though:
- Unused and ignored arguments: it takes
Precursorobjects plus aprecursor_peak_groupthat is documented as unused for MS1, and the queries are silently ignored for MS2. - A second entry point: it adds an overload of the main entry point instead of a mode.
A neutral setter mirroring the existing setTargetMasses() would fit better. Something like setQueryMasses(std::vector<std::pair<double,int>> mz_charge) or mass windows, cleared after each call, plus a documented "non-protecting" semantics. Then performSpectrumDeconvolution keeps one signature, and the pyOpenMS docstring ("Deconvolve RNA envelopes…") doesn't describe a generic class as RNA-specific.
Generated by Claude Code
| int SpectralDeconvolution::getThreadCount_(Size group_count, bool directed) | ||
| { | ||
| #ifdef _OPENMP | ||
| const int maximum = omp_get_max_threads(); | ||
| return directed ? std::min(maximum, std::max(1, int(group_count / 256))) : maximum; |
There was a problem hiding this comment.
Directed mode now has its own parallel construction path and a /256 team-size heuristic, while untargeted mode stays serial. If the parallel path is equivalent (it looks deterministic, since output is packed in bin order), either enable it for everyone or drop it. Two code paths through the core loop are harder to maintain. The 256 constant has no test or benchmark behind it.
Removing the omp critical from scoring is a general FLASH improvement and could go in on its own.
Generated by Claude Code
9497528 to
3ef97b9
Compare
timosachsenberg
left a comment
There was a problem hiding this comment.
Re-review at 3ef97b9, which has the same content as 9497528 after the rebase. The rest of the stack (#10529 → #10532) is approved. This PR still has open items:
- Windows CI is red in the new competition test (inline). The fixture is borderline at the quality cutoff, so it needs an unambiguous envelope rather than a changed expectation.
- The two earlier threads are still open with no reply:
- The API shape: a 4-argument overload of the generic entry point that takes
Precursorobjects plus aPeakGroupit never uses. A query setter mirroringsetTargetMasses()would fit the class better. Throwing on non-empty MS2 queries is an improvement, but the shape remains. - The directed-only parallel construction path, with an untested
/256team-size rule. Theomp criticalremoval in scoring benefits every FLASH user and could still go in separately.
- The API shape: a 4-argument overload of the generic entry point that takes
- Evidence for the speed-up: the paired microbenchmark shows 2.3–3.4× on the two reduced fixtures and is slower on the synthetic case. It still doesn't compare against centroiding the parent MS1 (or FLASH's own peak filtering in the caller), which might give the gain without a new library API. That comparison would settle whether the directed path is worth its complexity.
Improvements since the first review:
- the co-batching equivalence test and its documentation;
- removal of the redundant
input_peakscounter; - the Python test now runs before the
__main__guard and uses a real envelope.
Generated by Claude Code
32d1499 to
f9ae3dc
Compare
f9ae3dc to
738cd25
Compare
timosachsenberg
left a comment
There was a problem hiding this comment.
Looks good to me. It adds quite some complexity. Maybe talk to the top-down guys if your modification would better fit in a subdirectory of your tool. Note that it is now possible to have include and source subfolders for top tools where you can put more specialized code. Take, for example, a look at openNuXL, where I demonstrate how this is done
… names, #10584 CHANGELOG) Only the CHANGELOG conflicted: develop consolidated its entries (#10584), this branch keeps its own next to them. NucleicAcidSearchEngine copies the two new FLASH precursor annotations (flash_precursor_parent_peaks, flash_precursor_parent_queries) to the matches of the owning model, as it does the others; the new NASEDigestion tests cover RNAPrecursorCorrector only and need no port. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
NASE batches selected ions by parent MS1 and restricts FLASH envelope construction to their hypotheses and competing explanations. Complete parent peaks remain available for isotope recruitment, SNR, noise, harmonics and global mass-bin competition; queries receive no targeting exemption. The selected confident zero-only isotope policy and signed-charge convention from #10532 are unchanged.
The generic C++/pyOpenMS API now uses
setQueryMasses(std::vector<std::pair<double,int>>)followed by the existing three-argument deconvolution call. Queries are non-protecting and consumed at call entry, including rejected non-MS1 and empty-spectrum calls. Nonfinite/nonpositive m/z values are rejected. Empty queries use ordinary FLASH. Sorted parents retain the direct path; unsorted parents are sorted in a temporary copy without rearranging the original experiment or arrays.Candidate construction uses one serial loop for both full and directed runs. The directed-only parallel loop and
/256worker heuristic are removed. Scoring uses the same configured OpenMP workers for both modes. Competition still uses the union of the batch's query and evidence intervals; the overlap regressions do not establish universal invariance across arbitrary subsets. Callers requiring identical context must use the same batch or ordinary full-MS1 deconvolution.A new benchmark of this revision compares full/directed FLASH with caller-side
PeakPickerHiRescentroiding andNLargest500/1000 filtering. It uses three warmups and 20 repetitions, one OpenMP thread, RNA averagine, 10 ppm tolerance, cosine 0.85, SNR 0.25, max mass 8800.181396484375 Da, and charge ranges 1–20 (reduced fixtures) or 1–5 (synthetic). Full/directed order alternates. Alternative timings include spectrum transformation and deconvolution; initialization, averagine and result checks are excluded.Directed/full queried decisions, candidate fields and complete queried-envelope fingerprints are exact in all repetitions. Centroiding preserves the rejected first fixture but loses the accepted monoisotope in the second fixture, and loses the synthetic envelope. Top-500/1000 filtering preserves the second fixture's monoisotopic status but changes its confidence fields and envelope evidence. Filtering is therefore not an exact substitute in these examples. These are only two reduced parents and one synthetic envelope; no universal speed-up or full-search throughput claim follows. The synthetic directed case remains slower than full FLASH. Raw settings, scripts, timings and binary hashes are preserved with the review artifacts.
Validation of this follow-up: 11 focused C++/TOPP tests passed, all four relevant class tests passed with 32 OpenMP threads, and 115 Python FLASH cases plus direct unittest execution passed. New class regressions cover query consumption after successful, rejected and empty calls, plus invalid m/z rejection. Scoped Doxygen 1.18 validation of the changed public header produced no warnings; full-project documentation was not rerun. The earlier Windows portability fix is retained, and the preceding head's Windows/macOS/Linux CI is green; CI for this follow-up must rerun.
Stacked on #10532 and inherits the shared FLASH normalization/cosine fix merged in #10543. Earlier full-suite validation and frozen historical lab comparisons are preserved; neither constitutes repeated validation of this follow-up.
Summary by CodeRabbit