Skip to content

feat: runtime search diagnostics and tolerance estimation in PeptideSearchEngineFI - #9121

Merged
timosachsenberg merged 4 commits into
developfrom
feat/fi-search-diagnostics
Apr 10, 2026
Merged

timosachsenberg merged 4 commits into
developfrom
feat/fi-search-diagnostics

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Log a search summary after every search: MS2 spectra count, PSM count, MS2 ID rate, unique peptides/proteins, missed cleavages distribution
  • Log per-run tolerance estimation: median + MAD of precursor and fragment errors (ppm), with recommended tolerance (ceil(median + 3*MAD)), plus configured tolerance for comparison. Requires ≥10 PSMs (skipped otherwise). Follows the InternalCalibration.cpp pattern.
  • Addresses items #\10 (runtime summary statistics) and #\11 (per-run tolerance estimation) from PeptideDataBaseSearchFI: feature gap analysis vs Comet/Sage/MSFragger #9108

Test plan

  • All 11 PeptideDataBaseSearchFI / PeptideSearchEngineFIAlgorithm tests pass
  • Smoke test: diagnostics output verified with test data (3 PSMs → summary shown, tolerance estimation correctly skipped due to <10 PSMs)
  • Verify with real-world data that tolerance estimation produces sensible recommendations

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Enhanced search diagnostics: detailed logging of spectrum and identification summaries (MS2 count, PSMs, unique peptides/proteins).
    • Missed-cleavage distribution reporting based on configured enzyme specificity.
    • Per-run tolerance estimation with robust-statistic recommendations for precursor and fragment errors when sufficient data; current tolerances are also reported.

…earchEngineFI

Log a search summary (PSM count, MS2 ID rate, unique peptides/proteins,
missed cleavages distribution) and per-run tolerance estimation
(median + MAD of precursor/fragment errors with recommended tolerance)
after every search. Addresses items #10 and #11 from #9108.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4a56774a-dcfd-47f1-902a-86e7d676e534

📥 Commits

Reviewing files that changed from the base of the PR and between 2202771 and 8dc1a7e.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp

📝 Walkthrough

Walkthrough

Added a protected helper logSearchDiagnostics_ to PeptideSearchEngineFIAlgorithm and invoked it at the end of the in-memory search(...) flow; it logs MS2 spectrum and peptide-identification metrics, missed-cleavage distribution, and estimates per-run precursor/fragment tolerances from error metavalue samples.

Changes

Cohort / File(s) Summary
Search diagnostics
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h, src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp
Added protected method logSearchDiagnostics_(const PeakMap&, const std::vector<ProteinIdentification>&, const PeptideIdentificationList&) const and called it from search(...). Logs MS2 count, peptide ID count, unique peptide/protein counts, missed-cleavage distribution, computes per-run precursor/fragment error samples (median, MAD) and recommends tolerances, and prints configured tolerances.

Possibly related PRs

Poem

🐰 I hopped through spectra, soft and spry,

Counted PSMs beneath the sky,
Missed cleavages and errors I weigh,
Medians and MADs to guide the way,
A tiny rabbit logs your day.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: adding runtime search diagnostics and per-run tolerance estimation to PeptideSearchEngineFI, which matches the core functionality added across both modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fi-search-diagnostics

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h (1)

435-438: Use a full Doxygen block for the new helper declaration.

Please replace the single-line comment with a Doxygen block that includes @brief (and a short detail paragraph) for this method declaration.

