Skip to content

feat(PeptideDataBaseSearchFI): multi-file search with shared fragment index - #9109

Merged
timosachsenberg merged 3 commits into
developfrom
feat/pdbsfi-multi-mzml
Apr 9, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
feat/pdbsfi-multi-mzml

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PeptideDataBaseSearchFI can now process multiple spectrum files (mzML or Bruker .d) against the same FASTA in one invocation. The FragmentIndex is built once via a new prepareContext() step and reused across every input file, eliminating the redundant per-file index-build cost (peptide generation → fragment generation → sorting → bucketing) when batching searches.

Per-file output is written as either idXML or QPX PSM parquet, auto-detected from each -out entry's extension. Mixed formats within a single run are allowed.

Closes the FragmentIndex-reuse / multi-file batch use-case for this tool.

Algorithm changes (PeptideSearchEngineFIAlgorithm)

  • New SearchContext struct (decoy-augmented db + built FragmentIndex).
  • New prepareContext(fasta_db) extracted from the existing search() body.
  • New search(PeakMap&, SearchContext&, ...) overload reusing a pre-built context.
  • New MultiFileSearchResult struct (per-file SearchResults + aggregate).
  • Two new file-list searchWithModificationAnalysis(...) overloads (in-memory FASTA and FASTA file path) — build the index once, loop per file with per-file modification analysis, then run a single aggregate analysis on the pooled PSMs.
  • Single-file fast-path skips the redundant aggregate computation (no wasted PSM deep-copy).
  • Existing single-file search(PeakMap&, fasta_db, ...) and file-based searchWithModificationAnalysis(in_spectra, in_db, ...) refactored into thin wrappers — no behavior change for existing callers (verified by 10 byte-identical regression tests).
  • Per-scan top-hit log demoted from INFO to DEBUG (multi-file mode would otherwise emit one line per scan per input).

TOPP tool changes (PeptideDataBaseSearchFI)

  • -in and -out are now lists; -database stays a single FASTA.
  • Per-file extension dispatch: .idXML → FileHandler::storeIdentifications; .parquet → QPXFile::exportToParquet.
  • New advanced -out_mod_analysis_dir <dir> writes per-file (basename-stemmed) and aggregate modification-analysis TSVs in open-search mode. Uses registerOutputDir_ / getOutputDirOption so the directory is auto-created. When set, per-file tables use each input file's basename (works for both mzML and .d inputs).
  • Pre-flight validation: matching -in/-out list lengths, recognised output extensions, basename-collision detection (refuses to overwrite when two inputs share a stem or collide with the reserved aggregate name).
  • Explicit warning when -out_mod_analysis_dir is set in closed-search mode (precursor tolerance ≤ 1 Da / ≤ 1000 ppm).
  • Per-file failures are logged but don't abort remaining files; final summary line + INTERNAL_ERROR exit code if any file failed.

Tests

  • Class test: new sections verifying (a) prepareContext + context-based search() produces the same PSMs as the single-shot search() and that the same context can be reused for a second search; (b) the multi-file overload's input-validation paths (Exception::InvalidParameter on length mismatch, INPUT_FILE_EMPTY on empty list).
  • TOPP integration test: new TOPP_PeptideDataBaseSearchFI_3_multi runs the tool with two mzML inputs (the existing SimpleSearchEngine_1.mzML twice for simplicity) and one idXML + one parquet output. The idXML is diffed against the existing _1 reference (same input → same output, proving the multi-file path is equivalent to single-file). The parquet output is smoke-tested with cmake -E sha256sum (fails if missing).
  • All 10 pre-existing tests pass byte-identically after the algorithm refactor (_1, _2, _DDA, _FalseDiscoveryRate_DDA, write-INI, write-CTD, class test, plus the 3 new ones → 13/13).

Test plan

  • cmake --build OpenMS-build -j$(nproc) — clean
  • ctest --test-dir OpenMS-build -R 'PeptideDataBaseSearchFI|PeptideSearchEngineFIAlgorithm' — 13/13 pass
  • Existing single-file tests produce byte-identical idXML output as before the refactor
  • New _3_multi test produces matching idXML for the first input and a non-empty parquet for the second
  • Manual sanity run on a non-trivial dataset to confirm "Building fragment index..." appears once and per-file scoring stages appear N times

