Repository navigation
feat(MGF): support SEQ= sequence-query field on read and write - #9186
Conversation
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
|
@timosachsenberg The following names might be missing from the
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) |
There was a problem hiding this comment.
Always store as stringlist. A change of interface depending on file content is just making it harder to use and adds potential for errors
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Use Stringview? And think of a better name (sequence?)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Replaced all TEST_EQUAL(..., true/false) in the new SEQ section with TEST_TRUE / TEST_FALSE.
📝 WalkthroughWalkthroughExtended MGF parsing to recognize per-spectrum Changes
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
src/tests/class_tests/openms/source/MascotGenericFile_test.cpp (1)
371-374: Add a compact-mode write assertion forSEQ.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
📒 Files selected for processing (3)
src/openms/include/OpenMS/FORMAT/MascotGenericFile.hsrc/openms/source/FORMAT/MascotGenericFile.cppsrc/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]>
There was a problem hiding this comment.
🧹 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 ofSEQ=lines in the written output (e.g. viaString::splitand 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 aStringList, sotoStringList()cannot throw here for spectra loaded viagetNextSpectrum_(). For programmatically populated spectra, users must set it as aStringList(as done in the new test) — consider briefly documenting this contract nearwriteSpectrumor 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
📒 Files selected for processing (3)
src/openms/include/OpenMS/FORMAT/MascotGenericFile.hsrc/openms/source/FORMAT/MascotGenericFile.cppsrc/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
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]>
Summary
MascotGenericFilepreviously ignored theSEQ=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-classSEQ=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 aBEGIN IONS ... END IONSblock, alongsideCOMP=,TAG=,ETAG=.SEQ=lines per query; each acts as an independent filter.Other tools already treat it as a standard local field — e.g. pyteomics
mgfexposes it as'seq'in the per-spectrum params dict, and Mascot's ownms_inputquerysurfaces it via dedicated accessors.Changes
Read —
src/openms/include/OpenMS/FORMAT/MascotGenericFile.h(getNextSpectrum_):SEQ=and stores it on theMSSpectrumas the meta value"SEQ".SEQis kept as aString; multipleSEQlines per query are accumulated into aStringListunder the same key."SEQ"meta value on the reusable spectrum object is cleared at the top ofgetNextSpectrum_(same pattern asTITLE) so sequences cannot bleed between consecutive spectra.Write —
src/openms/source/FORMAT/MascotGenericFile.cpp(writeSpectrum):CHARGE, emit oneSEQ=line per entry when the meta value is aStringList, or a singleSEQ=line when it's aString. Works in both compact and full modes.Tests —
src/tests/class_tests/openms/source/MascotGenericFile_test.cpp:SEQround-trip (load → store → load).SEQStringListround-trip (three sequences preserved and re-emitted).MSSpectrumwithsetMetaValue("SEQ", "PEPTIDER").SEQmust not inherit the first spectrum'sSEQ.Design notes / rejected alternatives
"SEQ"— mirrors the MGF field directly, matching the existing convention in this file for"TITLE","IONMODE","SOURCE_INSTRUMENT", etc. No newConstants::UserParam::*entry was added, since the metabolomics constants (MSM_*) are tied toMetaboliteSpectralMatcherand SEQ is a proteomics concept. Happy to add a constant if reviewers prefer.PeptideIdentification— considered threading SEQ through attachedPeptideIdentification/PeptideHitobjects (where a realAASequencelives), 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.SEQis implemented here.COMP,TAG,ETAGare structurally similar and could be added in a follow-up with the same pattern.Test plan
MascotGenericFile_testpasses (four new sub-blocks inside a newSTART_SECTION).SEQ=.https://claude.ai/code/session_01LpLkMxcZnXc8eCTLx5uXCB
Summary by CodeRabbit
New Features
Bug Fixes
Tests