Skip to content

feat(MGF): support SEQ= sequence-query field on read and write - #9186

Merged
timosachsenberg merged 2 commits into
developfrom
claude/mgf-seq-peptide-encoding-bxX8j
Apr 20, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
claude/mgf-seq-peptide-encoding-bxX8j

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MascotGenericFile previously ignored the SEQ= field on load and never emitted it on store, so peptide-sequence annotations could not survive a pyOpenMS MGF round-trip. This PR adds first-class SEQ= support in both directions.

Background — what is SEQ in MGF?

Per the Mascot MGF specification and the Sequence Query docs:

  • SEQ= is a local (per-query) parameter that appears inside a BEGIN IONS ... END IONS block, alongside COMP=, TAG=, ETAG=.
  • The value is a peptide sequence in one-letter code — used by Mascot as a sequence-query filter.
  • The spec explicitly allows multiple SEQ= lines per query; each acts as an independent filter.

Other tools already treat it as a standard local field — e.g. pyteomics mgf exposes it as 'seq' in the per-spectrum params dict, and Mascot's own ms_inputquery surfaces it via dedicated accessors.

Changes

Read — src/openms/include/OpenMS/FORMAT/MascotGenericFile.h (getNextSpectrum_):

  • New branch parses SEQ= and stores it on the MSSpectrum as the meta value "SEQ".
  • A single SEQ is kept as a String; multiple SEQ lines per query are accumulated into a StringList under the same key.
  • Any pre-existing "SEQ" meta value on the reusable spectrum object is cleared at the top of getNextSpectrum_ (same pattern as TITLE) so sequences cannot bleed between consecutive spectra.

Write — src/openms/source/FORMAT/MascotGenericFile.cpp (writeSpectrum):

  • After CHARGE, emit one SEQ= line per entry when the meta value is a StringList, or a single SEQ= line when it's a String. Works in both compact and full modes.

Tests — src/tests/class_tests/openms/source/MascotGenericFile_test.cpp:

  • Single-SEQ round-trip (load → store → load).
  • Multi-SEQ StringList round-trip (three sequences preserved and re-emitted).
  • Programmatic write from a freshly built MSSpectrum with setMetaValue("SEQ", "PEPTIDER").
  • Cross-spectrum bleed guard: second spectrum without SEQ must not inherit the first spectrum's SEQ.

Design notes / rejected alternatives

  • Key name "SEQ" — mirrors the MGF field directly, matching the existing convention in this file for "TITLE", "IONMODE", "SOURCE_INSTRUMENT", etc. No new Constants::UserParam::* entry was added, since the metabolomics constants (MSM_*) are tied to MetaboliteSpectralMatcher and SEQ is a proteomics concept. Happy to add a constant if reviewers prefer.
  • PeptideIdentification — considered threading SEQ through attached PeptideIdentification/PeptideHit objects (where a real AASequence lives), but that conflates a raw MGF annotation with an OpenMS search result and would require deciding score/score-type semantics on round-trip. A meta value is the least-invasive, lossless option.
  • Scope — only SEQ is implemented here. COMP, TAG, ETAG are structurally similar and could be added in a follow-up with the same pattern.

Test plan

  • CI builds on Linux/macOS/Windows.
  • MascotGenericFile_test passes (four new sub-blocks inside a new START_SECTION).
  • No change in behaviour for MGF files that do not contain SEQ=.

Note: I was unable to run the build locally in this environment (no OpenMS-build/ tree present), so the above is verified by code review only and I'm relying on CI to confirm compilation and test pass.

https://claude.ai/code/session_01LpLkMxcZnXc8eCTLx5uXCB

Summary by CodeRabbit

  • New Features

    • Parser recognizes and stores SEQ= sequence-query fields as a list in spectrum metadata
    • Writer emits one SEQ= line per stored sequence when SEQ metadata is present
    • Multiple SEQ values per spectrum are accumulated and preserved
  • Bug Fixes

    • SEQ metadata is cleared at the start of each spectrum to prevent cross-spectrum leakage
  • Tests

    • Added round-trip and isolation tests for SEQ parsing and storage