Notes / follow-ups (not in this PR)

  • pyOpenMS bindings for the new SearchContext / MultiFileSearchResult / prepareContext / multi-file searchWithModificationAnalysis overloads (legacy single-file paths still bound).
  • Framework-level fix in TOPPBase::fileParamValidityCheck_ to add an OUTPUT_FILE_LIST branch (currently only INPUT_FILE_LIST is checked, so per-entry setValidFormats_ validation is silently skipped for output lists). This tool's local pre-flight loop covers the gap for now; affects 4 other tools (FileMerger, OpenSwathDIAPreScoring, QualityControl, SpectraSTSearchAdapter).
  • Class test parametrization over decoys=true to also exercise the decoy-generation path inside prepareContext.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Multi-file peptide search: batch processing of multiple spectrum files with per-file and pooled aggregate modification analysis.
    • Parquet output support alongside idXML; per-file output selection and optional modification-analysis output directory.
    • Reuse of prebuilt search context (database/index) to speed repeated searches; input/output count validation and output-name collision checks.
  • Tests

    • Added tests for context reuse, multi-file search behavior, input validation, and empty-input handling.

timosachsenberg and others added 2 commits April 8, 2026 18:33
… index

Allow PeptideDataBaseSearchFI to process multiple mzML files against the
same FASTA in one invocation, building the FragmentIndex once and reusing
it across all input files. Per-file output is written as either idXML or
QPX PSM parquet, auto-detected from each -out entry's extension; mixed
formats within one run are allowed.

Algorithm:
- New SearchContext (decoy-augmented db + built FragmentIndex) and
  prepareContext() extracted from the existing search() body.
- New search(spectra, ctx, ...) overload reusing a pre-built context.
- New MultiFileSearchResult and two file-list searchWithModificationAnalysis
  overloads producing per-file SearchResults plus an aggregate analysis on
  pooled PSMs. Single-file fast-path skips the redundant aggregate.
- Existing single-file search() and file-based searchWithModificationAnalysis
  refactored into thin wrappers; behavior preserved (all 10 pre-existing
  tests pass byte-identically).

Tool:
- -in/-out are now lists; per-file extension dispatch to idXML or parquet.
- New advanced -out_mod_analysis_dir writes per-file (basename-stemmed) and
  aggregate modification-analysis TSVs.

Tests:
- Class test: prepareContext + context-search equivalence to single-shot
  search; multi-file overload validation (length mismatch, empty list).
- TOPP_PeptideDataBaseSearchFI_3_multi: two mzML inputs with idXML +
  parquet outputs (idXML diffed against existing _1 reference, parquet
  smoke-tested via cmake -E sha256sum).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Reviewer feedback on commit 9d83fb5:

Algorithm:
- searchWithModificationAnalysis (multi-file): when all per-file runs fail,
  propagate the first non-OK per-file exit code into aggregate.exit_code
  instead of unconditionally setting UNEXPECTED_RESULT (which has a
  specific PeptideIndexing-failure meaning).
- Single-file fast path: skip the wasted aggregate deep-copy (per_file[0]
  was being copied into aggregate just so the single-file file-based
  wrapper could discard it). Aggregate is now left almost-empty
  (is_open_search + exit_code only) when the input list has one entry;
  callers should use per_file[0]. Documented on MultiFileSearchResult.
- Demote per-scan top-hit log line in postProcessHits_ from INFO to DEBUG
  (multi-file mode would otherwise emit one line per scan per input).

TOPP tool:
- -out_mod_analysis_dir now uses registerOutputDir_ + getOutputDirOption
  (was registerOutputPrefix_): the parameter is semantically a directory
  and getOutputDirOption auto-creates it. Pattern: ProteomicsLFQ.cpp:196.
- Pre-flight validate every -out file extension before starting the
  search (registerOutputFileList_ does NOT validate per-entry formats at
  the CLI layer).
- Detect basename collisions in -out_mod_analysis_dir: refuse to run when
  two -in files share a File::stemName, or when an input collides with
  the reserved aggregate stem. Aggregate stem changed from "aggregate" to
  "_aggregate_across_files" to make accidental collisions extremely
  unlikely.
- Warn explicitly when -out_mod_analysis_dir is set in closed-search mode
  (precursor tolerance <= 1 Da / 1000 ppm). The algorithm already logs a
  per-file skip notice; the tool now also tells the user up front.
