Repository navigation
MTD refactor - #8149
MTD refactor#8149
Conversation
…. Bug fux moving up in rt dimension
Co-authored-by: Timo Sachsenberg <[email protected]>
…aining fwhm_mz_avg for all traces
…1 traces annotated with fwhm_mz_avg. Now all traces are annotated
…lerance parameter
WalkthroughThe mass trace detection algorithm was refactored and enhanced to modularize peak finding, selection, and trace extension logic. New internal data structures and helper methods were introduced, and the main extension loop was rewritten for clarity and consistency. Documentation and changelog entries were updated to reflect these changes. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MassTraceDetection
participant Spectrum
participant Trace
User->>MassTraceDetection: run_()
loop For each apex
MassTraceDetection->>Spectrum: Access spectrum data
MassTraceDetection->>MassTraceDetection: findBestPeak_()
alt Peak found and isPeakAcceptable_()
MassTraceDetection->>Trace: processPeak_()
MassTraceDetection->>MassTraceDetection: Update centroid, intensity, FWHM, etc.
else No acceptable peak
MassTraceDetection->>MassTraceDetection: Increment miss counter
end
MassTraceDetection->>MassTraceDetection: Check extension/termination criteria
end
MassTraceDetection->>MassTraceDetection: isTraceValid_()
alt Valid trace
MassTraceDetection->>User: Add to result
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~35 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/openms/source/FEATUREFINDER/MassTraceDetection.cpp (1)
458-508: Good initialization updates for ion mobility support.The changes properly initialize:
- Metadata array detection via getIMIndices_
- Ion mobility centroid tracking when available
- FWHM metadata collection
However, the same concern about direct array access applies here.
Consider using getIMData() method for consistency with OpenMS best practices when accessing ion mobility data at lines 497 and 500-501.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG(2 hunks)src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h(4 hunks)src/openms/source/FEATUREFINDER/MassTraceDetection.cpp(6 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
📚 Learning: ms:1000893 in psi-ms controlled vocabulary refers to "peptide group label", not "peptidoform group l...
Learnt from: poshul
PR: OpenMS/OpenMS#8133
File: src/tests/class_tests/openms/data/MRMAssay_uisTransitions_output_4_boost58.TraML:30-30
Timestamp: 2025-07-29T10:06:14.860Z
Learning: MS:1000893 in PSI-MS controlled vocabulary refers to "peptide group label", not "peptidoform group label". There is no official PSI-MS CV term for "peptidoform group label" with accession MS:1003050 as I incorrectly claimed.
Applied to files:
CHANGELOG
📚 Learning: in openms, the proper way to access ion mobility data in msspectrum is to use the `getimdata()` meth...
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Applied to files:
src/openms/source/FEATUREFINDER/MassTraceDetection.cppsrc/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: cppcheck-test
🔇 Additional comments (11)
CHANGELOG (1)
45-45: LGTM! Good punctuation fix.Adding the period properly completes the sentence and maintains consistency with other changelog entries.
src/openms/source/FEATUREFINDER/MassTraceDetection.cpp (7)
88-90: LGTM! Proper use of constants for metadata array names.The code correctly uses the new constant names for ion mobility and FWHM metadata arrays, which aligns with the PR's objective of adding ion mobility support.
110-139: Excellent validation logic for metadata consistency.The lambda function approach for validating metadata arrays is clean and reusable. The validation ensures data integrity by checking that:
- Arrays are consistently present/absent across all spectra
- Array sizes match spectrum sizes
- Clear exception messages are provided for debugging
This is crucial for reliable ion mobility data processing.
322-359: Well-structured peak validation logic.The method properly validates peak candidates against:
- m/z tolerance window (±3 standard deviations)
- Ion mobility tolerance window (when available)
- Previous usage in other traces
The logic is clear and correctly implements the acceptance criteria.
361-419: Comprehensive peak processing implementation.The method effectively handles all aspects of peak processing:
- Correctly adds peaks to trace based on extension direction
- Updates centroids using intensity-weighted averaging
- Collects FWHM metadata for quality assessment
- Implements dynamic m/z tolerance adjustment when enabled
The implementation is thorough and well-structured.
422-446: Clean trace validation implementation.The method properly validates traces based on:
- Minimum length requirement
- Optional maximum length constraint
- Quality metric (sample rate) with appropriate adjustments for terminal missed scans
The logic is clear and correctly implements the validation criteria.
510-625: Excellent refactoring of the trace extension loop.The refactored implementation provides significant improvements:
- Clean state management using TraceExtensionState struct
- Clear separation of concerns with helper methods
- Proper handling of empty spectra (they don't affect termination counters)
- Well-implemented termination criteria for both "outlier" and "sample_rate" modes
- Improved readability and maintainability
This modular approach makes the code much easier to understand and maintain.
630-645: Clean trace finalization with proper metadata handling.The implementation correctly:
- Uses the new isTraceValid_ helper for validation
- Calculates median FWHM values (appropriate summary statistic)
- Sets ion mobility centroid when available
- Maintains all existing trace properties
Good separation of concerns and proper handling of optional metadata.
src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h (3)
17-118: Well-designed data structures for the refactored algorithm.The new structs provide excellent encapsulation:
PeakCandidate: Cleanly represents peak search results with all necessary attributesTraceExtensionState: Effectively manages trace extension state in a single structureBoth have proper default constructors with sensible initial values. The boost dynamic_bitset include is appropriate for efficient peak visitation tracking.
134-173: Clear and well-structured method declarations.The new private methods are well-designed:
findBestPeak_: Focused on peak finding with optional ion mobilityisPeakAcceptable_: Clear validation logic separationprocessPeak_: Handles all peak processing in one placeisTraceValid_: Encapsulates trace validation criteriaAll methods have appropriate const-correctness and clear documentation.
195-198: Consider thread safety implications of mutable members.While the mutable metadata indices are useful for caching array positions, they could cause issues in multi-threaded scenarios if the same MassTraceDetection instance is used concurrently.
Are there any multi-threading use cases for MassTraceDetection? If so, consider either:
- Making these non-mutable and passing them as parameters
- Adding thread synchronization
- Documenting that instances are not thread-safe
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (2)
src/openms/source/FEATUREFINDER/MassTraceDetection.cpp (2)
266-321: Ion mobility access still uses direct FloatDataArrays indexing.This code segment continues to use the pattern flagged in previous reviews. According to OpenMS best practices, you should use the
getIMData()method instead of directly accessingspectrum.getFloatDataArrays()[ion_mobility_idx_].Consider refactoring to use the recommended API:
-double im_value = spectrum.getFloatDataArrays()[ion_mobility_idx_][i]; +auto [im_position, im_unit] = spectrum.getIMData(); +double im_value = spectrum.getFloatDataArrays()[im_position][i];
498-503: Ion mobility access pattern needs updating.Similar to the earlier comment, this code uses direct FloatDataArrays access instead of the recommended
getIMData()method.
🧹 Nitpick comments (2)
src/openms/source/FEATUREFINDER/MassTraceDetection.cpp (2)
490-490: Unnecessary redundant call to updateIterativeWeightedMean_.Line 490 calls
updateIterativeWeightedMean_immediately after the centroid initialization, but the centroid values were already set correctly during initialization. This redundant call doesn't change the values but adds unnecessary computation.Remove the redundant call:
-updateIterativeWeightedMean_(apex_peak.getMZ(), apex_peak.getIntensity(), centroid_mz, prev_counter, prev_denom);
508-509: FWHM data access uses direct indexing.While not ion mobility data, these lines also use direct FloatDataArrays access. Consider if there are equivalent helper methods available for FWHM data access to maintain consistency.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h(5 hunks)src/openms/source/FEATUREFINDER/MassTraceDetection.cpp(8 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in openms, the proper way to access ion mobility data in msspectrum is to use the `getimdata()` meth...
Learnt from: jpfeuffer
PR: OpenMS/OpenMS#7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:24-28
Timestamp: 2025-04-07T21:16:06.557Z
Learning: In OpenMS, the proper way to access ion mobility data in MSSpectrum is to use the `getIMData()` method, which returns a tuple with (position, unit). The position corresponds to the index in the FloatDataArrays where the ion mobility data is stored. Always use this method rather than assuming the first FloatDataArray contains ion mobility data.
Applied to files:
src/openms/source/FEATUREFINDER/MassTraceDetection.cppsrc/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (18)
src/openms/source/FEATUREFINDER/MassTraceDetection.cpp (12)
18-18: LGTM: Exception handling import added.Good addition for improved error handling in parameter validation.
89-90: Improved variable naming for clarity.The renaming from ambiguous indices to more descriptive
ion_mobility_idx_andim_fwhm_idx_improves code readability.
111-140: Excellent validation logic for metadata consistency.The new validation ensures metadata arrays are consistently present across all spectra, preventing runtime errors from inconsistent data. The exception messages are clear and informative.
323-360: Well-structured peak acceptance validation.The
isPeakAcceptable_method properly encapsulates all validation logic including m/z tolerance, ion mobility tolerance, and peak visitation checks. The logic is clear and comprehensive.
362-420: Comprehensive peak processing encapsulation.The
processPeak_method effectively consolidates peak processing logic, handling both LC-MS and LC-IMS-MS data paths. The intensity-weighted centroid updates and FWHM collection are properly implemented.
423-447: Clean trace validation logic.The
isTraceValid_method nicely encapsulates trace quality assessment with clear length and sample rate criteria. The adjusted scan calculation properly accounts for consecutive misses.
459-463: Improved variable naming consistency.The parameter renaming to
fwhm_meta_idx_,ion_mobility_idx_, andim_fwhm_idx_provides better clarity and consistency throughout the codebase.
511-513: Clean state management with TraceExtensionState.The introduction of
TraceExtensionStatestruct significantly improves code organization by consolidating multiple counters and flags into coherent state objects.
518-625: Excellent refactoring of trace extension logic.The main extension loop is much cleaner now with the helper methods. The consistent application of termination criteria and state management makes the code more maintainable and easier to understand.
631-632: Simplified trace validation call.The refactored validation using
isTraceValid_method is much cleaner and easier to understand than the previous inline checks.
644-645: Clean FWHM median calculation.The conditional FWHM averaging logic is well-structured and handles the case when FWHM data is not available.
674-686: Robust parameter validation with enum mapping.The new parameter parsing logic with enum mapping and exception handling for invalid values is a significant improvement over string-based comparisons. This prevents runtime errors from configuration mistakes.
src/openms/include/OpenMS/FEATUREFINDER/MassTraceDetection.h (6)
17-17: Appropriate include for boost::dynamic_bitset.The include is correctly added to support the bitset usage in the implementation.
53-58: Well-designed enum for trace termination criteria.The
TraceTerminationCriterionenum provides better type safety and performance compared to string-based comparisons. The documentation is clear and descriptive.
104-125: Well-structured helper structs for data organization.Both
PeakCandidateandTraceExtensionStatestructs are well-designed with appropriate default constructors. They effectively encapsulate related data and improve code organization.
141-179: Comprehensive method declarations for modularization.The new private methods are well-documented and provide clear separation of concerns. The parameter lists are appropriate for their respective functionalities.
194-194: Type-safe parameter with enum.Replacing the string-based parameter with the enum type improves type safety and prevents invalid configuration values.
202-205: Mutable metadata indices for lazy initialization.The mutable metadata index members allow for lazy initialization during the run methods, which is a reasonable design choice for this use case.
Factored out into helper functions. No change in logic.
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Refactor