Repository navigation
Fragment Index search engine tests - #8220
Conversation
WalkthroughAdded per-PSM metadata (isotope_error, applied_charge, delta_mass), reorganized/search parameter namespaces (precursor/fragment/ions/scoring), replaced stored open_search flag with computed isOpenSearchMode_(), introduced OpenSearchModificationAnalysis (header+impl) and integrated it, and added TOPP tests/fixtures and updated tests. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant T as TOPP PeptideDataBaseSearchFI
participant A as PeptideSearchEngineFIAlgorithm
participant F as FragmentIndex
participant S as TheoreticalSpectrumGenerator
participant M as OpenSearchModificationAnalysis
U->>T: run tool (mzML + FASTA + params)
T->>A: configure (precursor/fragment/ions/scoring)
A->>F: build index (ions:add_*_ions)
F->>S: configure ion series
S-->>F: fragments
F-->>A: index ready
A->>A: isOpenSearchMode_() (precursor tolerance)
alt open-search
Note right of A #bfe5bf: auto-enabled (logged)
end
loop per spectrum
A->>F: query candidates
F-->>A: candidates (sorted by |isotope_error|, isotope_error, charge)
A->>A: compute used_charge, ln(hyperscore), add isotope_error
opt open-search
A->>A: compute delta_mass per hit
A->>M: analyzeModifications(peptide_ids,...)
M-->>A: mapped modifications & annotated PSMs
end
A-->>T: emit IdXML (PSMs with meta: isotope_error, applied_charge, DeltaMass)
end
T-->>U: IdXML output
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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. Comment |
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 (2)
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (2)
232-238: Bucket size can be zero → infinite loop.When fi_fragments_ is empty, bucketsize_ becomes 0 and the for-loop never advances. Clamp to >= 1 and early-exit on empty input.
- bucketsize_ = sqrt(fi_fragments_.size()); //Todo: MSFragger uses a different approach, which might be better + if (fi_fragments_.empty()) { + is_build_ = true; + OPENMS_LOG_INFO << "Fragment index built (no fragments)." << endl; + return; + } + bucketsize_ = std::max<size_t>(1, static_cast<size_t>(std::sqrt(static_cast<double>(fi_fragments_.size()))));
258-266: Off-by-one in peptide index range (inclusive vs. exclusive).getPeptidesInPrecursorRange returns [left, right_exclusive). Downstream treats second as inclusive and resizes with +1, admitting peptides outside the window and wasting space.
- return make_pair(std::distance(fi_peptides_.begin(), left_it), std::distance(fi_peptides_.begin(), right_it)); + // Return [begin, end) range + return {static_cast<size_t>(std::distance(fi_peptides_.begin(), left_it)), + static_cast<size_t>(std::distance(fi_peptides_.begin(), right_it))}; @@ - auto left_iter = std::lower_bound(slice_begin, slice_end, peptide_idx_range.first, [](Fragment a, UInt32 b) { return a.peptide_idx_ < b;} ); + auto left_iter = std::lower_bound(slice_begin, slice_end, peptide_idx_range.first, + [](const Fragment& a, UInt32 b) { return a.peptide_idx_ < b;}); @@ - if(left_iter->peptide_idx_ > peptide_idx_range.second) break; + if (left_iter->peptide_idx_ >= peptide_idx_range.second) break; @@ - candidates_iso_error.hits_.resize(candidates_range.second - candidates_range.first + 1); + candidates_iso_error.hits_.resize(candidates_range.second - candidates_range.first);Also applies to: 292-299, 445-447
🧹 Nitpick comments (12)
src/tests/topp/PeptideDataBaseSearchFI_2.ini (1)
30-30: Fix truncated description.Complete the fragment tolerance description string.
- <ITEM name="mass_tolerance_unit" value="Da" type="string" description="Unit of fragment m" required="false" advanced="false" restrictions="ppm,Da" /> + <ITEM name="mass_tolerance_unit" value="Da" type="string" description="Unit of fragment mass tolerance." required="false" advanced="false" restrictions="ppm,Da" />src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h (3)
24-51: Remove duplicated class docblock.Two identical blocks back-to-back. Drop one.
139-143: Fix parameter docs: units are strings, not booleans.Docs say "'true'->ppm, 'false'->Da" but the function receives strings ("ppm"/"Da"). Update comments.
197-198: Document new member.Add a brief Doxygen comment for open_search_ to explain when it’s set (explicit vs. auto).
src/tests/topp/PeptideDataBaseSearchFI_1.ini (3)
29-29: Fix truncated description.Same typo as in 2.ini.
- <ITEM name="mass_tolerance_unit" value="Da" type="string" description="Unit of fragment m" required="false" advanced="false" restrictions="ppm,Da" /> + <ITEM name="mass_tolerance_unit" value="Da" type="string" description="Unit of fragment mass tolerance." required="false" advanced="false" restrictions="ppm,Da" />
2-2: Align schema version if feasible.1.ini uses Param_1_6_2 while 2.ini uses 1_7_0. If not required by the test intent, consider bumping to 1.7.0 for consistency.
12-13: Boolean encoding inconsistency.These ITEMs model booleans as strings with restrictions. If the 1.6.2 schema supports type="bool", consider switching; otherwise keep but note the inconsistency with 2.ini.
Also applies to: 16-16, 20-21, 41-41, 47-47
src/tests/topp/PeptideDataBaseSearchFI_2_out.idXML (1)
4-4: Avoid machine-specific absolute paths in fixtures.db points to /home/...; prefer a relative path or normalized placeholder used by existing OpenMS tests to keep fixtures portable.
- <SearchParameters id="SP_0" db="/home/sachsenb/Development/OpenMS/src/tests/topp/SimpleSearchEngine_1.fasta" ... + <SearchParameters id="SP_0" db="SimpleSearchEngine_1.fasta" ...src/tests/topp/PeptideDataBaseSearchFI_1_out.idXML (1)
4-4: Avoid machine-specific absolute paths in fixtures.Same as 2_out.
- <SearchParameters id="SP_0" db="/home/sachsenb/Development/OpenMS/src/tests/topp/SimpleSearchEngine_1.fasta" ... + <SearchParameters id="SP_0" db="SimpleSearchEngine_1.fasta" ...src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (2)
359-365: Use std::abs and avoid manual branching.Minor clarity/readability in tie-breaker comparator.
- const auto abs_iso_a = a.isotope_error_ < 0 ? -a.isotope_error_ : a.isotope_error_; - const auto abs_iso_b = b.isotope_error_ < 0 ? -b.isotope_error_ : b.isotope_error_; + const auto abs_iso_a = std::abs(a.isotope_error_); + const auto abs_iso_b = std::abs(b.isotope_error_);Also applies to: 379-385
82-85: Prefer OpenMS logging over std::cout.Replace std::cout with OPENMS_LOG_* for consistency and log-level control, per guidelines.
- std::cout << "Generating peptides..." << std::endl; + OPENMS_LOG_INFO << "Generating peptides..." << std::endl; @@ - std::cout << "Sorting peptides..." << std::endl; + OPENMS_LOG_INFO << "Sorting peptides..." << std::endl; @@ - OPENMS_LOG_INFO << "Generating fragments..." << std::endl; + OPENMS_LOG_INFO << "Generating fragments..." << std::endl; @@ - std::cout << "Sorting fragments..." << std::endl; + OPENMS_LOG_INFO << "Sorting fragments..." << std::endl;Also applies to: 149-156, 192-195, 223-229
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (1)
400-409: Consider reducing debug logging verbosity in production.The debug logging provides useful information during development but may become verbose in production runs with large datasets. Consider making this conditional based on log level or adding a parameter to control verbosity.
-// Debug: log spectrum-level top hit details before storing PeptideIdentification -if (!pi.getHits().empty()) -{ - const PeptideHit& top_hit = pi.getHits().front(); - OPENMS_LOG_INFO << "[PDBS-FI] scan_index=" << scan_index - << " top_ln(hyperscore)=" << top_hit.getScore() - << " top_charge=" << top_hit.getCharge() - << " top_isotope_error=" << (int)top_hit.getMetaValue("isotope_error") - << std::endl; -} +// Debug: log spectrum-level top hit details before storing PeptideIdentification +if (!pi.getHits().empty()) +{ + const PeptideHit& top_hit = pi.getHits().front(); + OPENMS_LOG_DEBUG << "[PDBS-FI] scan_index=" << scan_index + << " top_ln(hyperscore)=" << top_hit.getScore() + << " top_charge=" << top_hit.getCharge() + << " top_isotope_error=" << (int)top_hit.getMetaValue("isotope_error") + << std::endl; +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h(2 hunks)src/openms/source/ANALYSIS/ID/FragmentIndex.cpp(7 hunks)src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp(10 hunks)src/tests/topp/CMakeLists.txt(1 hunks)src/tests/topp/PeptideDataBaseSearchFI_1.ini(1 hunks)src/tests/topp/PeptideDataBaseSearchFI_1_out.idXML(1 hunks)src/tests/topp/PeptideDataBaseSearchFI_2.ini(1 hunks)src/tests/topp/PeptideDataBaseSearchFI_2_out.idXML(1 hunks)src/topp/PeptideDataBaseSearchFI.cpp(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/openms/**/*.{cpp,h,hpp,cc,cxx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms
Files:
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cppsrc/openms/source/ANALYSIS/ID/FragmentIndex.cppsrc/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
src/openms/include/OpenMS/**/*.h
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Add Doxygen comments for new public methods and classes
Files:
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
🧠 Learnings (4)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/include/OpenMS/**/*.h : Add Doxygen comments for new public methods and classes
Applied to files:
src/topp/PeptideDataBaseSearchFI.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings
Applied to files:
src/topp/PeptideDataBaseSearchFI.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.
Applied to files:
src/tests/topp/CMakeLists.txt
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/tests/topp/CMakeLists.txt
🧬 Code graph analysis (1)
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h (1)
src/openms/include/OpenMS/METADATA/PeptideHit.h (1)
PeakAnnotation(84-97)
⏰ 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 (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
🔇 Additional comments (20)
src/topp/PeptideDataBaseSearchFI.cpp (2)
72-74: Make CLI help explicit: input is mzML-only (point to FileConverter). Verified no INI/CLI uses mzXML/MGF.- registerInputFile_("in", "<file>", "", "input file "); + registerInputFile_("in", "<file>", "", "Input spectra (mzML only). Use TOPP FileConverter to convert other formats."); setValidFormats_("in", ListUtils::create<String>("mzML"));
47-47: Clarify auto-open-search thresholds, parameter keys, and logging/meta keys.Replace the ambiguous note with a precise statement:
@note Open-search mode is automatically enabled when the configured precursor mass tolerance is strictly greater than 1.0 Da or strictly greater than 1000 ppm (this is a '>' check), even if the parameter "precursor:open_search" is set to false. This is logged at INFO (OPENMS_LOG_INFO) (e.g. "[FragmentIndex] Enabling open-search mode because precursor mass tolerance (...) exceeds threshold (1000 ppm or 1 Da)." and "[PDBS-FI] Enabling open-search mode (implicit) ..."), and the output search parameters include the meta key "open_search" set to "true" or "false" via search_parameters.setMetaValue("open_search", open_search_ ? "true" : "false"). To force a closed search, use a precursor tolerance <= 1.0 Da or <= 1000 ppm.
Relevant code locations: src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (implicit_open_search > 1.0 / > 1000.0), src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (implicit-open-search check, INFO logs, and search_parameters.setMetaValue).
src/tests/topp/PeptideDataBaseSearchFI_2.ini (1)
2-2: Schema URL uses raw GitHub; confirm stability.If the parser dereferences schemas in CI, prefer a stable hosted location (OpenMS site) or ensure offline validation. Otherwise keep as-is.
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h (1)
17-18: Header include/name check.Ensure PeptideIdentificationList is a valid public type and the include path is correct in this repo version.
src/tests/topp/PeptideDataBaseSearchFI_2_out.idXML (1)
10-10: Brittle timestamp/version.IdentificationRun date and search_engine_version look build-time specific. Ensure the TOPP test comparison ignores these fields; otherwise, pin deterministic values or strip in test harness.
src/tests/topp/PeptideDataBaseSearchFI_1_out.idXML (1)
10-10: Brittle timestamp/version.Same concern as 2_out; confirm comparator excludes these.
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (3)
237-250: Parallel sort of disjoint ranges: keep or drop?Sorting disjoint buckets in parallel is generally safe, but please confirm no overlap when bucketsize_ changes (especially for small vectors). If in doubt, consider single-threaded sort here; it’s not the hot path compared to peptide/fragment generation.
169-176: Param mapping looks good.Mapping ions:add_*_ions → TSG keys is correct.
648-663: Auto open-search enable is sensible.Thresholds and log message are clear; merging explicit and implicit flags is correct.
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (9)
131-167: LGTM! Hierarchical parameter organization with clear sections.The reorganization of parameters into logical namespaces (precursor, fragment, scoring, ions) improves maintainability and clarity. The auto-enabling open search based on tolerance thresholds is a thoughtful UX improvement.
215-216: LGTM! Parameter access correctly updated.The open_search_ assignment correctly reads from the new hierarchical parameter structure.
333-335: LGTM! Improved charge handling logic.The charge selection logic correctly prioritizes spectrum-reported charge while gracefully falling back to the FragmentIndex-applied charge. This ensures robust charge handling across different data sources.
362-362: LGTM! Consistent charge usage in theoretical m/z calculation.The precursor error calculation correctly uses the resolved
used_chargefor theoretical m/z computation, maintaining consistency with the charge handling logic above.
377-384: LGTM! Comprehensive metadata enrichment for PSMs.The addition of
isotope_errormetadata to all PSMs anddelta_massfor open search provides valuable information for downstream analysis and filtering. The conditional inclusion of delta_mass based on search mode is appropriate.
462-463: LGTM! Search parameters metadata correctly updated.The addition of open_search metadata to search parameters provides transparency about the search mode used, supporting reproducibility and result interpretation.
474-492: LGTM! Intelligent auto-enabling of open search with clear logging.The auto-enabling logic based on precursor tolerance thresholds (>1 Da or >1000 ppm) is well-reasoned and user-friendly. The logging clearly communicates when and why open search is enabled, improving transparency.
623-639: LGTM! Comprehensive metadata population from FragmentIndex results.The assignment of isotope_error and applied_charge from FragmentIndex results, along with proper delta_mass calculation for open search, ensures all relevant search metadata is captured. The delta_mass calculation correctly converts between m/z and neutral mass.
640-640: LGTM! Efficient move semantics for performance.Using
std::movefor the AnnotatedHit_ prevents unnecessary copying in the performance-critical spectrum scoring loop.src/tests/topp/CMakeLists.txt (2)
2735-2742: Approve — whitelist and DEPENDS present for TOPP_PeptideDataBaseSearchFI_2_out (src/tests/topp/CMakeLists.txt:2739–2741).
2726-2734: Approve: PeptideDataBaseSearchFI test, whitelist, and DEPENDS are correct.add_test (TOPP_PeptideDataBaseSearchFI_1), the -whitelist entries, and set_tests_properties("TOPP_PeptideDataBaseSearchFI_1_out" PROPERTIES DEPENDS "TOPP_PeptideDataBaseSearchFI_1") are present in src/tests/topp/CMakeLists.txt (lines 2727–2733).
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (3)
src/topp/SageAdapter.cpp (1)
634-642: Pass actual user-selected precursor tolerance (value + unit) instead of 0.01 Da.Hard-coded 0.01/Da ignores the adapter’s configured tolerance and ppm mode. Use the parsed options (you already compute and store them below for search_parameters).
Apply:
@@ - // Use shared modification analysis functionality - OpenSearchModificationAnalysis mod_analyzer; - auto modification_summaries = mod_analyzer.analyzeModifications( - peptide_identifications, - 0.01, // precursor_mass_tolerance - false, // precursor_mass_tolerance_unit_ppm (0.01 Da) - smoothing, - output_file - ); + // Use shared modification analysis functionality with actual precursor tolerance settings + const double precursor_tol_left = std::fabs(getDoubleOption_("precursor_tol_left")); + const double precursor_tol_right = std::fabs(getDoubleOption_("precursor_tol_right")); + const double precursor_tol_avg = 0.5 * (precursor_tol_left + precursor_tol_right); + const bool precursor_tol_is_ppm = (getStringOption_("precursor_tol_unit") == "ppm"); + + OpenSearchModificationAnalysis mod_analyzer; + auto modification_summaries = mod_analyzer.analyzeModifications( + peptide_identifications, + precursor_tol_avg, + precursor_tol_is_ppm, + smoothing, + output_file + );Run to ensure no other hard-coded calls remain:
#!/bin/bash rg -n -C2 -g '!**/test/**' -P '\banalyzeModifications\s*\(' rg -n -C2 -P '\banalyzeModifications\s*\([^)]*(0\.0*1|false|true)' src | sed -n '1,200p'src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp (2)
163-176: Fix PPM/Da tolerance, handle negative delta masses, scan full window, avoid .at() exceptions, and use exact +1 isotope mass.Current logic flips bounds for negative masses, compares with raw ppm input, only probes endpoints, uses 1.0 Da for isotopes, and may throw on at(). This breaks mapping and mislabels PTMs.
Apply:
@@ - double lower_bound, upper_bound; - const double epsilon = 1e-8; - - if (precursor_mass_tolerance_unit_ppm) - { - double tolerance = cluster_mass * precursor_mass_tolerance * 1e-6; - lower_bound = cluster_mass - tolerance; - upper_bound = cluster_mass + tolerance; - } - else - { - lower_bound = cluster_mass - precursor_mass_tolerance; - upper_bound = cluster_mass + precursor_mass_tolerance; - } + const double epsilon = 1e-8; + const double tol_da = precursor_mass_tolerance_unit_ppm + ? std::abs(cluster_mass) * precursor_mass_tolerance * 1e-6 + : precursor_mass_tolerance; + const double lower_bound = cluster_mass - tol_da; + const double upper_bound = cluster_mass + tol_da; @@ - // Search in single modifications - auto it_lower = mass_to_modification.lower_bound(lower_bound - epsilon); - bool found_lower = false; - if (it_lower != mass_to_modification.end() && - std::abs(it_lower->first - cluster_mass) <= precursor_mass_tolerance) - { - found_lower = true; - } - - auto it_upper = mass_to_modification.upper_bound(upper_bound + epsilon); - bool found_upper = false; - if (it_upper != mass_to_modification.begin()) - { - --it_upper; - if (std::abs(it_upper->first - cluster_mass) <= precursor_mass_tolerance) - { - found_upper = true; - } - } - - // Compare results from lower_bound and upper_bound - if (found_lower && found_upper) - { - if (it_lower->first == it_upper->first && it_lower->second == it_upper->second) - { - mod_name = it_lower->second; - mod_mass = it_lower->first; - histogram_found[mod_mass] = mod_name; - mapping_found = true; - } - else - { - mod_name = it_lower->second + "//" + it_upper->second; - mod_mass = cluster_mass; - histogram_found[it_lower->first] = it_lower->second; - histogram_found[it_upper->first] = it_upper->second; - mapping_found = true; - } - } - else - { + // Scan full window and pick closest single modification + { + auto it_begin = mass_to_modification.lower_bound(lower_bound - epsilon); + auto it_end = mass_to_modification.upper_bound(upper_bound + epsilon); + double best_diff = std::numeric_limits<double>::max(); + for (auto it = it_begin; it != it_end; ++it) + { + const double d = std::abs(it->first - cluster_mass); + if (d < best_diff) + { + best_diff = d; + mod_name = it->second; + mod_mass = it->first; + mapping_found = true; + } + } + if (mapping_found) histogram_found[mod_mass] = mod_name; + } + + if (!mapping_found) + { // Check if modification can be explained by known modifications for (const auto& hit : histogram_found) { - if (std::abs(hit.first - cluster_mass) < precursor_mass_tolerance) + if (std::abs(hit.first - cluster_mass) <= tol_da) { - addOrUpdateModification(hit.second, hit.first, count, charge_histogram.at(cluster_mass)); + const auto cc_it = charge_histogram.find(cluster_mass); + const int num_charges = (cc_it != charge_histogram.end()) ? cc_it->second : 0; + addOrUpdateModification(hit.second, hit.first, count, num_charges); mapping_found = true; break; } // Check if modification can be explained by a +1 isotope variant - else if (std::abs((hit.first + 1.0) - cluster_mass) < precursor_mass_tolerance) + else if (std::abs((hit.first + OpenMS::Constants::C13C12_MASSDIFF_U) - cluster_mass) <= tol_da) { - String temp_mod_name = hit.second + "+1Da"; - addOrUpdateModification(temp_mod_name, hit.first + 1.0, count, charge_histogram.at(cluster_mass)); - histogram_found[hit.first + 1.0] = temp_mod_name; + String temp_mod_name = hit.second + "+1.00335Da"; + const double iso_mass = hit.first + OpenMS::Constants::C13C12_MASSDIFF_U; + const auto cc_it = charge_histogram.find(cluster_mass); + const int num_charges = (cc_it != charge_histogram.end()) ? cc_it->second : 0; + addOrUpdateModification(temp_mod_name, iso_mass, count, num_charges); + histogram_found[iso_mass] = temp_mod_name; mapping_found = true; break; } } // Search in combination modifications if (!mapping_found) { auto it = combo_modifications.lower_bound(cluster_mass - epsilon); - if (it != combo_modifications.end() && - std::abs(it->first - cluster_mass) <= precursor_mass_tolerance / 10.0) + if (it != combo_modifications.end() && + std::abs(it->first - cluster_mass) <= tol_da) { mod_name = it->second; mod_mass = it->first; mapping_found = true; } } } - if (std::abs(mod_mass) < precursor_mass_tolerance) - continue; // Skip if closest mod_mass is too close to 0 + // Optionally skip masses effectively at 0 within tolerance + if (std::abs(cluster_mass) <= tol_da) continue; @@ - if (mapping_found) + if (mapping_found) { - addOrUpdateModification(mod_name, mod_mass, count, charge_histogram.at(cluster_mass)); + const auto cc_it = charge_histogram.find(cluster_mass); + const int num_charges = (cc_it != charge_histogram.end()) ? cc_it->second : 0; + addOrUpdateModification(mod_name, mod_mass, count, num_charges); } else { // Unknown modification String unknown_mod_name = "Unknown" + String(std::round(cluster_mass)); - addOrUpdateModification(unknown_mod_name, cluster_mass, count, charge_histogram.at(cluster_mass)); + const auto cc_it = charge_histogram.find(cluster_mass); + const int num_charges = (cc_it != charge_histogram.end()) ? cc_it->second : 0; + addOrUpdateModification(unknown_mod_name, cluster_mass, count, num_charges); }Also applies to: 183-201, 224-256, 258-270
313-323: Use ppm-aware tolerance when assigning PTM names to peptide hits.Comparing against raw precursor_mass_tolerance ignores ppm mode.
- for (const auto& entry : histogram_found) - { - if (std::abs(delta_mass - entry.first) < precursor_mass_tolerance) - { - ptm = entry.second; - found = true; - break; - } - } + const double tol_da_hit = precursor_mass_tolerance_unit_ppm + ? std::abs(delta_mass) * precursor_mass_tolerance * 1e-6 + : precursor_mass_tolerance; + for (const auto& entry : histogram_found) + { + if (std::abs(delta_mass - entry.first) <= tol_da_hit) + { + ptm = entry.second; + found = true; + break; + } + }
🧹 Nitpick comments (2)
src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp (2)
9-15: Add required headers for exact isotope mass and numeric limits.Needed for precise +1 isotope handling and best-diff search.
#include <OpenMS/CONCEPT/LogStream.h> +#include <OpenMS/CONCEPT/Constants.h> #include <algorithm> #include <cmath> #include <fstream> #include <numeric> +#include <limits> #include <unordered_map> #include <unordered_set>
129-137: Avoid O(N^2) combo generation; compute combinations on-demand within tolerance.Precomputing all pairwise sums across all known mods is quadratic and can be large. Prefer a two-pointer search over the sorted single-mod masses restricted to [cluster_mass±tol] per cluster, or gate combo search behind a small cap.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp(1 hunks)src/topp/SageAdapter.cpp(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/openms/**/*.{cpp,h,hpp,cc,cxx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
src/openms/**/*.{cpp,h,hpp,cc,cxx}: Follow the existing C++ coding conventions in the codebase
Use the established naming patterns for classes, methods, and variables
Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Follow the established error handling patterns
Utilize OpenMS logging mechanisms
Be mindful of memory usage when processing large datasets
Consider algorithmic complexity for data processing operations
Use appropriate OpenMS containers and algorithms
Files:
src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp
🧠 Learnings (1)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Applied to files:
src/topp/SageAdapter.cpp
🪛 GitHub Check: CodeFactor
src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp
[notice] 103-346: src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp#L103-L346
Complex Method
⏰ 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 (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: cppcheck-test
🔇 Additional comments (3)
src/topp/SageAdapter.cpp (2)
12-12: Header include looks correct.Including OpenSearchModificationAnalysis here is appropriate for the new shared workflow.
105-105: Good: clear refactor note.Comment succinctly explains the delegation to the shared class.
src/openms/source/ANALYSIS/ID/OpenSearchModificationAnalysis.cpp (1)
344-358: LGTM: clean orchestration of the pipeline.Good separation: pattern analysis then mapping + annotation.
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/tests/class_tests/openms/source/FragmentIndex_test.cpp (1)
96-161: Fix matching checks in testQuery()
- The test unconditionally requires s.precursor_charge_ == charge even when the constructed spec_theo has no precursor charge (precursor_mz_known == false). Make the charge check conditional, e.g.:
if (s.peptide_idx_ == peptide_idx && (!precursor_mz_known || s.precursor_charge_ == charge)) { found = (s.num_matched_ >= /expected_peak_count/); }- Use an explicit expected peak count for clarity (b_y_ions.size() or an explicitly computed expected_count) instead of relying on spec_theo.size(), and keep the >= check (or relax further if generator params may add extra peaks).
- Optional: align how you build the precursor with TheoreticalSpectrumGenerator semantics (it sets precursor_charge = max_charge+1 when precursor_charge==0) — either set the precursor charge deterministically or use the generator’s precursor.
File: src/tests/class_tests/openms/source/FragmentIndex_test.cpp (lines ~96-161).
🧹 Nitpick comments (5)
src/tests/class_tests/openms/source/FragmentIndex_test.cpp (5)
28-29: Clarify the test documentation.The comment mentions "asserts ordering invariants for peptides/fragments" but could be more specific about what ordering is verified (precursor_mz_ for peptides, peptide_idx_ within fragment buckets).
63-63: Minor style: Use!foundconsistently.The negation style should be consistent with the rest of the codebase.
- if (! found) return false; + if (!found) return false;
73-75: Improve readability of sorting validation.The nested conditional structure could be clearer.
- if (pep.precursor_mz_ >= last_mz) { last_mz = pep.precursor_mz_; } - else { return false; } + if (pep.precursor_mz_ < last_mz) return false; + last_mz = pep.precursor_mz_;
117-118: Use consistent naming convention.The variable name
peptide_idxshould match the type naming fromSpectrumMatch::peptide_idx_which suggests underscore convention.- size_t peptide_idx = 0; // use size_t to match SpectrumMatch::peptide_idx_ type + size_t peptide_idx_ = 0;
400-410: Consider extracting magic numbers as named constants.The jitter calculation uses magic numbers that could be more readable as named constants.
+ constexpr float kFragmentTolerance = 0.045f; // ±0.045 Da based on 0.05 Da setting constexpr float kJitterStep = 0.001f; - constexpr int kJitterHalfWidth = 45; + constexpr int kJitterHalfWidth = static_cast<int>(kFragmentTolerance / kJitterStep);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h(3 hunks)src/tests/class_tests/openms/source/FragmentIndex_test.cpp(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h
🧰 Additional context used
📓 Path-based instructions (1)
src/tests/class_tests/openms/**/*.cpp
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for new functionality
Files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
🧠 Learnings (5)
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/**/*.cpp : Write unit tests for new functionality
Applied to files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/tests/class_tests/openms/*Test.cpp : Follow naming convention: `ClassNameTest.cpp` for `ClassName`
Applied to files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use OpenMS data structures (e.g., MSExperiment, FeatureMap, PeptideIdentification)
Applied to files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
📚 Learning: 2025-09-03T12:58:20.032Z
Learnt from: timosachsenberg
PR: OpenMS/OpenMS#8177
File: src/tests/topp/CMakeLists.txt:1857-1865
Timestamp: 2025-09-03T12:58:20.032Z
Learning: OpenMS tests: When adding new TOPP tests in src/tests/topp/CMakeLists.txt that compare outputs via FuzzyDiff, always add set_tests_properties("<tool>_<n>_out<m>" PROPERTIES DEPENDS "<tool>_<n>") to avoid flakiness under parallel CTest runs.
Applied to files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
PR: OpenMS/OpenMS#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/openms/**/*.{cpp,h,hpp,cc,cxx} : Use appropriate OpenMS containers and algorithms
Applied to files:
src/tests/class_tests/openms/source/FragmentIndex_test.cpp
🧬 Code graph analysis (1)
src/tests/class_tests/openms/source/FragmentIndex_test.cpp (1)
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (3)
querySpectrum(457-507)querySpectrum(457-458)FragmentIndex(512-612)
⏰ 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 (ubuntu-22.04, g++, 11)
- GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
- GitHub Check: build-and-test (macos-13, xcode, 14.2)
- GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
- GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
- GitHub Check: cppcheck-test
🔇 Additional comments (10)
src/tests/class_tests/openms/source/FragmentIndex_test.cpp (10)
18-18: LGTM!The include for
ListUtils.his moved earlier in the file, which is appropriate since it's used in the test helper methods.
42-95: Well-structured test helper class with clear invariant validation.The
FragmentIndex_testhelper class properly exposes internal state for white-box testing and implements clear invariant checks. The methods validate expected behaviors:
testDigestion(): Verifies exact peptide generation matches expectationspeptidesSorted(): Validates precursor_mz_ orderingfragmentsSorted(): Validates peptide_idx_ ordering within buckets
170-252: Comprehensive build() test coverage with data-driven approach.The test effectively validates multiple parameter combinations:
- Different enzyme settings (Trypsin)
- Various peptide size/mass constraints
- Missed cleavages
- Fixed and variable modifications
The expected peptide sets are well-documented and the test validates both digestion results and ordering invariants.
187-204: Well-documented expected peptide data structures.The detailed comments explaining the expected peptide format and mapping to
FragmentIndex::Peptidefields are excellent for maintainability.
257-264: Simple and effective clear() test.The test properly verifies that
clear()resets the internal state by checking that the peptide container is empty.
272-299: Comprehensive querySpectrum() test with charge variations.The test validates spectrum querying across different charges (1-4) with both known and unknown precursor charges, ensuring robust candidate generation.
304-358: Validate updated parameter names align with FragmentIndex implementation.The test uses the new parameter structure (
precursor:isotope_error_min,precursor:isotope_error_max) which aligns with the parameter reorganization mentioned in the PR objectives.The isotope error test properly validates precursor m/z shifts by integer isotope offsets and expects stable peptide window mapping.
364-425: Effective tolerance test with deterministic jitter.The tolerance test uses a clever approach with deterministic m/z jitter (
±0.045 Da) to validate fragment and precursor tolerance handling. The test expects a hit with zero isotope error, which is appropriate given the precursor offset of1.9 Dawithin the2.0 Datolerance.
418-418: isotope_error_ field exists in SpectrumMatch — no action requiredThe struct SpectrumMatch in src/openms/include/OpenMS/ANALYSIS/ID/FragmentIndex.h declares int16_t isotope_error_ (line 68), so the test's hit.isotope_error_ access is valid.
315-316: No change required — parameter names match the implementation.
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp defines defaults for "precursor:isotope_error_min" and "precursor:isotope_error_max" (lines 581–582) and reads them (lines 641–642); the test at src/tests/class_tests/openms/source/FragmentIndex_test.cpp lines 315–316 is correct.
|
test pass. failing is timeout |
|
Any further comments? Otherwise, I would merge. It contains some useful documentation and tests (+ some experimental features) |
|
I guess it's fine since it's an additional experimental feature that does not affect others. Also looks fine at first glance |
Description
New Features:
Documentation:
Tests
Checklist
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
Advanced commands (admins / reviewer only)
Click to expand
/reformat(experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
New Features
Refactor
Documentation
Tests