The Mascot Generic Format spec defines SEQ= as a per-query local
parameter (alongside COMP/TAG/ETAG) carrying a peptide sequence in
one-letter code - see matrixscience.com/help/data_file_help.html and
the sq_help sequence-query docs. OpenMS's MascotGenericFile silently
dropped SEQ on load and never emitted it on store, so peptide-sequence
annotations could not survive a pyOpenMS MGF round-trip.

Changes:
- Parse SEQ= in getNextSpectrum_() and store on MSSpectrum under the
  meta key "SEQ". A single SEQ is kept as a String; multiple SEQ lines
  per query (explicitly allowed by the Mascot spec, since each SEQ is
  an independent sequence filter) are accumulated into a StringList.
- Emit SEQ= in writeSpectrum() after CHARGE, one line per entry when
  the meta value is a StringList. Works in both compact and full modes.
- Clear a leftover "SEQ" meta value at the start of each spectrum parse
  so sequences cannot bleed between consecutive spectra (the load()
  template reuses one spectrum object across iterations).
- Unit tests cover: single-SEQ round-trip, multi-SEQ StringList
  round-trip, programmatic write from a freshly-built spectrum, and
  the cross-spectrum bleed guard.

https://claude.ai/code/session_01LpLkMxcZnXc8eCTLx5uXCB
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Claude

Please consider applying the following patch:

--- AUTHORS	2026-04-18 17:28:49.394628890 +0000
+++ AUTHORS.new	2026-04-18 17:28:54.045634772 +0000
@@ -23,6 +23,7 @@
  - Chris Bauer
  - Chris Bielow
  - Christian Ehrlich
+ - Claude
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