- Replace any_failure bool with failed_count and emit a final summary log
  line ("N file(s) failing out of M") before returning INTERNAL_ERROR, so
  batch failures are visible at a glance.

All 13 PeptideDataBaseSearchFI / PeptideSearchEngineFIAlgorithm tests
still pass byte-identically.

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

coderabbitai Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aaf861d1-e794-46eb-b59c-99e9290aa009

📥 Commits

Reviewing files that changed from the base of the PR and between 66d6df2 and 85260f5.

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

📝 Walkthrough

Walkthrough

Adds multi-file batch search support to PeptideSearchEngineFIAlgorithm: introduces a SearchContext to cache decoy-augmented FASTA and a prebuilt FragmentIndex, new multi-file searchWithModificationAnalysis overloads that produce per-file and pooled aggregate modification analysis, and updates the TOPP tool for multi-input/multi-output handling and parquet output.

Changes

Cohort / File(s) Summary
Core API
src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
Added MultiFileSearchResult and SearchContext types; prepareContext(...); search(PeakMap&, SearchContext&, ...) overload; two searchWithModificationAnalysis(...) multi-file overloads.
Core Implementation
src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp
Moved decoy generation/index build into prepareContext; added context-reusing search overload; implemented multi-file flow that reuses context for per-file searches and pools PSMs for a single aggregate modification analysis; adjusted logging level.
TOPP Tool
src/topp/PeptideDataBaseSearchFI.cpp
Converted -in/-out to lists, validate counts; support .idXML and .parquet per-file outputs; added -out_mod_analysis_dir, open-search gating, per-file collision checks for mod-analysis base names; wrote per-file failure handling and changed output writing flow to iterate per result.
Unit Tests
src/tests/class_tests/openms/source/PeptideSearchEngineFIAlgorithm_test.cpp
Added tests: context-reuse equivalence and reusability; multi-file in-memory FASTA overload parameter validation and empty-input handling.
Integration Tests / CTest
src/tests/topp/CMakeLists.txt
Added multi-file integration CTest (TOPP_PeptideDataBaseSearchFI_3_multi) with idXML fuzzy-diff validation and parquet SHA256 check.

Sequence Diagram

sequenceDiagram
    rect rgba(220,230,241,0.5)
    participant Tool as TOPP<br/>PeptideDataBaseSearchFI
    participant SE as PeptideSearchEngineFIAlgorithm
    participant Ctx as SearchContext
    participant FI as FragmentIndex
    participant ModA as ModificationAnalysis
    end

    Tool->>SE: prepareContext(fasta_db)
    activate SE
    SE->>SE: generate decoys (if enabled)
    SE->>FI: build FragmentIndex
    FI-->>SE: index
    SE-->>Ctx: return SearchContext{db, index}
    deactivate SE

    loop for each spectrum file
        Tool->>SE: search(spectra_i, Ctx, ...)
        activate SE
        SE->>FI: reuse FragmentIndex
        SE-->>Tool: per-file SearchResult_i
        deactivate SE
    end

    Tool->>SE: pool PSMs from successful runs
    activate SE
    SE->>ModA: run aggregate modification analysis on pooled PSMs
    ModA-->>SE: aggregate modification results
    SE-->>Tool: MultiFileSearchResult{per_file[], aggregate}
    deactivate SE
Loading

Possibly related PRs

Suggested labels

enhancement, Review effort [1-5]: 3

Suggested reviewers

  • cbielow
  • jpfeuffer

Poem

🐇 Hops of code in tidy rows,

One context built, the indexing flows.
Files in batches, results combined,
Pooled analyses neatly aligned.
A rabbit cheers: reuse saves time!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately and concisely summarizes the main change: multi-file search capability with a shared fragment index optimization.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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/pdbsfi-multi-mzml

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.

🧹 Nitpick comments (1)
src/tests/topp/CMakeLists.txt (1)

2926-2932: Assert parquet semantics here, not just path existence.

cmake -E sha256sum only proves that something was written to the .parquet path. A regression in the new per-file format dispatch could still write the wrong payload there and this test would pass, especially since both -in entries use the same mzML. Please replace this with a semantic check (for example, parquet magic bytes or a read-back step) so the mixed-output path is actually covered.

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

In `@src/tests/topp/CMakeLists.txt` around lines 2926 - 2932, Replace the current
content-only existence check for the parquet output
("TOPP_PeptideDataBaseSearchFI_3_multi_parquet_out" which currently invokes
${CMAKE_COMMAND} -E sha256sum on
${TESTS_TEMP_DIR}/PeptideDataBaseSearchFI_3_multi_b.tmp.parquet) with a semantic
validation: read the file and assert parquet magic bytes (\"PAR1\"
header/footer) or perform a minimal read-back (e.g., call a small
parquet-inspection tool or a TOPP utility that can open parquet) and verify
expected schema/column names or row count; update the test command to run that
validation and keep the DEPENDS property intact for
"TOPP_PeptideDataBaseSearchFI_3_multi".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/tests/topp/CMakeLists.txt`:
- Around line 2926-2932: Replace the current content-only existence check for
the parquet output ("TOPP_PeptideDataBaseSearchFI_3_multi_parquet_out" which
currently invokes ${CMAKE_COMMAND} -E sha256sum on
${TESTS_TEMP_DIR}/PeptideDataBaseSearchFI_3_multi_b.tmp.parquet) with a semantic
validation: read the file and assert parquet magic bytes (\"PAR1\"
header/footer) or perform a minimal read-back (e.g., call a small
parquet-inspection tool or a TOPP utility that can open parquet) and verify
expected schema/column names or row count; update the test command to run that
validation and keep the DEPENDS property intact for
"TOPP_PeptideDataBaseSearchFI_3_multi".

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 962cc4f9-fa13-4800-abf5-25822908a904

📥 Commits

Reviewing files that changed from the base of the PR and between ef46507 and 66d6df2.

📒 Files selected for processing (5)
  • src/openms/include/OpenMS/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.h
  • src/openms/source/ANALYSIS/ID/PeptideSearchEngineFIAlgorithm.cpp
  • src/tests/class_tests/openms/source/PeptideSearchEngineFIAlgorithm_test.cpp
  • src/tests/topp/CMakeLists.txt
  • src/topp/PeptideDataBaseSearchFI.cpp

@timosachsenberg timosachsenberg changed the title feat(PeptideDataBaseSearchFI): multi-mzML search with shared fragment index feat(PeptideDataBaseSearchFI): multi-file search with shared fragment index Apr 9, 2026
…nd .d are supported

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg merged commit 602257d into develop Apr 9, 2026
13 of 14 checks passed
@timosachsenberg
timosachsenberg deleted the feat/pdbsfi-multi-mzml branch April 9, 2026 06:47
github-actions Bot pushed a commit that referenced this pull request Apr 10, 2026
Add missing entries for three features merged after last changelog sync:
- PeptideDataBaseSearchFI multi-file search with shared fragment index (#9109)
- Semi-tryptic and non-specific digestion in PeptideDataBaseSearchFI and
  SimpleSearchEngine via new peptide:enzyme_specificity parameter (#9112)
- New PSM annotation options (num_matched_peaks, matched_b_ions,
  matched_y_ions, longest_peptide_ion_sequence, fragment_annotation)
  in PeptideDataBaseSearchFI and SimpleSearchEngine, with parquet export (#9117)

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 10, 2026
Add missing entries for three features merged after last changelog sync:
- PeptideDataBaseSearchFI multi-file search with shared fragment index (#9109)
- Semi-tryptic and non-specific digestion in PeptideDataBaseSearchFI and
  SimpleSearchEngine via new peptide:enzyme_specificity parameter (#9112)
- New PSM annotation options (num_matched_peaks, matched_b_ions,
  matched_y_ions, longest_peptide_ion_sequence, fragment_annotation)
  in PeptideDataBaseSearchFI and SimpleSearchEngine, with parquet export (#9117)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Apr 15, 2026
- Updated ProSE multi-file search entry (#9109) to remove now-inaccurate
  reference to -out accepting file lists
- Added BREAKING entry for ProSE output parameter overhaul (#9146):
  -out replaced by -out_idxml, -out_qpx, -out_parquet with per-file
  and merged QPX/internal Parquet output

Co-authored-by: Copilot <[email protected]>
timosachsenberg pushed a commit that referenced this pull request Apr 15, 2026
- Updated ProSE multi-file search entry (#9109) to remove now-inaccurate
  reference to -out accepting file lists
- Added BREAKING entry for ProSE output parameter overhaul (#9146):
  -out replaced by -out_idxml, -out_qpx, -out_parquet with per-file
  and merged QPX/internal Parquet output

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

1 participant