Repository navigation
perf: OpenSwath scoring speedups, vectorization, and IM debugging controls - #8787
Conversation
…oop branch Two optimizations to cross-correlation computation in OpenSWATH scoring: 1. Cap maxdelay at 10 data points (~18-30s depending on cycle time) instead of N (full chromatogram length). Lags beyond this range are physically meaningless for coelution scoring. Reduces outer-loop iterations from ~300 to 21, changing complexity from O(N²) to O(N) per pair. 2. Rewrite calculateCrossCorrelation inner loop to be branch-free by precomputing start/end bounds instead of using if/continue. Enables compiler auto-vectorization (SSE/AVX). Co-Authored-By: Claude Opus 4.6 <[email protected]>
cf21270 to
e167c13
Compare
|
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:
📝 WalkthroughWalkthroughAdds XCORR_MAX_DELAY and weightedTriangularSum helpers; refactors many scoring routines to use Eigen/vector overloads and capped cross-correlation lag; moves StatsHelpers implementations to .cpp with explicit instantiations; updates OpenSwathWorkflow for per-run params and automatic PASEF detection; refreshes many tests/fixtures. Changes
Sequence Diagram(s)sequenceDiagram
participant Workflow as OpenSwathWorkflow
participant Maps as SWATH_Maps
participant FFParam as FeatureFinderParam_Run
participant Validator as IMValidator
participant Scoring as ScoringModule
Workflow->>Maps: inspect maps for IM/PASEF windows
Maps-->>Workflow: PASEF present? (yes/no)
alt PASEF
Workflow->>FFParam: clone per-run params
Workflow->>FFParam: apply no_IM_windowing / no_IM_calibration overrides
Workflow->>Validator: ensure transitions have precursor_im
Validator-->>Workflow: valid / error
Workflow->>Scoring: enable ion-mobility scoring
else Non-PASEF
Workflow->>Scoring: disable ion-mobility scoring
end
Workflow->>Scoring: run scoring (uses XCORR_MAX_DELAY, Eigen helpers)
Scoring-->>Workflow: scoring results
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/tests/class_tests/openms/source/MRMScoring_test.cpp (1)
239-281: No test coverage for data withN > XCORR_MAX_DELAY.All mock data uses 11-sample vectors. Since
min(10, 11) = 10, the test exercises the capped path by only one sample. A test with, say, 50-sample data would more explicitly validate that the lag is hard-capped at 10 regardless of input length, and that correlation values at lags > 10 are never computed.Would you like me to draft a test case with longer data that explicitly asserts the cap behaviour (
data.size() = 21would givemaxdelay = min(10,21) = 10⇒ still 21 elements)?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/MRMScoring_test.cpp` around lines 239 - 281, The test currently only uses 11-sample mock vectors which barely exercises the XCORR_MAX_DELAY cap; add a new unit test that constructs mock data with N > XCORR_MAX_DELAY (e.g., 21 or 50 samples), calls MRMScoring::initializeXCorrPrecursorContrastMatrix with that MockMRMFeature, then inspects mrmscore.getXCorrPrecursorContrastMatrix() to assert that the computed cross-correlation lags are capped at XCORR_MAX_DELAY (no values computed for lags > XCORR_MAX_DELAY) and that values for lags within the cap are computed; create the test alongside initializeXCorrPrecursorContrastMatrix using a distinct BOOST_AUTO_TEST_CASE name (e.g., initializeXCorrPrecursorContrastMatrix_NGreaterThanXcorrMaxDelay) and reuse fill_mock_objects2/MockMRMFeature to produce the longer vectors and the same assertions pattern as the existing test.src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp (1)
22-25:XCORR_MAX_DELAYis well-placed and consistently applied.
static constexprin the.cppfile correctly restricts visibility to this translation unit. All sevennormalizedCrossCorrelationPostcall sites applystd::min(XCORR_MAX_DELAY, static_cast<int>(...size()))consistently.One forward-looking note: the constant is currently not tunable at runtime or even at build time. If future users need a wider lag window (e.g., lower-resolution instruments with broader chromatographic peaks), this will require a recompile. Exposing it as a parameter or at minimum as a named build-time option could help — though for now the current design is the right trade-off.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 22 - 25, XCORR_MAX_DELAY is currently a compile-time-only constant limiting cross-correlation lag; make it configurable by exposing it as either (a) a runtime parameter passed into normalizedCrossCorrelationPost (and propagated from callers that call normalizedCrossCorrelationPost) or (b) a build-time option (e.g., a configurable macro or CMake option) so users can increase the lag without editing the source. Modify the definition of XCORR_MAX_DELAY to be set from the chosen configuration mechanism and update all call sites that use std::min(XCORR_MAX_DELAY, static_cast<int>(...size())) and the normalizedCrossCorrelationPost signature to accept the configurable max_delay parameter so the new value is applied consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tests/topp/ProteomicsLFQ_9_out.consensusXML`:
- Line 228: The updated ProteomicsLFQ_9_out.consensusXML contains unexplained
numeric drift in consensusElement centroid attributes (it, rt, mz) across many
entries (e.g., centroid it change on line with mz ~666.301876 in
ProteomicsLFQ_9), which likely came from regenerating the fixture with a
different binary/build or non-deterministic FP behavior; reproduce by rerunning
the LFQ/DDA test generation with the exact previous commit's binary and
environment (same shared libraries, compiler flags, and RNG seeds) to confirm
the root cause, then either revert ProteomicsLFQ_9_out.consensusXML to the
previous committed version if drift is spurious or update the test fixture with
a short note in the test metadata documenting the specific cause (binary/build
id, lib versions, or non-determinism) so only intended XCorr/OpenSWATH changes
remain in the PR.
---
Nitpick comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp`:
- Around line 22-25: XCORR_MAX_DELAY is currently a compile-time-only constant
limiting cross-correlation lag; make it configurable by exposing it as either
(a) a runtime parameter passed into normalizedCrossCorrelationPost (and
propagated from callers that call normalizedCrossCorrelationPost) or (b) a
build-time option (e.g., a configurable macro or CMake option) so users can
increase the lag without editing the source. Modify the definition of
XCORR_MAX_DELAY to be set from the chosen configuration mechanism and update all
call sites that use std::min(XCORR_MAX_DELAY, static_cast<int>(...size())) and
the normalizedCrossCorrelationPost signature to accept the configurable
max_delay parameter so the new value is applied consistently.
In `@src/tests/class_tests/openms/source/MRMScoring_test.cpp`:
- Around line 239-281: The test currently only uses 11-sample mock vectors which
barely exercises the XCORR_MAX_DELAY cap; add a new unit test that constructs
mock data with N > XCORR_MAX_DELAY (e.g., 21 or 50 samples), calls
MRMScoring::initializeXCorrPrecursorContrastMatrix with that MockMRMFeature,
then inspects mrmscore.getXCorrPrecursorContrastMatrix() to assert that the
computed cross-correlation lags are capped at XCORR_MAX_DELAY (no values
computed for lags > XCORR_MAX_DELAY) and that values for lags within the cap are
computed; create the test alongside initializeXCorrPrecursorContrastMatrix using
a distinct BOOST_AUTO_TEST_CASE name (e.g.,
initializeXCorrPrecursorContrastMatrix_NGreaterThanXcorrMaxDelay) and reuse
fill_mock_objects2/MockMRMFeature to produce the longer vectors and the same
assertions pattern as the existing test.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (17)
src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cppsrc/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cppsrc/tests/class_tests/openms/source/MRMScoring_test.cppsrc/tests/topp/FeatureFinderIdentification_5_candidates.featureXMLsrc/tests/topp/OpenSwathWorkflow_16_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_17_b_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_17_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_18_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_19_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_20_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_21_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_22_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_24_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_25_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_27_expected.featureXMLsrc/tests/topp/OpenSwathWorkflow_3_output.featureXMLsrc/tests/topp/ProteomicsLFQ_9_out.consensusXML
|
Seems to make sense however unsure if 10 will always make sense if sampling speed is really quick. Would there be a way to estimate this max delay? Will look in more detail later. |
|
I think if you have a proper peak shape it is typically +-1 scan. if not it is more random |
Replace hand-rolled numeric loops with Eigen operations in Scoring.cpp, StatsHelpers.cpp, and MRMScoring.cpp. Deprecate raw-pointer interfaces in favor of std::vector overloads. Switch cor_pearson to the more numerically stable Math::pearsonCorrelationCoefficient. Add weightedTriangularSum helper using Eigen selfadjointView for zero-copy quadratic form computation on upper-triangular matrices. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 4
♻️ Duplicate comments (16)
src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp (1)
29-37: Same size-type concern fornormalize_sumoverloads.
Please propagate the OpenMS size-type change here as well.As per coding guidelines, use OpenMS primitive types from
OpenMS/CONCEPT/Types.h(e.g.,Size,SignedSize) instead of standard types likeint,unsigned intfor STL container sizes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp` around lines 29 - 37, The two overloads of normalize_sum should use OpenMS size types instead of unsigned int: change the parameter type in normalize_sum(double x[], unsigned int n) and the backend call to detail::normalize_sum_impl to use OpenMS::Size (or the project alias Size from OpenMS/CONCEPT/Types.h), and update the vector overload to static_cast<Size>(x.size()); ensure the file includes OpenMS/CONCEPT/Types.h or the appropriate header so Size is available and call detail::normalize_sum_impl(x.data(), static_cast<Size>(x.size())).src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp (10)
785-790: Downstream of weightedTriangularSum helper.
Covered by the helper comment above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 785 - 790, The comment here is a duplicate of the helper's documentation; remove the redundant downstream comment and keep just the helper-level explanation: in MRMScoring::calcMIWeightedScore (which calls weightedTriangularSum with mi_matrix_ and normalized_library_intensity) delete the duplicate comment block so only the helper weightedTriangularSum retains the explanatory comment, leaving the function body unchanged except for removing the redundant note.
449-454: Downstream of weightedTriangularSum helper.
Covered by the helper comment above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 449 - 454, The comment duplicated the helper's documentation downstream of the weightedTriangularSum use; update MRMScoring::calcXcorrShapeWeightedScore to remove the redundant/duplicate comment and rely on the existing weightedTriangularSum documentation instead (or add a one-line pointer note). Ensure the implementation still enforces the precondition (OPENSWATH_PRECONDITION) and call to weightedTriangularSum(xcorr_matrix_max_peak_sec_, normalized_library_intensity) remains unchanged.
208-209: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 208 - 209, The call filling xcorr_precursor_contrast_matrix_ uses Scoring::normalizedCrossCorrelationPost with a max-delay argument but does not apply the same XCORR_MAX_DELAY cap logic used earlier; update this call so the delay parameter uses the identical min(XCORR_MAX_DELAY, static_cast<int>(...size())) expression (the same cap used above) for the relevant intensity vector(s) passed to Scoring::normalizedCrossCorrelationPost to ensure consistent delay capping.
265-266: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 265 - 266, The cross-correlation call at xcorr_precursor_combined_matrix_ uses std::min(XCORR_MAX_DELAY, static_cast<int>(combined_intensity[i].size())) only, duplicating the previous max-delay cap; update the delay cap to mirror the earlier logic by taking the minimum of XCORR_MAX_DELAY and the lengths of both series (combined_intensity[i].size() and combined_intensity[j].size()) before calling Scoring::normalizedCrossCorrelationPost so the delay bound respects both signals.
131-132: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 131 - 132, The call to Scoring::normalizedCrossCorrelationPost uses std::min(XCORR_MAX_DELAY, static_cast<int>(intensity[i].size())) but should use the same max-delay cap logic as earlier; change this to cap by the signal length minus one (and guard against zero length) so replace the min argument with std::max(0, std::min(XCORR_MAX_DELAY, static_cast<int>(intensity[i].size()) - 1)) (affecting normalizedCrossCorrelationPost call that sets xcorr_matrix_(i, j)) and keep the subsequent Scoring::xcorrArrayGetMaxPeak call unchanged so the delay bound matches the rest of the code.
232-233: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 232 - 233, The second call to Scoring::normalizedCrossCorrelationPost uses a different/max delay cap than the earlier call; replace the inline std::min(XCORR_MAX_DELAY, static_cast<int>(tmp_data_precursor[i].size())) expression with the same max-delay logic used above (i.e., reuse the same computed maxDelay variable or the identical std::min expression used earlier) so both normalizedCrossCorrelationPost calls use the identical delay cap; target the call that sets xcorr_precursor_contrast_matrix_(i, j) and align its max-delay argument with the earlier occurrence.
161-162: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 161 - 162, The max-delay cap passed to Scoring::normalizedCrossCorrelationPost here should use the same logic as earlier; replace the current std::min(XCORR_MAX_DELAY, static_cast<int>(intensityi[i].size())) with the same computation used above (e.g., std::min(XCORR_MAX_DELAY, static_cast<int>(intensityi[i].size()) - 1)) and ensure you guard against empty vectors (check intensityi[i].size() > 0 before subtracting) so Scoring::normalizedCrossCorrelationPost and subsequent Scoring::xcorrArrayGetMaxPeak receive the correct max-delay value.
441-446: Downstream of lower-triangle initialization concern.
Covered by the helper comment above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 441 - 446, The code sums the entire eigenView (em.sum()) but only the upper triangle contains valid data and the element count calculation is wrong; change to sum only the upper-triangular elements of xcorr_matrix_max_peak_sec_ (use the Eigen triangular view on em, e.g., triangularView<Upper>().sum()) and compute the correct element count as n*(n+1)/2 (use n*(n+1)/2 with appropriate type) before returning intensities/element_number; refer to xcorr_matrix_max_peak_sec_, em (OpenMS::eigenView), and element_number when making the fix.
301-306: Downstream of weightedTriangularSum helper.
Covered by the helper comment above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 301 - 306, The inline comment here is a duplicate of the documentation already provided on the helper weightedTriangularSum; remove the redundant comment or replace it with a single-line pointer if you want to keep context (e.g., "uses weightedTriangularSum for computation"). Update MRMScoring::calcXcorrCoelutionWeightedScore to simply enforce the OPENSWATH_PRECONDITION and return weightedTriangularSum(xcorr_matrix_max_peak_, normalized_library_intensity) without the duplicate comment to avoid noise.
183-184: Same maxdelay cap as above.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 183 - 184, Compute the max-delay once (as done in the earlier block) and reuse that variable here instead of duplicating the expression: e.g. create an int max_delay = std::min(XCORR_MAX_DELAY, static_cast<int>(intensity[i].size())) before the loop/assignment and pass max_delay to Scoring::normalizedCrossCorrelationPost when setting xcorr_precursor_matrix_; this keeps the cap logic consistent with the earlier occurrence and avoids duplicated expressions.src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h (3)
88-93: Same Doxygen@paramrequirement for RMSD overload.
Please add@param[in]tags for both parameters.As per coding guidelines, use Doxygen documentation with
@brieftag (required), followed by blank line and details; use@param[in],@param[out], or@param[in,out]for all parameters.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h` around lines 88 - 93, The Doxygen for the two RootMeanSquareDeviation overloads is missing parameter documentation and the required layout; update the comment blocks for both functions (RootMeanSquareDeviation(double x[], double y[], int n) and RootMeanSquareDeviation(const std::vector<double>& x, const std::vector<double>& y)) to use a `@brief` line, a blank line, then `@param`[in] tags for each input parameter (for the C-array overload document x, y and n; for the vector overload document x and y), following the `@param`[in]/@param[out]/@param[in,out] convention in the project guidelines.
102-107: Same Doxygen@paramrequirement for SpectralAngle overload.
Please add@param[in]tags for both parameters.As per coding guidelines, use Doxygen documentation with
@brieftag (required), followed by blank line and details; use@param[in],@param[out], or@param[in,out]for all parameters.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h` around lines 102 - 107, Add missing Doxygen parameter tags for both SpectralAngle overloads: ensure the comment for OPENSWATHALGO_DLLAPI double SpectralAngle(double x[], double y[], int n) and for OPENSWATHALGO_DLLAPI double SpectralAngle(const std::vector<double>& x, const std::vector<double>& y) uses the required `@brief` line, a blank line, then include `@param`[in] for each input parameter (e.g. `@param`[in] x, `@param`[in] y and for the C-array overload also `@param`[in] n) following the `@param`[in], `@param`[out], `@param`[in,out] conventions in the project guidelines.
134-139: Add Doxygen@paramtags for the newnormalize_sum(std::vector<double>&)overload.
Please document the in/out parameter.As per coding guidelines, use Doxygen documentation with
@brieftag (required), followed by blank line and details; use@param[in],@param[out], or@param[in,out]for all parameters.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h` around lines 134 - 139, Add Doxygen for the new overload normalize_sum(std::vector<double>& x): add a required `@brief` line, a blank line, then a short description and a `@param`[in,out] x describing that the vector is modified in-place (each element divided by the sum of the vector) and what happens for edge cases; ensure you follow the same Doxygen style used elsewhere in this header and keep the deprecated C-array overload comment intact.src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp (1)
91-109: Same size-type concern inmanhattanDist.
Please apply the same OpenMS size-type change here.As per coding guidelines, use OpenMS primitive types from
OpenMS/CONCEPT/Types.h(e.g.,Size,SignedSize) instead of standard types likeint,unsigned intfor STL container sizes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp` around lines 91 - 109, In manhattanDist, replace the raw size_t with OpenMS types: compute the iterator difference into an OpenMS::SignedSize (using std::distance into SignedSize), handle the zero/negative case early, then cast to OpenMS::Size for the Eigen::Map length; update the local variable formerly named size and any uses (itExpBeg/itExpEnd distance and Eigen::Map construction) to use these OpenMS types so the function adheres to OpenMS/CONCEPT/Types.h conventions.src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/StatsHelpers.h (1)
77-87: Same instantiation risk formanhattanDist.
Covered by the previous comment; please ensure all uses are limited to the explicitly instantiated iterator types.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/StatsHelpers.h` around lines 77 - 87, The header currently exposes a generic manhattanDist declaration (manhattanDist(Texp,...)) which can trigger unwanted template instantiations; replace that generic declaration with two explicit non-template overloads matching your extern template instantiations (i.e., declare double manhattanDist(std::vector<double>::iterator itExpBeg, std::vector<double>::iterator itExpEnd, std::vector<double>::iterator itTheo) and double manhattanDist(std::vector<double>::const_iterator itExpBeg, std::vector<double>::const_iterator itExpEnd, std::vector<double>::const_iterator itTheo)) so all calls are limited to the explicitly instantiated iterator types referenced by the extern template declarations for manhattanDist.
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp (1)
580-586: Avoid redundantnormalize_sumbeforeNormalizedManhattanDist.
The vector overload already normalizes inputs, so the precedingnormalize_sumcalls add an extra pass in a hot path. Consider removing unless you need the double-normalization behavior explicitly.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp` around lines 580 - 586, The code currently calls Scoring::normalize_sum(experimental_intensity) and Scoring::normalize_sum(library_intensity) immediately before calling Scoring::NormalizedManhattanDist, but NormalizedManhattanDist already performs normalization, causing a redundant and costly extra pass; remove the two explicit Scoring::normalize_sum calls and rely on NormalizedManhattanDist's internal normalization, while keeping calls to Scoring::RootMeanSquareDeviation and OpenMS::Math::pearsonCorrelationCoefficient unchanged (or if RMSD/correlation require normalized inputs, replace the two explicit normalizations with a single normalization step used by those functions only).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h`:
- Around line 74-79: Update the Doxygen for the vector overload
NormalizedManhattanDist(std::vector<double>& x, std::vector<double>& y) to
include parameter tags: add a blank line after the existing `@brief` and then add
`@param`[in,out] x and `@param`[in,out] y (document that inputs are
normalized/mutated via normalize_sum). Ensure the `@brief` remains first, followed
by the blank line and the `@param` lines to satisfy the documentation guidelines.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp`:
- Around line 179-191: The code narrows container sizes to int; replace the
local ints used for container lengths and index bounds with OpenMS types: use
OpenMS::Size for non-negative sizes (replace datasize) and OpenMS::SignedSize
for signed indices/offsets (replace delay, start, end, and loop counters as
needed), update any related arithmetic to use these types, and add `#include`
"OpenMS/CONCEPT/Types.h" at the top; ensure uses of std::max/std::min are
appropriately typed or cast to SignedSize to avoid ambiguous overloads and keep
existing logic in Scoring.cpp unchanged otherwise.
- Around line 18-27: The helper normalize_sum_impl currently takes a raw double*
and unsigned int n; change it to use OpenMS size types and avoid raw
pointer/size pairs by using OpenMS::Size (from OpenMS/CONCEPT/Types.h) and
preferably a std::span<double> parameter (or a reference to a container) instead
of double* + n; update the signature of normalize_sum_impl and its callers to
accept std::span<double> (or span + OpenMS::Size) and construct the Eigen::Map
from span.data() and span.size(), ensuring the function name normalize_sum_impl
is preserved and include the OpenMS Types header.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp`:
- Around line 73-90: The norm template uses std::distance and a size_t for size
which conflicts with OpenMS type guidelines; change the local `size` to an
OpenMS signed size type (e.g., OpenMS::SignedSize or OpenMS::Size as
appropriate) by including OpenMS/CONCEPT/Types.h, compute distance into that
OpenMS type, and when constructing the Eigen::Map in function norm<T> cast the
OpenMS size to Eigen::Index (or static_cast<Eigen::Index>) to ensure correct
signedness and compatibility; update uses in
norm<std::vector<double>::const_iterator> and
norm<std::vector<double>::iterator> instantiations if needed.
---
Duplicate comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp`:
- Around line 785-790: The comment here is a duplicate of the helper's
documentation; remove the redundant downstream comment and keep just the
helper-level explanation: in MRMScoring::calcMIWeightedScore (which calls
weightedTriangularSum with mi_matrix_ and normalized_library_intensity) delete
the duplicate comment block so only the helper weightedTriangularSum retains the
explanatory comment, leaving the function body unchanged except for removing the
redundant note.
- Around line 449-454: The comment duplicated the helper's documentation
downstream of the weightedTriangularSum use; update
MRMScoring::calcXcorrShapeWeightedScore to remove the redundant/duplicate
comment and rely on the existing weightedTriangularSum documentation instead (or
add a one-line pointer note). Ensure the implementation still enforces the
precondition (OPENSWATH_PRECONDITION) and call to
weightedTriangularSum(xcorr_matrix_max_peak_sec_, normalized_library_intensity)
remains unchanged.
- Around line 208-209: The call filling xcorr_precursor_contrast_matrix_ uses
Scoring::normalizedCrossCorrelationPost with a max-delay argument but does not
apply the same XCORR_MAX_DELAY cap logic used earlier; update this call so the
delay parameter uses the identical min(XCORR_MAX_DELAY,
static_cast<int>(...size())) expression (the same cap used above) for the
relevant intensity vector(s) passed to Scoring::normalizedCrossCorrelationPost
to ensure consistent delay capping.
- Around line 265-266: The cross-correlation call at
xcorr_precursor_combined_matrix_ uses std::min(XCORR_MAX_DELAY,
static_cast<int>(combined_intensity[i].size())) only, duplicating the previous
max-delay cap; update the delay cap to mirror the earlier logic by taking the
minimum of XCORR_MAX_DELAY and the lengths of both series
(combined_intensity[i].size() and combined_intensity[j].size()) before calling
Scoring::normalizedCrossCorrelationPost so the delay bound respects both
signals.
- Around line 131-132: The call to Scoring::normalizedCrossCorrelationPost uses
std::min(XCORR_MAX_DELAY, static_cast<int>(intensity[i].size())) but should use
the same max-delay cap logic as earlier; change this to cap by the signal length
minus one (and guard against zero length) so replace the min argument with
std::max(0, std::min(XCORR_MAX_DELAY, static_cast<int>(intensity[i].size()) -
1)) (affecting normalizedCrossCorrelationPost call that sets xcorr_matrix_(i,
j)) and keep the subsequent Scoring::xcorrArrayGetMaxPeak call unchanged so the
delay bound matches the rest of the code.
- Around line 232-233: The second call to
Scoring::normalizedCrossCorrelationPost uses a different/max delay cap than the
earlier call; replace the inline std::min(XCORR_MAX_DELAY,
static_cast<int>(tmp_data_precursor[i].size())) expression with the same
max-delay logic used above (i.e., reuse the same computed maxDelay variable or
the identical std::min expression used earlier) so both
normalizedCrossCorrelationPost calls use the identical delay cap; target the
call that sets xcorr_precursor_contrast_matrix_(i, j) and align its max-delay
argument with the earlier occurrence.
- Around line 161-162: The max-delay cap passed to
Scoring::normalizedCrossCorrelationPost here should use the same logic as
earlier; replace the current std::min(XCORR_MAX_DELAY,
static_cast<int>(intensityi[i].size())) with the same computation used above
(e.g., std::min(XCORR_MAX_DELAY, static_cast<int>(intensityi[i].size()) - 1))
and ensure you guard against empty vectors (check intensityi[i].size() > 0
before subtracting) so Scoring::normalizedCrossCorrelationPost and subsequent
Scoring::xcorrArrayGetMaxPeak receive the correct max-delay value.
- Around line 441-446: The code sums the entire eigenView (em.sum()) but only
the upper triangle contains valid data and the element count calculation is
wrong; change to sum only the upper-triangular elements of
xcorr_matrix_max_peak_sec_ (use the Eigen triangular view on em, e.g.,
triangularView<Upper>().sum()) and compute the correct element count as
n*(n+1)/2 (use n*(n+1)/2 with appropriate type) before returning
intensities/element_number; refer to xcorr_matrix_max_peak_sec_, em
(OpenMS::eigenView), and element_number when making the fix.
- Around line 301-306: The inline comment here is a duplicate of the
documentation already provided on the helper weightedTriangularSum; remove the
redundant comment or replace it with a single-line pointer if you want to keep
context (e.g., "uses weightedTriangularSum for computation"). Update
MRMScoring::calcXcorrCoelutionWeightedScore to simply enforce the
OPENSWATH_PRECONDITION and return weightedTriangularSum(xcorr_matrix_max_peak_,
normalized_library_intensity) without the duplicate comment to avoid noise.
- Around line 183-184: Compute the max-delay once (as done in the earlier block)
and reuse that variable here instead of duplicating the expression: e.g. create
an int max_delay = std::min(XCORR_MAX_DELAY,
static_cast<int>(intensity[i].size())) before the loop/assignment and pass
max_delay to Scoring::normalizedCrossCorrelationPost when setting
xcorr_precursor_matrix_; this keeps the cap logic consistent with the earlier
occurrence and avoids duplicated expressions.
In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h`:
- Around line 88-93: The Doxygen for the two RootMeanSquareDeviation overloads
is missing parameter documentation and the required layout; update the comment
blocks for both functions (RootMeanSquareDeviation(double x[], double y[], int
n) and RootMeanSquareDeviation(const std::vector<double>& x, const
std::vector<double>& y)) to use a `@brief` line, a blank line, then `@param`[in]
tags for each input parameter (for the C-array overload document x, y and n; for
the vector overload document x and y), following the
`@param`[in]/@param[out]/@param[in,out] convention in the project guidelines.
- Around line 102-107: Add missing Doxygen parameter tags for both SpectralAngle
overloads: ensure the comment for OPENSWATHALGO_DLLAPI double
SpectralAngle(double x[], double y[], int n) and for OPENSWATHALGO_DLLAPI double
SpectralAngle(const std::vector<double>& x, const std::vector<double>& y) uses
the required `@brief` line, a blank line, then include `@param`[in] for each input
parameter (e.g. `@param`[in] x, `@param`[in] y and for the C-array overload also
`@param`[in] n) following the `@param`[in], `@param`[out], `@param`[in,out] conventions
in the project guidelines.
- Around line 134-139: Add Doxygen for the new overload
normalize_sum(std::vector<double>& x): add a required `@brief` line, a blank line,
then a short description and a `@param`[in,out] x describing that the vector is
modified in-place (each element divided by the sum of the vector) and what
happens for edge cases; ensure you follow the same Doxygen style used elsewhere
in this header and keep the deprecated C-array overload comment intact.
In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/StatsHelpers.h`:
- Around line 77-87: The header currently exposes a generic manhattanDist
declaration (manhattanDist(Texp,...)) which can trigger unwanted template
instantiations; replace that generic declaration with two explicit non-template
overloads matching your extern template instantiations (i.e., declare double
manhattanDist(std::vector<double>::iterator itExpBeg,
std::vector<double>::iterator itExpEnd, std::vector<double>::iterator itTheo)
and double manhattanDist(std::vector<double>::const_iterator itExpBeg,
std::vector<double>::const_iterator itExpEnd,
std::vector<double>::const_iterator itTheo)) so all calls are limited to the
explicitly instantiated iterator types referenced by the extern template
declarations for manhattanDist.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp`:
- Around line 29-37: The two overloads of normalize_sum should use OpenMS size
types instead of unsigned int: change the parameter type in normalize_sum(double
x[], unsigned int n) and the backend call to detail::normalize_sum_impl to use
OpenMS::Size (or the project alias Size from OpenMS/CONCEPT/Types.h), and update
the vector overload to static_cast<Size>(x.size()); ensure the file includes
OpenMS/CONCEPT/Types.h or the appropriate header so Size is available and call
detail::normalize_sum_impl(x.data(), static_cast<Size>(x.size())).
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp`:
- Around line 91-109: In manhattanDist, replace the raw size_t with OpenMS
types: compute the iterator difference into an OpenMS::SignedSize (using
std::distance into SignedSize), handle the zero/negative case early, then cast
to OpenMS::Size for the Eigen::Map length; update the local variable formerly
named size and any uses (itExpBeg/itExpEnd distance and Eigen::Map construction)
to use these OpenMS types so the function adheres to OpenMS/CONCEPT/Types.h
conventions.
---
Nitpick comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cpp`:
- Around line 580-586: The code currently calls
Scoring::normalize_sum(experimental_intensity) and
Scoring::normalize_sum(library_intensity) immediately before calling
Scoring::NormalizedManhattanDist, but NormalizedManhattanDist already performs
normalization, causing a redundant and costly extra pass; remove the two
explicit Scoring::normalize_sum calls and rely on NormalizedManhattanDist's
internal normalization, while keeping calls to Scoring::RootMeanSquareDeviation
and OpenMS::Math::pearsonCorrelationCoefficient unchanged (or if
RMSD/correlation require normalized inputs, replace the two explicit
normalizations with a single normalization step used by those functions only).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
src/openms/source/ANALYSIS/OPENSWATH/DIAScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMScoring.cppsrc/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.hsrc/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/StatsHelpers.hsrc/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cppsrc/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cppsrc/tests/topp/OpenSwathWorkflow_17_b_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_17_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_21_output.featureXMLsrc/tests/topp/OpenSwathWorkflow_27_expected.featureXML
| [[deprecated("Use the std::vector& overload instead")]] | ||
| OPENSWATHALGO_DLLAPI double NormalizedManhattanDist(double x[], double y[], int n); | ||
|
|
||
| /// @brief Calculate the normalized Manhattan distance between two vectors (mutates inputs via normalize_sum) | ||
| OPENSWATHALGO_DLLAPI double NormalizedManhattanDist(std::vector<double>& x, std::vector<double>& y); | ||
|
|
There was a problem hiding this comment.
Add Doxygen @param tags for the new vector overload.
The new overload has only @brief. Please add @param[in,out] x and @param[in,out] y to comply with documentation guidelines.
As per coding guidelines, use Doxygen documentation with @brief tag (required), followed by blank line and details; use @param[in], @param[out], or @param[in,out] for all parameters.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openswathalgo/include/OpenMS/OPENSWATHALGO/ALGO/Scoring.h` around lines
74 - 79, Update the Doxygen for the vector overload
NormalizedManhattanDist(std::vector<double>& x, std::vector<double>& y) to
include parameter tags: add a blank line after the existing `@brief` and then add
`@param`[in,out] x and `@param`[in,out] y (document that inputs are
normalized/mutated via normalize_sum). Ensure the `@brief` remains first, followed
by the blank line and the `@param` lines to satisfy the documentation guidelines.
| namespace detail | ||
| { | ||
| // Internal helper to avoid deprecation warnings between our own functions | ||
| static void normalize_sum_impl(double* x, unsigned int n) | ||
| { | ||
| x[i] *= inverse_sum; | ||
| Eigen::Map<Eigen::VectorXd> v(x, n); | ||
| double s = v.sum(); | ||
| if (s != 0.0) { v /= s; } | ||
| } | ||
| } |
There was a problem hiding this comment.
Prefer OpenMS size types (and avoid raw pointer/size pairs if possible).
The helper takes double* with unsigned int n. Guidelines prefer OpenMS size types for container lengths and avoiding raw pointer parameters. Consider OpenMS::Size (and, if feasible, std::span<double> or similar) to bundle pointer+size.
🔧 Suggested update
+#include <OpenMS/CONCEPT/Types.h>
...
- static void normalize_sum_impl(double* x, unsigned int n)
+ static void normalize_sum_impl(double* x, OpenMS::Size n)As per coding guidelines, use OpenMS primitive types from OpenMS/CONCEPT/Types.h (e.g., Size, SignedSize) instead of standard types like int, unsigned int for STL container sizes, and avoid raw pointers; prefer references for parameters and member variables.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| namespace detail | |
| { | |
| // Internal helper to avoid deprecation warnings between our own functions | |
| static void normalize_sum_impl(double* x, unsigned int n) | |
| { | |
| x[i] *= inverse_sum; | |
| Eigen::Map<Eigen::VectorXd> v(x, n); | |
| double s = v.sum(); | |
| if (s != 0.0) { v /= s; } | |
| } | |
| } | |
| namespace detail | |
| { | |
| // Internal helper to avoid deprecation warnings between our own functions | |
| static void normalize_sum_impl(double* x, OpenMS::Size n) | |
| { | |
| Eigen::Map<Eigen::VectorXd> v(x, n); | |
| double s = v.sum(); | |
| if (s != 0.0) { v /= s; } | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp` around lines 18 -
27, The helper normalize_sum_impl currently takes a raw double* and unsigned int
n; change it to use OpenMS size types and avoid raw pointer/size pairs by using
OpenMS::Size (from OpenMS/CONCEPT/Types.h) and preferably a std::span<double>
parameter (or a reference to a container) instead of double* + n; update the
signature of normalize_sum_impl and its callers to accept std::span<double> (or
span + OpenMS::Size) and construct the Eigen::Map from span.data() and
span.size(), ensuring the function name normalize_sum_impl is preserved and
include the OpenMS Types header.
| const int datasize = static_cast<int>(data1.size()); | ||
| const double* __restrict d1 = data1.data(); | ||
| const double* __restrict d2 = data2.data(); | ||
|
|
||
| for (delay = -maxdelay; delay <= maxdelay; delay = delay + lag) | ||
| for (int delay = -maxdelay; delay <= maxdelay; delay += lag) | ||
| { | ||
| double sxy = 0; | ||
| for (i = 0; i < datasize; ++i) | ||
| const int start = std::max(0, -delay); | ||
| const int end = std::min(datasize, datasize - delay); | ||
| for (int i = start; i < end; ++i) | ||
| { | ||
| j = i + delay; | ||
| if (j < 0 || j >= datasize) | ||
| { | ||
| continue; | ||
| } | ||
| sxy += (data1[i]) * (data2[j]); | ||
| sxy += d1[i] * d2[i + delay]; | ||
| } |
There was a problem hiding this comment.
Use OpenMS size types for datasize and index bounds.
data1.size() is a container length; storing it in int risks narrowing and conflicts with the OpenMS size-type guideline.
🔧 Suggested update
- const int datasize = static_cast<int>(data1.size());
+ const OpenMS::SignedSize datasize = static_cast<OpenMS::SignedSize>(data1.size());
...
- const int start = std::max(0, -delay);
- const int end = std::min(datasize, datasize - delay);
+ const OpenMS::SignedSize start = std::max<OpenMS::SignedSize>(0, -delay);
+ const OpenMS::SignedSize end = std::min<OpenMS::SignedSize>(datasize, datasize - delay);As per coding guidelines, use OpenMS primitive types from OpenMS/CONCEPT/Types.h (e.g., Size, SignedSize) instead of standard types like int, unsigned int for STL container sizes.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const int datasize = static_cast<int>(data1.size()); | |
| const double* __restrict d1 = data1.data(); | |
| const double* __restrict d2 = data2.data(); | |
| for (delay = -maxdelay; delay <= maxdelay; delay = delay + lag) | |
| for (int delay = -maxdelay; delay <= maxdelay; delay += lag) | |
| { | |
| double sxy = 0; | |
| for (i = 0; i < datasize; ++i) | |
| const int start = std::max(0, -delay); | |
| const int end = std::min(datasize, datasize - delay); | |
| for (int i = start; i < end; ++i) | |
| { | |
| j = i + delay; | |
| if (j < 0 || j >= datasize) | |
| { | |
| continue; | |
| } | |
| sxy += (data1[i]) * (data2[j]); | |
| sxy += d1[i] * d2[i + delay]; | |
| } | |
| const OpenMS::SignedSize datasize = static_cast<OpenMS::SignedSize>(data1.size()); | |
| const double* __restrict d1 = data1.data(); | |
| const double* __restrict d2 = data2.data(); | |
| for (int delay = -maxdelay; delay <= maxdelay; delay += lag) | |
| { | |
| double sxy = 0; | |
| const OpenMS::SignedSize start = std::max<OpenMS::SignedSize>(0, -delay); | |
| const OpenMS::SignedSize end = std::min<OpenMS::SignedSize>(datasize, datasize - delay); | |
| for (int i = start; i < end; ++i) | |
| { | |
| sxy += d1[i] * d2[i + delay]; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/Scoring.cpp` around lines 179 -
191, The code narrows container sizes to int; replace the local ints used for
container lengths and index bounds with OpenMS types: use OpenMS::Size for
non-negative sizes (replace datasize) and OpenMS::SignedSize for signed
indices/offsets (replace delay, start, end, and loop counters as needed), update
any related arithmetic to use these types, and add `#include`
"OpenMS/CONCEPT/Types.h" at the top; ensure uses of std::max/std::min are
appropriately typed or cast to SignedSize to avoid ambiguous overloads and keep
existing logic in Scoring.cpp unchanged otherwise.
| // Template implementation for norm (only compiled in this .cpp file) | ||
| template <typename T> | ||
| double norm(T beg, T end) | ||
| { | ||
| if (beg == end) return 0.0; | ||
| size_t size = std::distance(beg, end); | ||
| using ValueType = typename std::iterator_traits<T>::value_type; | ||
| Eigen::Map<const Eigen::Matrix<ValueType, Eigen::Dynamic, 1>> v(&(*beg), size); | ||
| return static_cast<double>(v.norm()); | ||
| } | ||
|
|
||
| // Explicit template instantiation definitions for norm | ||
| template OPENSWATHALGO_DLLAPI double norm<std::vector<double>::const_iterator>( | ||
| std::vector<double>::const_iterator, std::vector<double>::const_iterator); | ||
|
|
||
| template OPENSWATHALGO_DLLAPI double norm<std::vector<double>::iterator>( | ||
| std::vector<double>::iterator, std::vector<double>::iterator); | ||
|
|
There was a problem hiding this comment.
Use OpenMS size types for iterator distances.
std::distance returns a signed value, and guidelines prefer OpenMS::Size/OpenMS::SignedSize for container lengths. Consider switching to a signed OpenMS type and casting to Eigen::Index when mapping.
🔧 Suggested update
+#include <OpenMS/CONCEPT/Types.h>
...
- size_t size = std::distance(beg, end);
+ const OpenMS::SignedSize size = std::distance(beg, end);
...
- Eigen::Map<const Eigen::Matrix<ValueType, Eigen::Dynamic, 1>> v(&(*beg), size);
+ Eigen::Map<const Eigen::Matrix<ValueType, Eigen::Dynamic, 1>> v(&(*beg), static_cast<Eigen::Index>(size));As per coding guidelines, use OpenMS primitive types from OpenMS/CONCEPT/Types.h (e.g., Size, SignedSize) instead of standard types like int, unsigned int for STL container sizes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp` around lines 73
- 90, The norm template uses std::distance and a size_t for size which conflicts
with OpenMS type guidelines; change the local `size` to an OpenMS signed size
type (e.g., OpenMS::SignedSize or OpenMS::Size as appropriate) by including
OpenMS/CONCEPT/Types.h, compute distance into that OpenMS type, and when
constructing the Eigen::Map in function norm<T> cast the OpenMS size to
Eigen::Index (or static_cast<Eigen::Index>) to ensure correct signedness and
compatibility; update uses in norm<std::vector<double>::const_iterator> and
norm<std::vector<double>::iterator> instantiations if needed.
|
I ran a quick test on a diaPASEF file (20200505_Evosep_200SPD_SG06-16_MLHeLa_200ng_py8_S3-A1_1_2737.mzML (1.6G)), with a library of 14,216 proteins, 146,788 compounds with 880,728 transitions, previously provided by @jcharkow. Overall seems to be ~30-40% faster, the precursor IDs are roughly the same (~500 IDs less compared to the dev branch at 1% FDR), but I don't think that's a huge issue. Interestingly though, when I first tested the I do echo @jcharkow's comment. I think for most standard DIA data, capping to max 10 data points is probably fine, but depending on the instrument / acquisition and LC gradient this could require a different cap. So it would be great if we could somehow estimate this from the data.
branch develop with pasef flag commands and logbranch feature/xcorr-speedup with pasef flag commands and logbranch feature/xcorr-speedup without pasef flag commands and log |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||
| // Template implementation for manhattanDist (only compiled in this .cpp file) | ||
| template <typename Texp, typename Ttheo> | ||
| double manhattanDist(Texp itExpBeg, Texp itExpEnd, Ttheo itTheo) |
There was a problem hiding this comment.
Hmmm I'm wondering.. I think we should restrict the function to vector iterators now or other contiguous memory iterators.
|
Thanks. Interesting observation regarding the pasef flag. Dues this result in the full im take being extracted? Instead of a im window? |
Technically yes, it would extract the full IM (the default window is set to -1), but I did explicitly set the im windows to 0.06, so it likely only extracted and scored that range of ion mobility. But with the |
|
That would explain the lower intensities |
Debugging:disable_features and IM scoring semanticsAdded a
|
| Value | Effect |
|---|---|
no_IM_calibration |
Skip ion mobility calibration by iRT peptides (forces irt_im_extraction_window = -1 so correctIM() early-returns) |
no_IM_windowing |
Extract chromatograms over the full IM range (im_extraction_window = -1 for MS1/MS2) and disable PASEF window matching (pasef = false). Does not affect IM calibration — use no_IM_calibration for that. |
These are orthogonal — each targets a distinct mechanism and can be combined freely.
Scoring:Scores:use_ion_mobility_scores (changed default)
Default changed from "false" to "auto":
| Value | Behavior |
|---|---|
auto (default) |
Automatically enabled for PASEF data, disabled otherwise |
true |
Always enabled — user intent respected regardless of data type |
false |
Always disabled — user intent respected, never auto-overridden |
Previously, the auto-enable code checked == "false" and could not distinguish "user explicitly set false" from "default is false", so explicit user intent was silently overridden for PASEF data. The three-valued parameter fixes this.
Interaction between the knobs
no_IM_windowingforcespasef = false, soautoIM scoring resolves tofalse. If you want IM scoring without PASEF windowing, explicitly set-Scoring:Scores:use_ion_mobility_scores true.no_IM_calibrationhas no effect on IM scoring or windowing.- All combinations are valid for isolating individual IM effects in benchmarks.
Bug fix: per-run state leaking
pasef and feature_finder_param are now reset/copied at the start of each run in multi-run mode, matching the existing pattern for cp_current/cp_ms1_current/cp_irt_current. Previously, auto-detection and overrides from run N could carry over into run N+1.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/topp/OpenSwathWorkflow.cpp (1)
940-957:⚠️ Potential issue | 🔴 CriticalAdd missing
pasefparameter to bothloadSwathFiles()calls.The function signature requires
const bool pasefas the 12th parameter, but both calls are missing it. At line 942,&qc_consumeris being passed in thepasefargument position; at line 957, the parameter is omitted entirely. Both calls must be updated to include thepasefvariable in the correct position before the optionalplugin_consumerparameter.Line 942 should be:
loadSwathFiles(single_file_list, exp_meta, swath_maps, swath_map_sources, split_file, tmp_dir, readoptions, swath_windows_file, min_upper_edge_dist, force, sort_swath_maps, prm, pasef, &qc_consumer)Line 957 should be:
loadSwathFiles(single_file_list, exp_meta, swath_maps, swath_map_sources, split_file, tmp_dir, readoptions, swath_windows_file, min_upper_edge_dist, force, sort_swath_maps, prm, pasef)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/topp/OpenSwathWorkflow.cpp` around lines 940 - 957, Both calls to loadSwathFiles are missing the required const bool pasef argument (the 12th parameter): update the call that currently passes &qc_consumer in the 12th position so pasef is passed before the plugin consumer (i.e. pass pasef, &qc_consumer to loadSwathFiles), and update the other call to include pasef as the 12th argument (i.e. pass pasef before the optional plugin consumer). Locate loadSwathFiles invocations in OpenSwathWorkflow::... (the two calls shown that currently pass &qc_consumer and the one without it) and insert pasef in the parameter list immediately before any plugin/consumer pointer argument.
🧹 Nitpick comments (1)
src/topp/OpenSwathWorkflow.cpp (1)
1007-1020: Prefer range-based for and consider robustness of the IM sentinel check.Two minor points:
The index-based loop can be simplified to a range-based
for, which is more idiomatic and avoids theSize kcounter.The comparison
precursor_im == -1is an exact floating-point equality against an integer literal. While-1is exactly representable in IEEE 754 and this works correctly for the sentinel value, using< 0would be more defensive against transitions that might carry other negative sentinel values.Suggested refactor
- const auto& transitions = transition_exp.getTransitions(); - for (Size k = 0; k < transitions.size(); k++) + for (const auto& tr : transition_exp.getTransitions()) { - if (transitions[k].precursor_im == -1) + if (tr.precursor_im < 0) { throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, - "Error: Transition " + transitions[k].getNativeID() + + "Error: Transition " + tr.getNativeID() + " does not have a valid IM value, this must be set to use PASEF mode (auto-detected or via -pasef flag)"); } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/topp/OpenSwathWorkflow.cpp` around lines 1007 - 1020, Replace the index-based loop over transition_exp.getTransitions() with a range-based loop (e.g. for (const auto& tr : transition_exp.getTransitions())) and change the sentinel check from exact equality to a defensive numeric test (replace tr.precursor_im == -1 with tr.precursor_im < 0) to catch any negative sentinel values; keep the thrown Exception::IllegalArgument and use tr.getNativeID() for the error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 968-986: When disable_im_windowing forces pasef to false, also
emit an informational log explaining that auto-resolution will disable
use_ion_mobility_scores unless the user overrides it; locate the block that sets
pasef = false when disable_im_windowing is true (reference variable names:
disable_im_windowing and pasef) and add an OPENMS_LOG_INFO right after where
use_ion_mobility_scores is auto-resolved (reference parameter name
use_ion_mobility_scores/Scoring:Scores:use_ion_mobility_scores) stating that IM
scoring was auto-disabled due to no_IM_windowing and instructing users to pass
-Scoring:Scores:use_ion_mobility_scores true if they want to keep IM scoring.
---
Outside diff comments:
In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 940-957: Both calls to loadSwathFiles are missing the required
const bool pasef argument (the 12th parameter): update the call that currently
passes &qc_consumer in the 12th position so pasef is passed before the plugin
consumer (i.e. pass pasef, &qc_consumer to loadSwathFiles), and update the other
call to include pasef as the 12th argument (i.e. pass pasef before the optional
plugin consumer). Locate loadSwathFiles invocations in OpenSwathWorkflow::...
(the two calls shown that currently pass &qc_consumer and the one without it)
and insert pasef in the parameter list immediately before any plugin/consumer
pointer argument.
---
Nitpick comments:
In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 1007-1020: Replace the index-based loop over
transition_exp.getTransitions() with a range-based loop (e.g. for (const auto&
tr : transition_exp.getTransitions())) and change the sentinel check from exact
equality to a defensive numeric test (replace tr.precursor_im == -1 with
tr.precursor_im < 0) to catch any negative sentinel values; keep the thrown
Exception::IllegalArgument and use tr.getNativeID() for the error message.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/tests/topp/CMakeLists.txt (1)
1773-1776: Avoid parallel test clobbering of shared outputs
TOPP_OpenSwathWorkflow_17and_17_cachewrite to the same temp output files. When CTest runs in parallel, the cache variant can overwrite the non-cache outputs mid-diff. Consider giving the cache test its own output filenames.Suggested change
-add_test("TOPP_OpenSwathWorkflow_17_cache" ${TOPP_BIN_PATH}/OpenSwathWorkflow -in ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_input.mzML -tr ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_input.tsv -out_chrom ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.chrom.tmp.mzML -out_features ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.tmp.featureXML -readOptions cache -ion_mobility_window 0.05 -use_ms1_ion_mobility "false" -Scoring:Scores:use_ion_mobility_scores "true" -Calibration:auto_irt:enabled "false" -Calibration:windows:estimate_rt "false" -Calibration:windows:estimate_mz "false" -Calibration:windows:estimate_im "false" +add_test("TOPP_OpenSwathWorkflow_17_cache" ${TOPP_BIN_PATH}/OpenSwathWorkflow -in ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_input.mzML -tr ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_input.tsv -out_chrom ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17_cache.chrom.tmp.mzML -out_features ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17_cache.tmp.featureXML -readOptions cache -ion_mobility_window 0.05 -use_ms1_ion_mobility "false" -Scoring:Scores:use_ion_mobility_scores "true" -Calibration:auto_irt:enabled "false" -Calibration:windows:estimate_rt "false" -Calibration:windows:estimate_mz "false" -Calibration:windows:estimate_im "false" ${OLD_OSW_PARAM} ) -add_test("TOPP_OpenSwathWorkflow_17_cache_out1" ${DIFF} -whitelist "id=" -in1 ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.tmp.featureXML -in2 ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_output.featureXML) -add_test("TOPP_OpenSwathWorkflow_17_cache_out2" ${DIFF} -whitelist "id=" -in1 ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.chrom.tmp.mzML -in2 ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_output.chrom.mzML) +add_test("TOPP_OpenSwathWorkflow_17_cache_out1" ${DIFF} -whitelist "id=" -in1 ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17_cache.tmp.featureXML -in2 ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_output.featureXML) +add_test("TOPP_OpenSwathWorkflow_17_cache_out2" ${DIFF} -whitelist "id=" -in1 ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17_cache.chrom.tmp.mzML -in2 ${DATA_DIR_TOPP}/OpenSwathWorkflow_17_output.chrom.mzML)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/topp/CMakeLists.txt` around lines 1773 - 1776, The cache variant add_test "TOPP_OpenSwathWorkflow_17_cache" currently writes to the same temp files ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.chrom.tmp.mzML and ${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.tmp.featureXML as the non-cache test, causing parallel CTest clobbering; change the cache test to use unique filenames (e.g. append _cache to both temp output names) and update the corresponding comparison tests "TOPP_OpenSwathWorkflow_17_cache_out1" and "TOPP_OpenSwathWorkflow_17_cache_out2" to point at those new cache-specific temp files so the diff compares the cache outputs to the reference files without interfering with the non-cache run.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/tests/topp/CMakeLists.txt`:
- Around line 1773-1776: The cache variant add_test
"TOPP_OpenSwathWorkflow_17_cache" currently writes to the same temp files
${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.chrom.tmp.mzML and
${TESTS_TEMP_DIR}/OpenSwathWorkflow_17.tmp.featureXML as the non-cache test,
causing parallel CTest clobbering; change the cache test to use unique filenames
(e.g. append _cache to both temp output names) and update the corresponding
comparison tests "TOPP_OpenSwathWorkflow_17_cache_out1" and
"TOPP_OpenSwathWorkflow_17_cache_out2" to point at those new cache-specific temp
files so the diff compares the cache outputs to the reference files without
interfering with the non-cache run.
44d353c to
7576699
Compare
…nSwathWorkflow Add a string list parameter Debugging:disable_features that allows selectively disabling IM features for benchmarking: - no_IM_calibration: skip ion mobility calibration by iRT peptides - no_IM_windowing: extract over full IM range and disable PASEF matching Change Scoring:Scores:use_ion_mobility_scores default from "false" to "auto". "auto" enables IM scoring for PASEF data and disables otherwise, while explicit "true"/"false" is always respected. This fixes a bug where the previous auto-enable code could not distinguish user-set "false" from the default "false". Also fix per-run state leaking in multi-run mode by resetting pasef and creating a per-run copy of feature_finder_param inside the run loop. Co-Authored-By: Claude Opus 4.6 <[email protected]>
7576699 to
41f7f2e
Compare
|
@singjc Quick question about the multi-run loop: In your commit This commit adds: pasef = user_pasef; // reset to user-provided value at start of each run
Param feature_finder_param_run = feature_finder_param; // per-run copyDoes this match your intent from the original carry-over fix? Or was there a reason |
MSVC with /arch:AVX uses 256-bit SIMD reductions in Eigen (4 doubles per lane), while GCC/Clang with -mssse3 use 128-bit (2 doubles). The different tree-reduction groupings cause floating-point rounding differences in standardize_data(), flipping borderline potentialOutlier decisions on Windows (tests 21 and 27). MSVC x64 defaults to SSE2 (128-bit), matching GCC/Clang's lane width and ensuring consistent Eigen reduction order across platforms. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The chromatogram extraction params were set to a new copy for each input mzML because we estimate and modify the rt / mz/ im extraction windows stored in the chromatogram extraction param object. |
|
@singjc Do you know how it possibly could be slower with linear calibration? Random business of your computer? |
|
@cbielow I will merge as avx seemed to be the culprit. I don't think it will make a huge difference in practice given that eigen and the base64 stuff is the main part that uses it. If we find evidence that it indeed has pratical implications we should e.g. reenable it targeted to the relevant files. |
I think it's just resource races, I had it running in the background, but had a bunch of other programs running when I was testing it |
Summary
XCorr scoring speedups
maxdelayat 10 data points in allMRMScoringcross-correlation call sites. Previouslymaxdelay = N(full chromatogram length, typically ~150), computing 301 lags when only lags within ~10 points (~18-30 seconds) are physically meaningful for coelution scoring. This reduces the outer loop from ~300 to 21 iterations, changing per-pair complexity from O(N²) to O(N).calculateCrossCorrelationinner loop by precomputingstart/endbounds instead ofif (j < 0 || j >= datasize) continue. This enables compiler auto-vectorization (SSE/AVX) of the dot-product loop.Eigen vectorization
IM debugging controls and fixes
New parameter:
Debugging:disable_features— a string list that selectively disables IM features for benchmarking:no_IM_calibrationirt_im_extraction_window = -1)no_IM_windowingno_IM_calibrationfor that)Changed default:
Scoring:Scores:use_ion_mobility_scores— changed from"false"to"auto":auto(new default)truefalseThis fixes a bug where the previous auto-enable code checked
== "false"but could not distinguish "user explicitly set false" from "default is false", silently overriding user intent for PASEF data.Bug fix: per-run state leaking in multi-run mode —
pasefandfeature_finder_paramare now reset/copied at the start of each run iteration, matching the existing pattern forcp_current/cp_ms1_current/cp_irt_current. Previously, auto-detection and scoring overrides from run N could carry into run N+1.Details
XCorr
A new
static constexpr int XCORR_MAX_DELAY = 10is used at all 7normalizedCrossCorrelationPostcall sites inMRMScoring.cppasstd::min(XCORR_MAX_DELAY, static_cast<int>(data.size())). Call sites outside the hot scoring loop (MasstraceCorrelator,MRMTransitionGroupPicker) are left unchanged.Score values change slightly since fewer lags are computed, but the scores at small lags (which determine coelution and shape scores) are numerically identical. Reference files updated accordingly.
IM flag interactions
no_IM_windowingforcespasef = false, soautoIM scoring resolves tofalse. To get IM scoring without PASEF windowing, explicitly set-Scoring:Scores:use_ion_mobility_scores true.no_IM_calibrationhas no effect on IM scoring or windowing.Test plan
MRMScoring_test— all sections pass (updated expectations for array size 23→21 and aggregate scores)Scoring_test— passes (usesmaxdelay=2, unaffected)OpenSwathScoring_test— passesMRMFeatureFinderScoring_test— passesTOPP_OpenSwathWorkflow— 76/76 pass (12 reference featureXML files regenerated)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Performance
Chores