As per coding guidelines "Use @brief plus blank line plus detailed description in Doxygen comments; required @brief tag".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h`
around lines 435 - 438, Replace the single-line comment for the helper method
logSearchDiagnostics_ with a full Doxygen comment block containing an `@brief` tag
and a short detailed paragraph on the next line; specifically, above the
declaration of void logSearchDiagnostics_(const PeakMap& spectra, const
std::vector<ProteinIdentification>& protein_ids, const
PeptideIdentificationList& peptide_ids) const; add a /** `@brief` ... */ style
block that includes `@brief` followed by a blank line and then a concise detailed
description of what the method logs (search summary statistics and per-run
tolerance estimation) to satisfy the project's Doxygen style requirement.
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (1)

1290-1342: Prefer \n over std::endl in the new diagnostics logs.

The new block uses std::endl repeatedly, which flushes unnecessarily and adds overhead in heavy logging paths.

As per coding guidelines "Avoid std::endl for performance reasons; prefer \n in C++".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around
lines 1290 - 1342, Replace all occurrences of std::endl in the new diagnostics
logging block with '\n' to avoid unnecessary flushes; specifically update the
OPENMS_LOG_INFO streams in the block that prints the search summary, missed
cleavages, tolerance estimation and the final summary (the lines that currently
end with << std::endl), keeping existing manipulators (std::fixed,
std::setprecision) unchanged so formatting is preserved.
🤖 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/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp`:
- Around line 1278-1285: The diagnostics' tolerance estimation is incorrectly
gated on whether PSM annotation keys PRECURSOR_ERROR_PPM_USERPARAM and
FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM exist, so when annotate:PSM is disabled the
precursor_errors and fragment_errors vectors remain empty; change the logic in
PeptideSearchEngineFIAlgorithm.cpp (around the top.metaValueExists checks and
the code that fills precursor_errors and fragment_errors) to always compute and
push the precursor and fragment error values during post-processing (e.g.,
compute values regardless of top.metaValueExists and use the computed doubles to
populate precursor_errors and fragment_errors), and only conditionally attach
these values to PSM annotations when
PRECURSOR_ERROR_PPM_USERPARAM/FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM are enabled so
diagnostics no longer depend on annotation toggles.
- Around line 1251-1254: The log currently uses peptide_ids.size() (number of
identified spectra) for "PSMs", which underreports when multiple hits per
spectrum are kept; replace that with a count of all PeptideHit entries by
summing getHits().size() across peptide_ids (e.g. accumulate over peptide_ids
calling getHits().size()) so num_identified reflects total PSMs; apply the same
change where the PSM count is computed later (the other occurrence around the
num_identified calculation) and keep the variable name (num_identified) and the
log label "PSMs" intact so report:top_hits > 1 is handled correctly.

---

Nitpick comments:
In `@src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h`:
- Around line 435-438: Replace the single-line comment for the helper method
logSearchDiagnostics_ with a full Doxygen comment block containing an `@brief` tag
and a short detailed paragraph on the next line; specifically, above the
declaration of void logSearchDiagnostics_(const PeakMap& spectra, const
std::vector<ProteinIdentification>& protein_ids, const
PeptideIdentificationList& peptide_ids) const; add a /** `@brief` ... */ style
block that includes `@brief` followed by a blank line and then a concise detailed
description of what the method logs (search summary statistics and per-run
tolerance estimation) to satisfy the project's Doxygen style requirement.