if (spec.metaValueExists("SEQ"))
{
const DataValue& seq_value = spec.getMetaValue("SEQ");
if (seq_value.valueType() == DataValue::STRING_LIST)

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.

Always store as stringlist. A change of interface depending on file content is just making it harder to use and adds potential for errors

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.

Done — read and write paths now always use StringList. The branch on valueType() is gone in both directions.

// an independent sequence filter). A single SEQ is stored as a
// String meta value; multiple SEQ lines are accumulated into a
// StringList under the same "SEQ" key.
String tmp = line.substr(4);

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.

Use Stringview? And think of a better name (sequence?)

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.

Renamed tmp → sequence. Left it as String rather than StringView: every other branch in this parse block uses String tmp = line.substr(...), and setMetaValue takes String, so a one-off StringView here would be inconsistent without saving an allocation. Happy to switch all of them in a follow-up if you'd like the whole block migrated.

mgf_file.load(tmp_in, exp);

TEST_EQUAL(exp.size(), 2)
TEST_EQUAL(exp[0].metaValueExists("SEQ"), true)

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.

TEST_TRUE
TEST_FALSE

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.

Replaced all TEST_EQUAL(..., true/false) in the new SEQ section with TEST_TRUE / TEST_FALSE.

@timosachsenberg
timosachsenberg marked this pull request as ready for review April 19, 2026 13:41
@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Extended MGF parsing to recognize per-spectrum SEQ= lines (stored as a StringList), clear SEQ at each spectrum start to avoid carry-over, and emit one SEQ= line per sequence when writing spectra.

Changes

Cohort / File(s) Summary
SEQ Field Parsing
src/openms/include/OpenMS/FORMAT/MascotGenericFile.h
Clear existing "SEQ" meta at spectrum start; parse SEQ= lines within BEGIN IONS/END IONS and accumulate values into a StringList (first occurrence converts/initializes, later occurrences append).
SEQ Field Emission
src/openms/source/FORMAT/MascotGenericFile.cpp
When spec.metaValueExists("SEQ"), write one SEQ=<sequence> line per entry from spec.getMetaValue("SEQ").toStringList() during spectrum output (placed after CHARGE handling).
Tests
src/tests/class_tests/openms/source/MascotGenericFile_test.cpp
Added tests for single/multiple SEQ= parsing, order-preserving accumulation, store round-trip (standard and compact modes), and ensuring spectra do not inherit SEQ from previous spectra; added include for ListUtils.h.

Possibly related PRs

Suggested labels

Review effort 1/5

Poem

🐇
I hop through MGF lines bright and neat,
SEQ strings gathered, never meet-repeat,
Cleared each dawn, then saved with care,
One per line — a tidy rabbit's share,
Hooray for spectra, ordered and complete!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding support for the SEQ= sequence-query field in MGF parsing and writing. It is concise, specific, and accurately reflects the primary objective of the pull request.

✏️ 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 claude/mgf-seq-peptide-encoding-bxX8j

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/class_tests/openms/source/MascotGenericFile_test.cpp (1)

371-374: Add a compact-mode write assertion for SEQ.

The write code is intentionally outside the compact/full branches, but this test only verifies default-mode output. A compact-mode assertion would lock in the stated behavior with minimal overhead.

🧪 Proposed compact-mode assertion
     MascotGenericFile mgf_file;
     stringstream ss;
     mgf_file.store(ss, "test", exp);
     TEST_EQUAL(String(ss.str()).hasSubstring("SEQ=PEPTIDER"), true)
+
+    stringstream compact_ss;
+    mgf_file.store(compact_ss, "test", exp, true);
+    TEST_EQUAL(String(compact_ss.str()).hasSubstring("SEQ=PEPTIDER"), true)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tests/class_tests/openms/source/MascotGenericFile_test.cpp` around lines
371 - 374, Add a second assertion that verifies SEQ appears when writing in
compact mode: enable compact-mode on the MascotGenericFile instance (e.g., call
the class's compact/write-compact setter such as setWriteCompact(true) or
equivalent on mgf_file), call mgf_file.store(ss, "test", exp) or a fresh
stringstream, and assert that String(ss.str()).hasSubstring("SEQ=PEPTIDER") is
true for the compact-mode output; this locks the behavior for both default and
compact writes while keeping the check adjacent to the existing TEST_EQUAL.
🤖 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/class_tests/openms/source/MascotGenericFile_test.cpp`:
- Around line 371-374: Add a second assertion that verifies SEQ appears when
writing in compact mode: enable compact-mode on the MascotGenericFile instance
(e.g., call the class's compact/write-compact setter such as
setWriteCompact(true) or equivalent on mgf_file), call mgf_file.store(ss,
"test", exp) or a fresh stringstream, and assert that
String(ss.str()).hasSubstring("SEQ=PEPTIDER") is true for the compact-mode
output; this locks the behavior for both default and compact writes while
keeping the check adjacent to the existing TEST_EQUAL.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2e8ffd9-dfd1-4101-b7d3-e60bf2ad4c2b

📥 Commits

Reviewing files that changed from the base of the PR and between cea1aa4 and 5dce79a.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/FORMAT/MascotGenericFile.h
  • src/openms/source/FORMAT/MascotGenericFile.cpp
  • src/tests/class_tests/openms/source/MascotGenericFile_test.cpp

- Read/write paths use StringList unconditionally (no String/StringList
  branch depending on count of SEQ= lines).
- Rename parsed substring `tmp` to `sequence` in the SEQ= block.
- Tests: switch to TEST_TRUE/TEST_FALSE, adapt to always-StringList,
  and add a compact-mode write assertion.

Co-Authored-By: Claude Opus 4.7 (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.

🧹 Nitpick comments (2)
src/tests/class_tests/openms/source/MascotGenericFile_test.cpp (1)

268-419: Good coverage for the new SEQ round-trip paths.

The four sub-blocks (single, multi, programmatic write in both modes, bleed guard) line up with the parser/writer contract and the past reviewer feedback is addressed (TEST_TRUE/TEST_FALSE, always-StringList). Optional: consider also asserting the exact number of SEQ= lines in the written output (e.g. via String::split and count) for the multi case, so a future regression that collapses duplicates or drops ordering is caught at the write layer specifically, not only through the re-load.

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

In `@src/tests/class_tests/openms/source/MascotGenericFile_test.cpp` around lines
268 - 419, Add an assertion in the "Multiple SEQ lines" sub-block to verify the
writer emits exactly three "SEQ=" lines (so the write layer preserves count and
order) by reading the stored output (tmp_out or the stringstream used) and
counting occurrences of the substring "SEQ=" (or splitting lines and filtering
those that start with "SEQ="). Place this check after mgf_file.store(tmp_out,
exp) and/or after re-loading checks; reference the variables mgf_file, tmp_out
(or compact_ss/stringstream if you prefer), and the "seq_multi" test block so
the test fails if the writer collapses/drops SEQ lines.
src/openms/source/FORMAT/MascotGenericFile.cpp (1)

383-390: LGTM — SEQ emission is correctly placed and unconditional of compact mode.

The block relies on the parser's invariant that "SEQ" meta is always stored as a StringList, so toStringList() cannot throw here for spectra loaded via getNextSpectrum_(). For programmatically populated spectra, users must set it as a StringList (as done in the new test) — consider briefly documenting this contract near writeSpectrum or extracting "SEQ" into a named constant shared with the parser to avoid stringly-typed drift.

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

In `@src/openms/source/FORMAT/MascotGenericFile.cpp` around lines 383 - 390, Add a
brief doc comment near writeSpectrum describing the contract that the "SEQ" meta
key must be stored as a StringList (used by getNextSpectrum_ and the SEQ
emission loop in MascotGenericFile::writeSpectrum) and replace the hard-coded
"SEQ" string with a shared named constant (e.g., constexpr String MGF_SEQ_KEY)
used by both the parser/getNextSpectrum_ and writeSpectrum to avoid
stringly-typed drift; update references in the parser and writer to use that
constant and ensure tests set the meta as a StringList.
🤖 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/openms/source/FORMAT/MascotGenericFile.cpp`:
- Around line 383-390: Add a brief doc comment near writeSpectrum describing the
contract that the "SEQ" meta key must be stored as a StringList (used by
getNextSpectrum_ and the SEQ emission loop in MascotGenericFile::writeSpectrum)
and replace the hard-coded "SEQ" string with a shared named constant (e.g.,
constexpr String MGF_SEQ_KEY) used by both the parser/getNextSpectrum_ and
writeSpectrum to avoid stringly-typed drift; update references in the parser and
writer to use that constant and ensure tests set the meta as a StringList.

In `@src/tests/class_tests/openms/source/MascotGenericFile_test.cpp`:
- Around line 268-419: Add an assertion in the "Multiple SEQ lines" sub-block to
verify the writer emits exactly three "SEQ=" lines (so the write layer preserves
count and order) by reading the stored output (tmp_out or the stringstream used)
and counting occurrences of the substring "SEQ=" (or splitting lines and
filtering those that start with "SEQ="). Place this check after
mgf_file.store(tmp_out, exp) and/or after re-loading checks; reference the
variables mgf_file, tmp_out (or compact_ss/stringstream if you prefer), and the
"seq_multi" test block so the test fails if the writer collapses/drops SEQ
lines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb648c36-5426-4308-a93c-6840ce82dac0

📥 Commits

Reviewing files that changed from the base of the PR and between 5dce79a and c5722e4.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/FORMAT/MascotGenericFile.h
  • src/openms/source/FORMAT/MascotGenericFile.cpp
  • src/tests/class_tests/openms/source/MascotGenericFile_test.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/FORMAT/MascotGenericFile.h

@timosachsenberg
timosachsenberg merged commit bf456a8 into develop Apr 20, 2026
42 checks passed
@timosachsenberg
timosachsenberg deleted the claude/mgf-seq-peptide-encoding-bxX8j branch April 20, 2026 10:40
timosachsenberg pushed a commit that referenced this pull request Apr 21, 2026
Add missing changelog entries for PRs merged after 2026-04-19 sync:
- #9186: MascotGenericFile SEQ= field support (read/write)
- #9188: ProSE Orbitrap-aware isotope defaults [0,+2] + isotope_error Percolator feature
- #9191: ProSE SNES mother-peptide indexing for non-specific searches

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.

3 participants