Skip to content

[FIX] Handle empty ConsensusID searches and preserve run metadata - #10203

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/consensusid-empty-input-1427
Sep 19, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:fix/consensusid-empty-input-1427

Conversation

@timosachsenberg

Copy link
Copy Markdown
Contributor

Valid idXML searches can contain no peptide identifications. ConsensusID currently rejects a single empty run, drops search settings when combining empty runs, and leaves per-spectrum runs without their MS-file metadata. Unannotated featureXML and consensusXML maps can also crash.

This follows the discussion on the closed PR #8250: empty means valid XML without peptide identifications, and search settings and spectra_data must be retained and tested.

  • Preserve the original runs and search settings for entirely empty input in RT/mz mode.
  • Finalize per-spectrum settings for every MS file, including files with no peptide results. Preserve unknown enzyme and charge settings instead of failing or inventing a charge range.
  • Handle maps without identification runs and return a clean error for unsupported input combinations.
  • Cover empty and mixed inputs, both count_empty settings, metadata, and invalid inputs with regression tests.
  • Update AGENTS.md to require a successful local build and relevant tests before opening a PR.

Local validation completed before opening this PR: Linux/GCC 13 Debug build of the OpenMS libraries, ConsensusID, FuzzyDiff, and the relevant class-test executables; the final ConsensusID source was recompiled and linked with the CMake-generated commands. All 48 selected CTest tests passed, including the existing ConsensusID tests and the clustering/consensus class tests. All eight new fixtures and the generated outputs validated against the OpenMS XML schemas. Additional XML checks verified that merged search settings belong to the correct MS file.

Adversarial review found and fixed the missing-enzyme lookup and sentinel-charge-range cases. A baseline binary built from unmodified develop reproduced the single-empty-run failure, metadata loss, and both unannotated-map crashes; the updated binary passed the same cases.

Closes #1427.

Treat valid empty idXML searches as successful inputs, preserve their settings, and finalize per-spectrum metadata independently of peptide results. Guard unannotated maps and invalid input combinations. Require local builds and relevant tests before opening pull requests.

Fixes OpenMS#1427
@timosachsenberg
timosachsenberg marked this pull request as ready for review September 19, 2026 10:59
@timosachsenberg
timosachsenberg merged commit baafdf8 into OpenMS:develop Sep 19, 2026
12 of 13 checks passed

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of df1f221. The core fix is sound and well-targeted — the per-file metadata finalization in particular is the right shape, and the new loop over mzml_to_new_run_idx is a strict superset of the old grouping_per_file keys, so no file loses settings it previously got.

I could not build or run ctest in this environment, so everything below is traced through the loader/writer sources rather than executed. Flagging that explicitly because it means I am not confirming the "all 48 tests passed" claim — only that the assertions are consistent with the code paths they exercise.

Verified as correct

  • Enzyme guard (L495) — genuine crash fix. DigestionEnzymeDB::getEnzyme("") throws ElementNotFound, and final_enz is "" whenever every run reports unknown_enzyme. Skipping the assignment leaves the SearchParameters default, which is Protease("unknown_enzyme", "") — so it really does preserve "unknown" rather than silently inventing an enzyme.
  • Charge guard (L513) — genuine. min_chg/max_chg start at 10000/-10000 and getChargeRange() returns {0,0} for an empty charges string, so the old code emitted the sentinel charges="10000--10000".
  • unique_ptr conversion — fixes a real leak. The pre-existing !pep.hasRT() early return already skipped delete consensus, and the two new return INCOMPATIBLE_INPUT_DATA paths would have added two more.
  • prot_ids.size() < 2 plus the added returns — both OPENMS_LOG_FATAL_ERROR branches previously logged and then kept executing. Clean exit code 11 is a real improvement.
  • Round-trip fixtures — the whitelist-free FuzzyDiff comparisons are sound: IdXMLFile.cpp:107-113 emits byte-identical stylesheet/version/schema lines to what the fixtures carry, FeatureXMLHandler emits no stylesheet line, and ConsensusID never calls addDataProcessing_, so no extra block appears in the output.
  • count_empty assertions — n_other_ids = (count_empty_ ? number_of_runs_ : ids.size()) - 1 yields exactly support 1.0 vs 0.0 as asserted. Note the FORBIDDEN=<PeptideIdentification check holds in both modes for different reasons: RT/mz filters hit-less IDs at L879, per-spectrum does not and is saved only by IdXMLFile.cpp:299-303 skipping them at write time. Worth knowing if that writer behaviour ever changes.
  • if(count_empty) in the CMake foreach correctly evaluates the "false"/"true" loop values as CMake boolean constants, and both helper scripts already exist on develop.

Findings

Three inline, ranked:

  1. L819 — missing space in the fatal error message; the PR fixes the identical defect in the adjacent message but not this one. One-character fix, suggestion attached.
  2. L576-581 — the number_of_runs == 0 guard replaces UB with silent data loss on maps that carry peptide IDs but no runs (reachable: FeatureXMLHandler warns and continues on a dangling identification_run_ref). Also the clear() on this path is either a no-op or destructive, never useful.
  3. L94 — the two modes now disagree on what empty input produces. Probably intended, but if so the @note at L82 ("All protein-level identification results will be lost") is now stale and should be corrected in the same PR.

Plus two non-blocking notes on AGENTS.md (repo-wide policy change bundled into a bug fix) and on the featureXML/consensusXML branches silently dropping extra -in files.


Generated by Claude Code

Comment thread src/topp/ConsensusID.cpp
@@ -801,14 +818,26 @@ class TOPPConsensusID :
{
OPENMS_LOG_FATAL_ERROR << "ConsensusID on idXML without the --per_spectrum flag, expects a single idXML file."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The adjacent string literals concatenate without a separating space, so this prints:

... expects a single idXML file.Please merge the files with IDMerger using its default settings.

This PR fixes exactly this defect in the sibling message 12 lines below (adding the leading space to " with multiple runs."), so this one looks like an oversight rather than a deliberate omission.

The new TOPP_ConsensusID_multiple_files_without_per_spectrum test only matches expects a single idXML file, so it will not catch the run-together text.

Suggested change
OPENMS_LOG_FATAL_ERROR << "ConsensusID on idXML without the --per_spectrum flag, expects a single idXML file."
OPENMS_LOG_FATAL_ERROR << "ConsensusID on idXML without the --per_spectrum flag, expects a single idXML file."
" Please merge the files with IDMerger using its default settings." << std::endl;

Generated by Claude Code

Comment thread src/topp/ConsensusID.cpp
Comment on lines +576 to +581
if (number_of_runs == 0)
{
// Unannotated maps have no identification runs to combine.
input_map.getUnassignedPeptideIdentifications().clear();
return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This guard is right for the case the new tests cover, and it fixes real undefined behaviour — I checked both new fixtures (ConsensusID_no_ids_input.featureXML / .consensusXML) and neither carries any peptide identification, so before this change the loop below hit times_seen[id_mapping[...]] as an out-of-bounds write on an empty vector, followed by *max_element over an empty range.

Two things to consider:

1. A map can have peptide IDs and zero runs, and this path silently discards them.

FeatureXMLHandler.cpp:555-559 loads <PeptideIdentification identification_run_ref="PI_0"> even when no matching <IdentificationRun> exists — it only emits warning(LOAD, "Peptide identification without ProteinIdentification found") and leaves the identifier empty. On such input the guard now returns, the unassigned IDs are deleted outright, the assigned ones are dropped at write time by FeatureXMLHandler.cpp:962-965, and the tool exits EXECUTION_OK. Better than the previous UB, but the user gets a zero exit code and a file with every PSM gone.

Distinguishing the two cases would keep the fix and close the hole — no-op when the map carries no peptide identifications, and warn (or return INCOMPATIBLE_INPUT_DATA) when it does. A fixture with a dangling identification_run_ref would cover it.

2. The clear() has no justification on this path.

The identical call at line 610 is explained by the comment "remove outdated information (protein references will be broken)" — true there, because setProteinIdentifications_ has just replaced the runs. Nothing is replaced here, so this clear() is either a no-op (unannotated map) or data loss (case 1 above); it is never useful.


Generated by Claude Code

Comment thread src/topp/ConsensusID.cpp

@note Currently mzIdentML (mzid) is not directly supported as an input/output format of this tool. Convert mzid files to/from idXML using @ref TOPP_IDFileConverter if necessary.

@note An idXML file without peptide identifications is a valid empty search result. Without @p per_spectrum, its original identification runs and search settings are preserved. With @p per_spectrum, search settings are combined for each originating MS file even if no peptides were identified. Empty runs also remain available for the @p count_empty support calculation when combined with non-empty results.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Worth a deliberate decision before this merges: the two modes now disagree on what empty input produces.

Without per_spectrum, the original runs and their search parameters survive verbatim. With per_spectrum, empty input is still rewritten into ConsensusID for <file> runs (lines 778-785). So the shape of ConsensusID's output depends on whether the input happened to contain PSMs — a per-sample pipeline feeding IDMerger/FDR gets N original runs for samples that came out empty and one merged run for every other sample.

That may well be the intent (it is a fair reading of #1427 and the #8250 discussion), in which case this @note is the right place to record it. But if so, the @note at line 82 needs updating in the same PR:

@note Important: All protein-level identification results will be lost by applying ConsensusID.

That is no longer true on the empty RT/mz path, where the original ProteinHits are preserved by the early return at line 826. Line 82 is currently the only statement a user reads about protein-level output, and it now contradicts the new behaviour.


Generated by Claude Code

Comment thread AGENTS.md
Comment on lines +14 to +16
**Before opening a pull request, always build the changes locally and run the relevant tests.**
Use an out-of-tree build and select the targets and tests affected by the change. Resolve
build or test failures before opening the PR; do not defer this validation to CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Non-blocking, process rather than code: this inverts a repository-wide agent policy inside a ConsensusID bug fix. The deleted line was a hard constraint —

- Build the project unless explicitly asked (extremely resource-intensive)

— under NEVER do these things, and it is replaced by a mandate to always build and test locally. The PR description does disclose it, but the CHANGELOG entry mentions only ConsensusID, so a reviewer approving the C++ fix approves the policy change without it appearing in the release notes, and the two cannot be reverted independently.

Suggest splitting it into its own PR, where it can be discussed on its merits by the people it actually governs.


Generated by Claude Code

Comment thread src/topp/ConsensusID.cpp
FileHandler().loadFeatures(in[0], map, {FileTypes::FEATUREXML});

processFeatureOrConsensusMap_(map, consensus);
processFeatureOrConsensusMap_(map, consensus.get());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Optional, and pre-existing rather than introduced here: this branch and the consensusXML one below load only in[0] and silently discard any further -in files — registerInputFileList_("in", ...) accepts the list and setValidFormats_ accepts featureXML, so nothing upstream rejects it. ConsensusID -in a.featureXML b.featureXML -out out.featureXML processes a.featureXML and returns EXECUTION_OK with no message about b.

Since this PR just added the symmetric INCOMPATIBLE_INPUT_DATA return for the idXML branch, the asymmetry is now conspicuous and cheap to close — an in.size() != 1 guard here and at line 943 would make "report invalid input combinations cleanly" hold for every input type, not just idXML. Reasonable to leave for a follow-up if you would rather keep this PR tight.


Generated by Claude Code

timosachsenberg added a commit that referenced this pull request Sep 22, 2026
…10226)

Adds CHANGELOG entries for merged PRs not yet reflected: FLASHDeconv
negative mass/charge handling and TOPPAS file type detection (#9054),
ConsensusID handling of empty idXML runs (#10203), the Applications
install-component casing fix (#10199), and the implementing PR for the
glycan/glycopeptide fragment generator (#10204). Also fills in the PR
references on two existing Robustness entries (mzIdentML Measure
definitions #10213, XIC chromatogram native IDs #10214) that were
merged without one.


Claude-Session: https://claude.ai/code/session_01CVWcsWWMa4DHbvKMhi9G8n

Co-authored-by: Claude <[email protected]>
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.

ConsensusID crashes on empty input

1 participant