In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp`:
- Around line 1290-1342: Replace all occurrences of std::endl in the new
diagnostics logging block with '\n' to avoid unnecessary flushes; specifically
update the OPENMS_LOG_INFO streams in the block that prints the search summary,
missed cleavages, tolerance estimation and the final summary (the lines that
currently end with << std::endl), keeping existing manipulators (std::fixed,
std::setprecision) unchanged so formatting is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 003b231e-ed29-4096-b03e-0000bea0a8bf

📥 Commits

Reviewing files that changed from the base of the PR and between 248e51a and 52ea31f.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp

Comment on lines +1278 to +1285
if (top.metaValueExists(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))
{
precursor_errors.push_back(fabs(static_cast<double>(top.getMetaValue(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))));
}
if (top.metaValueExists(Constants::UserParam::FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM))
{
fragment_errors.push_back(static_cast<double>(top.getMetaValue(Constants::UserParam::FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM)));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Tolerance estimation is coupled to optional PSM annotation settings.

If users disable PRECURSOR_ERROR_PPM_USERPARAM / FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM in annotate:PSM, the error vectors stay empty and estimation is skipped even with enough identified spectra. The diagnostics feature should not depend on output-annotation toggles.

🔧 Suggested direction
-      if (top.metaValueExists(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))
-      {
-        precursor_errors.push_back(fabs(static_cast<double>(top.getMetaValue(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))));
-      }
+      if (top.metaValueExists(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))
+      {
+        precursor_errors.push_back(fabs(static_cast<double>(
+          top.getMetaValue(Constants::UserParam::PRECURSOR_ERROR_PPM_USERPARAM))));
+      }
+      else if (pid.getMZ() > 0.0 && top.getCharge() > 0)
+      {
+        const double theo_mz = top.getSequence().getMZ(top.getCharge());
+        precursor_errors.push_back(fabs(Math::getPPM(pid.getMZ(), theo_mz)));
+      }

For fragment error, consider computing/storing it unconditionally in post-processing (even if not requested for final PSM annotation), so diagnostics always has data.

Also applies to: 1320-1338

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around
lines 1278 - 1285, The diagnostics' tolerance estimation is incorrectly gated on
whether PSM annotation keys PRECURSOR_ERROR_PPM_USERPARAM and
FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM exist, so when annotate:PSM is disabled the
precursor_errors and fragment_errors vectors remain empty; change the logic in
PeptideSearchEngineFIAlgorithm.cpp (around the top.metaValueExists checks and
the code that fills precursor_errors and fragment_errors) to always compute and
push the precursor and fragment error values during post-processing (e.g.,
compute values regardless of top.metaValueExists and use the computed doubles to
populate precursor_errors and fragment_errors), and only conditionally attach
these values to PSM annotations when
PRECURSOR_ERROR_PPM_USERPARAM/FRAGMENT_ERROR_MEDIAN_PPM_USERPARAM are enabled so
diagnostics no longer depend on annotation toggles.

timosachsenberg and others added 2 commits April 10, 2026 07:54
peptide_ids.size() counts identified spectra, not total PSM hits.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Compute precursor error inline in logSearchDiagnostics_() instead of
reading from annotation metavalues. This ensures tolerance estimation
works even if annotate:PSM is customized to exclude precursor error.
Fragment error still uses the metavalue (computing it inline would
require expensive spectrum alignment).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (1)

1251-1254: ⚠️ Potential issue | 🟠 Major

Add explicit PSM counting (current summary only counts identified spectra).

Line 1253 (peptide_ids.size()) is the number of identified spectra, not total PSM hits. This misses the requested PSM metric when multiple hits per spectrum are retained.

🔧 Suggested fix
-    Size num_identified = peptide_ids.size();
+    Size num_identified_spectra = peptide_ids.size();
+    Size num_psms = 0;
+    for (const auto& pid : peptide_ids)
+    {
+      num_psms += pid.getHits().size();
+    }
...
-    OPENMS_LOG_INFO << "[PDBS-FI]   Matched spectra:      " << num_identified << std::endl;
+    OPENMS_LOG_INFO << "[PDBS-FI]   Matched spectra:      " << num_identified_spectra << std::endl;
+    OPENMS_LOG_INFO << "[PDBS-FI]   PSMs:                " << num_psms << std::endl;
...
-                      << std::fixed << std::setprecision(1) << (100.0 * num_identified / num_ms2) << "%" << std::endl;
+                      << std::fixed << std::setprecision(1) << (100.0 * num_identified_spectra / num_ms2) << "%" << std::endl;

Also applies to: 1295-1301

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around
lines 1251 - 1254, The code currently uses peptide_ids.size() (number of
identified spectra) but needs an explicit PSM count; iterate over peptide_ids
and sum id.getHits().size() to compute num_psms (e.g., Size num_psms =
std::accumulate(peptide_ids.begin(), peptide_ids.end(), 0u, [](Size acc, const
PeptideIdentification& id){ return acc + id.getHits().size(); })), then use
num_psms wherever a PSM metric is required (replace uses of peptide_ids.size()
at the blocks around the code in PeptideSearchEngineFIAlgorithm.cpp, including
the other occurrence around lines ~1295-1301) so both identified spectra and
total PSM hits are reported correctly.
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp (1)

1294-1347: Replace std::endl in the new diagnostics logger.

The new log block uses repeated std::endl; prefer '\n' to avoid unnecessary stream flushes on frequent logging paths.

As per coding guidelines, "Avoid std::endl for performance reasons; prefer \n in C++".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp` around
lines 1294 - 1347, The logging block in PeptideSearchEngineFIAlgorithm (the
OPENMS_LOG_INFO calls in the search summary / tolerance estimation section) uses
multiple std::endl which forces flushes; replace each trailing std::endl with
'\n' (e.g., the OPENMS_LOG_INFO lines printing "[PDBS-FI] ============ Search
Summary ============", MS2 spectra, MS2 ID rate, Unique peptides/proteins,
Missed cleavages line, the tolerance estimation header and the
precursor/fragment recommendation lines, and the final divider) so the messages
end with '\n' instead of std::endl; keep the same formatting/precision and do
not add explicit flushes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp`:
- Around line 1251-1254: The code currently uses peptide_ids.size() (number of
identified spectra) but needs an explicit PSM count; iterate over peptide_ids
and sum id.getHits().size() to compute num_psms (e.g., Size num_psms =
std::accumulate(peptide_ids.begin(), peptide_ids.end(), 0u, [](Size acc, const
PeptideIdentification& id){ return acc + id.getHits().size(); })), then use
num_psms wherever a PSM metric is required (replace uses of peptide_ids.size()
at the blocks around the code in PeptideSearchEngineFIAlgorithm.cpp, including
the other occurrence around lines ~1295-1301) so both identified spectra and
total PSM hits are reported correctly.

---

Nitpick comments:
In `@src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp`:
- Around line 1294-1347: The logging block in PeptideSearchEngineFIAlgorithm
(the OPENMS_LOG_INFO calls in the search summary / tolerance estimation section)
uses multiple std::endl which forces flushes; replace each trailing std::endl
with '\n' (e.g., the OPENMS_LOG_INFO lines printing "[PDBS-FI] ============
Search Summary ============", MS2 spectra, MS2 ID rate, Unique
peptides/proteins, Missed cleavages line, the tolerance estimation header and
the precursor/fragment recommendation lines, and the final divider) so the
messages end with '\n' instead of std::endl; keep the same formatting/precision
and do not add explicit flushes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cc5569e0-a901-4860-92da-d923a9048c89

📥 Commits

Reviewing files that changed from the base of the PR and between 58bef87 and 2202771.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp

PeptideHits with unresolved precursor charge (0) would cause getMZ()
to throw. Skip these hits in the precursor error collection.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg merged commit 2bd80d8 into develop Apr 10, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the feat/fi-search-diagnostics branch April 10, 2026 08:30
github-actions Bot pushed a commit that referenced this pull request Apr 11, 2026
Add missing changelog entries for commits merged after the last sync:
- #9127: Fix LinearResampler right_index bounds clamping (intensity spike bug)
- #9126: CometAdapter Bruker .d DDA-PASEF input support
- #9121: PeptideDataBaseSearchFI runtime search diagnostics and tolerance estimation
- #9122: PeptideDataBaseSearchFI automatic mass accuracy calibration (two-pass search)
- #9123: PeptideDataBaseSearchFI protein-level FDR (picked-protein)
- #9129: OpenSwathWorkflow Bruker DIA MS2 frame aggregation, denoising, and streaming

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 11, 2026
Add missing changelog entries for commits merged after the last sync:
- #9127: Fix LinearResampler right_index bounds clamping (intensity spike bug)
- #9126: CometAdapter Bruker .d DDA-PASEF input support
- #9121: PeptideDataBaseSearchFI runtime search diagnostics and tolerance estimation
- #9122: PeptideDataBaseSearchFI automatic mass accuracy calibration (two-pass search)
- #9123: PeptideDataBaseSearchFI protein-level FDR (picked-protein)
- #9129: OpenSwathWorkflow Bruker DIA MS2 frame aggregation, denoising, and streaming

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot mentioned this pull request Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant