Skip to content

feat(UniPEFF): native TOPP-tool port of the C# UniPEFF UniProtKB→PEFF converter - #9649

Merged
timosachsenberg merged 8 commits into
developfrom
feat/topp-unipeff-tool
Jun 23, 2026
Merged

timosachsenberg merged 8 commits into
developfrom
feat/topp-unipeff-tool

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds new TOPP tool UniPEFF that converts UniProtKB XML protein databases (.xml or .xml.gz) to PEFF 1.0 with full annotation routing — modifications (\ModResPsi/\ModResUnimod/\ModRes), variants (\VariantSimple/\VariantComplex), processed regions (\Processed), and disulfide bonds (\DisulfideBond in Option B).
  • Adds new OpenMS library class UniProtXMLFile (FORMAT/) — first native UniProtKB XML reader in OpenMS — with a private UniProtXMLHandler SAX subclass. Streams entries into a parser-neutral UniProtEntry POD; transparent .xml.gz support via the existing CompressedInputSource.
  • Native C++ port of David L. Tabb's standalone C# UniPEFF tool (github.com/timosachsenberg/UniPEFF, feat/merge-half-cystines branch). Output is byte-exact with the upstream tool's golden expected_A.peff / expected_B.peff for every annotation tag except \PName (see "Deliberate divergence from C# UniPEFF" below).
  • Two PEFFFile parser improvements as drive-by fixes: (a) accepts the scalar \PName=value (with parens) form that the C# UniPEFF emits, (b) reverses PEFF escape sequences (\\, \|, \(, \)) in parseParenList_ so consumers see logical content not raw on-wire form.

Approach

  • Half-cystines synthesized from <feature type="disulfide bond"> are merged into the main modified-residue list in position-sorted order (regular mods before half-cystines on ties; unknown positions last). Option B's \DisulfideBond=(idA,idB) IDs therefore resolve cleanly to the correct merged-list entries.
  • Streaming spool pipeline (constant memory): each parsed-and-prepared entry's serialized PEFF text is written to a per-prefix temp file (<out>.sp.tmp, <out>.tr.tmp) as we go. After parsing, the final output is <file header> + <DB blocks per prefix> + <concatenated per-prefix spools>. Memory stays bounded (one entry in flight) regardless of input size; tested at 42 MB peak RSS on a 1 GB-uncompressed human SwissProt input. The spool is opened before registering the prefix so an open failure aborts the run cleanly rather than emitting a malformed 0-entry DB block.
  • A snapshot of UniProt's ptmlist.txt is bundled at share/OpenMS/CHEMISTRY/UniProt_ptmlist.txt (overridable via -ptmlist).
  • Canonical PSI-MOD / Unimod modification names come from the already-bundled share/OpenMS/CHEMISTRY/PSI-MOD.obo and an optional unimod.obo; both overridable (-psimod_obo, -unimod_obo).
  • The handler does manual UTF-16→UTF-8 transcoding rather than relying on xercesc::XMLString::transcode, which silently goes through the local C-runtime encoding and loses non-Latin codepoints. Element-name matching uses local_name with fallback to qname, robust to either namespace-aware or namespace-unaware Xerces configurations.
  • Non-ASCII transliteration covers Latin-1 Supplement + the full Latin Extended-A block (~120 entries) — most Slavic/Baltic/Hungarian diacritics in UniProt taxonomy names now collapse to their base ASCII letter rather than ?.
  • Custom PEFF formatter (in UniPEFF.cpp, not via PEFFFile::writeStart) reproduces UniPEFF's exact byte format: unpaired-paren-only escape, 60-char sequence wrap, per-prefix sp/tr DB blocks, and the bucketed \ModResPsi/\ModResUnimod/\ModRes split.

Deliberate divergence from C# UniPEFF: \PName emission

The C# tool emits \PName=Insulin (Fragment) as a bare scalar. This is legal under PEFF 1.0 (the spec permits both scalar and list forms for single-value keys), but a paren-list-greedy reader (including the OpenMS PEFFFile) can silently truncate it to "Fragment". To make the output unambiguous, this port emits \PName=(value) as a single-element list. This is the only annotation tag where output is not byte-identical with the C# tool. Companion fix in PEFFFile: parser now also accepts the scalar form (a value whose first non-whitespace char is not ( is taken verbatim), so legacy C# UniPEFF output continues to round-trip cleanly.

CLI

Flag Purpose
-in <file> Input UniProtKB XML (.xml or .xml.gz) — required
-out <file> Output PEFF — required; rejects compressed suffixes (.gz/.bz2/.zip)
-ptmlist <file> Override the bundled UniProt PTM CV
-psimod_obo <file> Override the bundled PSI-MOD.obo
-unimod_obo <file> Optional Unimod OBO for canonical names
-prefix <p> Force a single PEFF prefix for every entry
-dbversion <v> Value for the mandatory # DbVersion= PEFF header
-annotation_identifiers Emit Option B (annotation IDs + \DisulfideBond)
-omit_molecular_processing Skip \Processed
-omit_amino_acid_modifications Skip \ModRes* and \DisulfideBond
-omit_sequence_variations Skip \Variant*

Tests

All passing (ctest -R "TOPP_UniPEFF|UniProtXMLFile_test|PEFFFile_test" → 19/19):

Test Coverage
TOPP_UniPEFF_1 + _out Option A (default), byte-exact FuzzyDiff against committed golden
TOPP_UniPEFF_2 + _out Option B (-annotation_identifiers), byte-exact against committed golden
TOPP_UniPEFF_3 + _out Gzipped input → identical to Option A output
TOPP_UniPEFF_4 + _out -prefix custom — single DB block, all entries under >custom:
TOPP_UniPEFF_5 + _out -omit_molecular_processing — \Processed absent
TOPP_UniPEFF_6 + _out -omit_amino_acid_modifications — \ModRes* and \DisulfideBond absent
TOPP_UniPEFF_7 + _out -omit_sequence_variations — \Variant* absent
TOPP_UniPEFF_8_reject_gz -out foo.peff.gz — WILL_FAIL TRUE guards the rejection
TOPP_UniPEFF_9 + _out Whitespace-stripped UniProt XML (compact.xml) — guards against future regression
TOPPWRITEINI_UniPEFF_SectionName / TOPPWRITECTD_UniPEFF Auto-generated INI/CTD round-trips
UniProtXMLFile_test Class unit test (load, loadStreaming, AltAC, gene/organism scoping, isoform skipping, all routed feature types)
PEFFFile_test [EXTRA] round-trip Loads UniPEFF golden via PEFFFile::load() and asserts entry counts + un-escaped protein name content + 18 modifications (5 half cystines) + 2 simple + 5 complex variants + 5 processed regions + getSequence() / getProcessedSequence("PEFF:0001020").
PEFFFile_test [EXTRA] scalar PName Asserts the parser correctly handles the scalar \PName=Insulin (Fragment) form.

Real-data smoke test (human SwissProt)

Metric Value Note
Entries processed 20,431 Matches UniPEFF README spot check
Wall time 12.35 s UniPEFF reports ~12 s
Peak RSS 42 MB Streaming spool works on ~1 GB uncompressed input
Output PEFF 22 MB ASCII-only, valid
Insulin (P01308) \DisulfideBond (35:0,3)(36:1,5)(37:2,4) = 31-96, 43-109, 95-100 Matches documented connectivity
PEFFFile::load() round-trip on 20K-entry output 1.80 s, RSS 184 MB All entries → AASequence + tryptic digestion succeeds; PName preserved in full
OBO fallback report 2886 modification name(s) across 37 distinct accession(s) Now reports both totals — actionable refresh hint

Code review follow-ups

Commit 1b9c029873 — first codex pass

Memory + compressed -out rejection. Per-prefix spool replaces in-memory buffering; .gz/.bz2/.zip suffixes are rejected upfront with ILLEGAL_PARAMETERS.

Commit 65b72363f0 — Opus P0 + codex PName

Spool-open failure no longer silently emits malformed 0-entry DB blocks. UniPEFF emits \PName=(value) in list form; PEFFFile parser also accepts scalar form.

Commit fe011dac11 — all remaining deferred items

  1. (Opus P1) Snake_case TOPP flag names matching OpenMS convention.
  2. (Opus P1) SAX handler uses local_name (with qname fallback) — robust to namespace-aware/unaware Xerces.
  3. (Opus P1) Latin Extended-A block added to ASCII transliteration table.
  4. (Opus P1) OBO fallback warning now reports "N occurrences across M distinct accessions".
  5. (drive-by) PEFFFile::parseParenList_ now reverses PEFF escape rules — consumers see logical content not raw on-wire form.

Notes for reviewers

  • Author of the original C# UniPEFF tool: David L. Tabb (UMC Groningen). This port preserves the algorithm and (almost all of) the output byte format.
  • The bundled UniProt_ptmlist.txt is a snapshot of the upstream UniProt CV file; refresh is a docs/maintenance task, not a code change.
  • The library handler intentionally uses a custom UTF-16→UTF-8 transcode rather than xercesc::XMLString::transcode — see the comment block in xmlchToString() for the rationale.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added UniPEFF tool to convert UniProtKB XML protein databases to PEFF 1.0 format with comprehensive metadata annotations.
    • Support for gzip-compressed input files.
    • Configurable output options including custom prefixes, omit modifications, omit variants, and omit processing flags.
  • Bug Fixes

    • Improved PEFF file parsing with corrected escape sequence handling and proper protein name parsing.

timosachsenberg and others added 2 commits June 23, 2026 09:09
… converter

Adds a new TOPP tool `UniPEFF` that converts UniProtKB XML protein databases
(plain or gzipped) to PEFF 1.0 with full annotation routing — modifications
(\ModResPsi/\ModResUnimod/\ModRes), variants (\VariantSimple/\VariantComplex),
processed regions (\Processed), and disulfide bonds (\DisulfideBond in
Option B). Output is byte-exact with the standalone C# UniPEFF tool
(github.com/timosachsenberg/UniPEFF, feat/merge-half-cystines branch),
verified by diffing against that project's golden expected_A.peff /
expected_B.peff.

Half-cystines synthesized from <feature type="disulfide bond"> are merged
into the main modified-residue list in position-sorted order (regular mods
before half-cystines on ties, unknown positions last), so Option B's
\DisulfideBond=(idA,idB) IDs resolve to the correct merged-list entries.

Adds a new OpenMS library class `UniProtXMLFile` (FORMAT/) with a private
`UniProtXMLHandler` SAX subclass; bounded subtree scoping for <gene>,
<organism>, <comment type="alternative products">, and <feature>; manual
UTF-16→UTF-8 transcoding (Xerces's default goes through the local
C-runtime encoding which silently loses non-Latin codepoints).

A snapshot of UniProt's ptmlist.txt is bundled under
share/OpenMS/CHEMISTRY/UniProt_ptmlist.txt; canonical PSI-MOD/Unimod
names come from the already-bundled PSI-MOD.obo and an optional
unimod.obo. Test fixtures (comprehensive.xml + golden PEFFs +
test-specific ptmlist/PSI-MOD/Unimod files) are committed from the
upstream UniPEFF testdata/ directory.

Tests:
  * TOPP_UniPEFF_1/2/3 — Option A, Option B (-AnnotationIdentifiers),
    and gzipped-input round-trip; each is a byte-exact FuzzyDiff against
    the upstream golden output.
  * UniProtXMLFile_test — class unit test covering load() and
    loadStreaming() against an inline UniProtKB fixture.

Author: David L. Tabb (UMC Groningen) — original C# tool. This port
preserves the algorithm and output byte format.

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

Addresses two issues from a code review of the initial commit.

1. Memory: the original implementation buffered every parsed UniProtEntry
   plus its annotation lists in a std::vector<PreparedEntry>, so converting
   SwissProt or TrEMBL would scale linearly with database size (~5-50 GB
   resident for TrEMBL) even though UniProtXMLFile is SAX-streaming. Replace
   that with a per-prefix spool: each parsed-and-prepared entry's serialized
   PEFF text is written to a small temp file as we go, and the final output
   is the file header + DB-description blocks + concatenated per-prefix
   spools. Memory now stays bounded (one entry in flight at a time) regardless
   of input size; the on-disk spool is bounded by the output PEFF size.
   Entry ordering within each prefix is preserved (the byte-exact golden
   tests still pass).

2. Compressed -out: TOPPBase's format validation accepts `.peff.gz`/`.bz2`/
   `.zip` (it strips the compression suffix and rechecks the inner type),
   but the writer is a plain std::ofstream, so we would silently write
   uncompressed bytes under a compressed file name and break downstream
   tools that auto-detect compression. Reject compressed suffixes upfront
   with ILLEGAL_PARAMETERS.

All UniPEFF and UniProtXMLFile tests still pass.

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

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Introduces a new UniPEFF TOPP tool converting UniProtKB XML databases to PEFF 1.0 format. Adds UniProtXMLFile/UniProtXMLHandler for SAX-based XML streaming with gzip support, implements full PEFF annotation (modifications, variants, processed regions, disulfide bonds, Option B IDs), registers the tool in the build system, and provides class and TOPP integration tests with golden fixtures. Fixes a PEFFFile parsing bug where scalar PName values with balanced parentheses were truncated, and standardizes PEFF escape handling across all annotation value fields.

Changes

UniPEFF: UniProtKB XML → PEFF 1.0 TOPP Tool

Layer / File(s) Summary
Parser-neutral data structures and UniProtXMLFile interface
src/openms/include/OpenMS/FORMAT/UniProtXMLFile.h, src/openms/include/OpenMS/FORMAT/HANDLERS/UniProtXMLHandler.h
Defines UniProtFeature, UniProtEntry, and UniProtXMLFile with load/loadStreaming APIs; declares UniProtXMLHandler with EntryCallback, CaptureTarget enum, and SAX override signatures.
SAX handler implementation
src/openms/source/FORMAT/HANDLERS/UniProtXMLHandler.cpp
Implements UTF-16→UTF-8 conversion with surrogate-pair handling, depth-based gating for subtree skipping (alternative products), per-entry/feature state machines in startElement/endElement/characters, and entry callback invocation.
UniProtXMLFile implementation and CMake wiring
src/openms/source/FORMAT/UniProtXMLFile.cpp, src/openms/include/OpenMS/FORMAT/HANDLERS/sources.cmake, src/openms/source/FORMAT/HANDLERS/sources.cmake, src/openms/include/OpenMS/FORMAT/sources.cmake, src/openms/source/FORMAT/sources.cmake
Implements load (delegates to loadStreaming) and loadStreaming (constructs handler, calls parse_); registers new sources in all relevant CMake lists.
UniPEFF tool: input parsing and formatting helpers
src/topp/UniPEFF.cpp (lines 1–418)
Adds ptmlist.txt parsing with hard-coded Half cystine entry, OBO stanza parsing for PSI-MOD/Unimod name maps, PEFF formatting utilities (dataset prefix mapping, PE code mapping, ASCII transliteration, reserved-character escaping, position formatting), and annotation data structures (PeffMod, PeffVariant, PeffProcessed, DisulfideEndpoint, PreparedEntry).
UniPEFF tool: feature classification, merging, ID assignment, and PEFF output
src/topp/UniPEFF.cpp (lines 423–1031)
Classifies UniProt features into PEFF buckets; merges half-cystine disulfide endpoints into sorted modification lists; assigns sequential Option B annotation IDs; writes PEFF header and per-entry descriptor tags (ModRes*, Variant*, Processed, DisulfideBond) with OBO name resolution and fixed-width sequences; provides per-entry orchestration and writable-entry filtering.
UniPEFF TOPP tool wiring and build registration
src/topp/UniPEFF.cpp (lines 1038–1293), src/topp/executables.cmake, src/openms/source/APPLICATIONS/ToolHandler.cpp, doc/doxygen/public/TOPP.doxygen, CHANGELOG
Wires CLI options/flags, streams and filters entries, groups by PEFF prefix, writes output; registers UniPEFF in executables, ToolHandler category map, doxygen index, and changelog.
UniProtXMLFile class tests and fixture
src/tests/class_tests/openms/data/UniProtXMLFile_test.xml, src/tests/class_tests/openms/executables.cmake, src/tests/class_tests/openms/source/UniProtXMLFile_test.cpp
Adds two-entry XML fixture covering isoform/feature parsing paths; validates construction, load (metadata, gene/taxonomy, canonical sequence, feature fields), and loadStreaming (entry count, accession order).
UniPEFF TOPP tests, golden fixtures, and PEFFFile parsing fix
src/tests/topp/CMakeLists.txt, src/tests/topp/UniPEFF_1_input.xml, src/tests/topp/UniPEFF_1_output_*.peff, src/tests/topp/UniPEFF_1_*.obo, src/tests/topp/UniPEFF_1_ptmlist.txt, src/tests/topp/UniPEFF_2_*, src/tests/class_tests/openms/data/PEFFFile_UniPEFF_test.peff, src/tests/class_tests/openms/source/PEFFFile_test.cpp, src/openms/source/FORMAT/PEFFFile.cpp
Adds four-entry kitchen-sink XML fixture (Swiss-Prot with extensive features, TrEMBL, two skip-guard entries) with full feature annotations; provides golden PEFF outputs for default and Option B modes, option variants (prefix override, omit flags, compact XML), minimal OBO/ptmlist/Unimod fixtures; defines nine CTest entries with gzip-equivalence, option coverage, and FuzzyDiff dependency ordering. Fixes PEFFFile PName parsing to distinguish scalar vs list form, avoiding truncation when scalar values contain balanced parentheses. Standardizes PEFF escape handling by introducing peffUnescape() helper and applying it to all annotation text fields (names, tags, tuple components). Adds PEFFFile round-trip regression tests validating UniPEFF output consumption and escape-handling edge cases.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant UniPEFF
  participant UniProtXMLFile
  participant UniProtXMLHandler
  participant PEFFWriter
  CLI->>UniPEFF: run main
  UniPEFF->>UniProtXMLFile: loadStreaming input
  UniProtXMLFile->>UniProtXMLHandler: parse with callback
  UniProtXMLHandler-->>UniPEFF: stream UniProtEntry
  UniPEFF->>PEFFWriter: write PEFF headers and entries
  PEFFWriter-->>CLI: output file
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • jpfeuffer

Poem

🐇 A rabbit hops through XML streams,
Converting proteins, PEFF-ing dreams,
Half-cystines merged with stable sort,
UniPEFF writes the golden report —
Gzip or plain, both pass the test! 🧬✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main contribution: a native C++ port of the UniPEFF tool that converts UniProtKB XML to PEFF 1.0 format.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/topp-unipeff-tool

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.

@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 (5)
src/openms/include/OpenMS/FORMAT/HANDLERS/UniProtXMLHandler.h (1)

35-35: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add Doxygen documentation for the public type alias.

The EntryCallback type alias is part of the public interface but lacks a Doxygen comment. As per coding guidelines, public types should be documented with @brief.

📝 Proposed documentation addition
+    /// `@brief` Callback signature for streaming UniProtEntry objects.
     using EntryCallback = std::function<void(UniProtEntry&&)>;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/include/OpenMS/FORMAT/HANDLERS/UniProtXMLHandler.h` at line 35,
The EntryCallback type alias lacks Doxygen documentation required by coding
guidelines. Add a Doxygen comment block before the EntryCallback type alias
definition that includes a `@brief` tag describing what this callback function
type is used for. The comment should follow the standard Doxygen format with ///
or /** */ style comments and concisely explain that this is a callback type for
processing UniProt entries.

Source: Coding guidelines

src/topp/UniPEFF.cpp (4)

772-772: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use OpenMS size types for .size() casts.

seq_len here (and the equivalent casts at Lines 653 and 679) cast std::string::size() to int. As per coding guidelines, use Size/SignedSize (from OpenMS/CONCEPT/Types.h) for STL container .size() values rather than raw int.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/topp/UniPEFF.cpp` at line 772, Replace the raw `int` type with OpenMS's
Size or SignedSize types when casting the result of `.size()` on the sequence
string. Locate the three instances of this pattern in the file: the seq_len
variable at line 772 and the equivalent casts at lines 653 and 679. Change the
static_cast from `int` to `SignedSize` (or `Size` if appropriate for the
context), and ensure that the header `OpenMS/CONCEPT/Types.h` is included if it
is not already present. This aligns the code with OpenMS coding guidelines for
handling STL container size values.

Source: Coding guidelines


102-103: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Replace std::endl with \n in log statements.

This and the other OPENMS_LOG_* statements (Lines 170, 536, 549, 558, 1106, 1110, 1115, 1132, 1144, 1145, 1200) use std::endl, which forces a flush on every call. As per coding guidelines, avoid std::endl and use \n instead for performance reasons.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/topp/UniPEFF.cpp` around lines 102 - 103, The OPENMS_LOG_WARN and other
OPENMS_LOG_* statements throughout the UniPEFF.cpp file use std::endl which
triggers unnecessary buffer flushes and impacts performance. Replace all
instances of std::endl with \n in the log statements at the specified locations
(the warning about ptmlist on lines 102-103, and all other OPENMS_LOG_*
statements at lines 170, 536, 549, 558, 1106, 1110, 1115, 1132, 1144, 1145, and
1200). This change applies to all OPENMS_LOG_WARN, OPENMS_LOG_INFO, and similar
logging macros in the file to ensure consistent performance-conscious logging
practices.

Source: Coding guidelines


688-704: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Dead/misleading disulfide-ID reservation in assignAnnotationIds.

This block only does ++next_id on the by-reference counter, but prepareEntry (Lines 1012-1014) discards that local next_id immediately after the call, so nothing is persisted. The disulfide tuple IDs are actually recomputed independently in writePeffEntry (Lines 939-964). The reservation here has no effect and the comments describing a "sentinel" are misleading.

Either store the disulfide IDs here (and consume them in writePeffEntry instead of re-deriving), or drop this block to avoid the impression that it feeds emission.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/topp/UniPEFF.cpp` around lines 688 - 704, The disulfide ID reservation
block in the `assignAnnotationIds` function increments `next_id` locally, but
this counter is discarded immediately after the function returns in
`prepareEntry`, making the reservation ineffective. The actual disulfide tuple
IDs are re-derived independently in the `writePeffEntry` function, making this
reservation block and its comments misleading. Either remove this disulfide
block entirely from `assignAnnotationIds` to eliminate the misleading comments
about ID reservation, or alternatively refactor to properly persist the
disulfide IDs generated here and consume them in `writePeffEntry` instead of
recomputing them independently.

15-24: 📐 Maintainability & Code Quality | 🔵 Trivial

Add explicit #include <functional> for std::function.

std::function is used at lines 805-806 in the writeMods lambda but relies on a transitive include from UniProtXMLFile.h. While this compiles, adding an explicit include improves clarity and robustness against future changes to transitive dependencies.

♻️ Add the include
 `#include` <algorithm>
 `#include` <cctype>
 `#include` <cstdint>
 `#include` <fstream>
+#include <functional>
 `#include` <map>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/topp/UniPEFF.cpp` around lines 15 - 24, Add an explicit `#include
<functional>` to the includes section in UniPEFF.cpp. Currently, `std::function`
is used in the writeMods lambda but relies on a transitive include from
UniProtXMLFile.h. Add the include in alphabetical order with the other standard
library includes (it should go after cctype and before fstream based on the
current include list) to make the dependency explicit and improve robustness
against future changes to transitive dependencies.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@doc/doxygen/public/TOPP.doxygen`:
- Around line 34-35: The TOPP_UniPEFF documentation entry only advertises
support for XML format but the tool also accepts gzipped UniProtKB XML files
(.xml.gz). Update the description of the TOPP_UniPEFF subpage entry to
explicitly mention that the tool converts both uncompressed and gzipped
UniProtKB XML formats to PEFF 1.0, ensuring users are aware of the supported
compressed input mode.

In `@src/topp/UniPEFF.cpp`:
- Around line 129-142: The DR key parsing is brittle when handling files with
CRLF line endings because std::getline leaves a trailing \r character. When the
code extracts PSI-MOD and Unimod values using fixed offsets with rest.substr(9,
rest.size() - 10) and rest.substr(8, rest.size() - 9), it drops the wrong
trailing character (the \r instead of the period), silently corrupting the
accession value. To fix this, trim all trailing whitespace and carriage returns
from the line string immediately after reading it with std::getline, before
extracting the rest substring and performing the PSI-MOD and Unimod parsing
logic.

---

Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/HANDLERS/UniProtXMLHandler.h`:
- Line 35: The EntryCallback type alias lacks Doxygen documentation required by
coding guidelines. Add a Doxygen comment block before the EntryCallback type
alias definition that includes a `@brief` tag describing what this callback
function type is used for. The comment should follow the standard Doxygen format
with /// or /** */ style comments and concisely explain that this is a callback
type for processing UniProt entries.

In `@src/topp/UniPEFF.cpp`:
- Line 772: Replace the raw `int` type with OpenMS's Size or SignedSize types
when casting the result of `.size()` on the sequence string. Locate the three
instances of this pattern in the file: the seq_len variable at line 772 and the
equivalent casts at lines 653 and 679. Change the static_cast from `int` to
`SignedSize` (or `Size` if appropriate for the context), and ensure that the
header `OpenMS/CONCEPT/Types.h` is included if it is not already present. This
aligns the code with OpenMS coding guidelines for handling STL container size
values.
- Around line 102-103: The OPENMS_LOG_WARN and other OPENMS_LOG_* statements
throughout the UniPEFF.cpp file use std::endl which triggers unnecessary buffer
flushes and impacts performance. Replace all instances of std::endl with \n in
the log statements at the specified locations (the warning about ptmlist on
lines 102-103, and all other OPENMS_LOG_* statements at lines 170, 536, 549,
558, 1106, 1110, 1115, 1132, 1144, 1145, and 1200). This change applies to all
OPENMS_LOG_WARN, OPENMS_LOG_INFO, and similar logging macros in the file to
ensure consistent performance-conscious logging practices.
- Around line 688-704: The disulfide ID reservation block in the
`assignAnnotationIds` function increments `next_id` locally, but this counter is
discarded immediately after the function returns in `prepareEntry`, making the
reservation ineffective. The actual disulfide tuple IDs are re-derived
independently in the `writePeffEntry` function, making this reservation block
and its comments misleading. Either remove this disulfide block entirely from
`assignAnnotationIds` to eliminate the misleading comments about ID reservation,
or alternatively refactor to properly persist the disulfide IDs generated here
and consume them in `writePeffEntry` instead of recomputing them independently.
- Around line 15-24: Add an explicit `#include <functional>` to the includes
section in UniPEFF.cpp. Currently, `std::function` is used in the writeMods
lambda but relies on a transitive include from UniProtXMLFile.h. Add the include
in alphabetical order with the other standard library includes (it should go
after cctype and before fstream based on the current include list) to make the
dependency explicit and improve robustness against future changes to transitive
dependencies.
🪄 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: c320ffa0-af0f-4dcd-8482-8b0e253c5fec

📥 Commits

Reviewing files that changed from the base of the PR and between e6fcc89 and 78d0e84.

⛔ Files ignored due to path filters (1)
  • src/tests/topp/UniPEFF_1_input.xml.gz is excluded by !**/*.gz
📒 Files selected for processing (24)
  • CHANGELOG
  • doc/doxygen/public/TOPP.doxygen
  • share/OpenMS/CHEMISTRY/UniProt_ptmlist.txt
  • src/openms/include/OpenMS/FORMAT/HANDLERS/UniProtXMLHandler.h
  • src/openms/include/OpenMS/FORMAT/HANDLERS/sources.cmake
  • src/openms/include/OpenMS/FORMAT/UniProtXMLFile.h
  • src/openms/include/OpenMS/FORMAT/sources.cmake
  • src/openms/source/APPLICATIONS/ToolHandler.cpp
  • src/openms/source/FORMAT/HANDLERS/UniProtXMLHandler.cpp
  • src/openms/source/FORMAT/HANDLERS/sources.cmake
  • src/openms/source/FORMAT/UniProtXMLFile.cpp
  • src/openms/source/FORMAT/sources.cmake
  • src/tests/class_tests/openms/data/UniProtXMLFile_test.xml
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/UniProtXMLFile_test.cpp
  • src/tests/topp/CMakeLists.txt
  • src/tests/topp/UniPEFF_1_input.xml
  • src/tests/topp/UniPEFF_1_output_A.peff
  • src/tests/topp/UniPEFF_1_output_B.peff
  • src/tests/topp/UniPEFF_1_psi-mod.obo
  • src/tests/topp/UniPEFF_1_ptmlist.txt
  • src/tests/topp/UniPEFF_1_unimod.obo
  • src/topp/UniPEFF.cpp
  • src/topp/executables.cmake

Comment thread doc/doxygen/public/TOPP.doxygen Resolved
Comment thread src/topp/UniPEFF.cpp Resolved
…EFFFile round-trip)

Adds 7 new TOPP tests + extends PEFFFile_test:

  TOPP_UniPEFF_4    -prefix custom           -> byte-exact golden
  TOPP_UniPEFF_5    -OmitMolecularProcessing -> byte-exact golden (no \Processed)
  TOPP_UniPEFF_6    -OmitAminoAcidModifications -> byte-exact golden (no \ModRes*/\DisulfideBond)
  TOPP_UniPEFF_7    -OmitSequenceVariations  -> byte-exact golden (no \Variant*)
  TOPP_UniPEFF_8_reject_gz  -out foo.peff.gz -> WILL_FAIL (must reject)
  TOPP_UniPEFF_9    compact.xml (no inter-element whitespace) -> byte-exact golden

  PEFFFile_test [EXTRA] round-trip: loads the UniPEFF Option-A golden via
    PEFFFile::load() and asserts field counts (entries, modifications,
    variants, processed regions, half-cystine count), exercises
    PEFFEntry::getSequence() and ::getProcessedSequence("PEFF:0001020").
    Guards against future drift in either the UniPEFF emitter or the
    PEFFFile parser — a divergence in either direction will fail here.

Test count: 19/19 PASS (was 8/8 before this commit).

The new omit/prefix goldens were produced by the UniPEFF binary itself
after the Option-A/B paths had been verified byte-exact against the
upstream C# tool's expected_*.peff. The compact.xml fixture is taken
verbatim from the upstream UniPEFF testdata/.

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

1628-1628: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use TEST_FALSE for boolean assertion consistency.

Line 1628 should use TEST_FALSE(headers[0].has_annotation_identifiers) instead of TEST_EQUAL(..., false) to match class-test conventions.

Suggested patch
-  TEST_EQUAL(headers[0].has_annotation_identifiers, false)  // Option A golden
+  TEST_FALSE(headers[0].has_annotation_identifiers)  // Option A golden

As per coding guidelines, “Prefer TEST_TRUE(expr) and TEST_FALSE(expr) over TEST_EQUAL(expr, true) and TEST_EQUAL(expr, false) for boolean assertions.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/class_tests/openms/source/PEFFFile_test.cpp` at line 1628, The
assertion on line 1628 uses TEST_EQUAL(headers[0].has_annotation_identifiers,
false) which does not follow the coding guidelines for boolean assertions.
Replace this with TEST_FALSE(headers[0].has_annotation_identifiers) to match the
class-test conventions that prefer TEST_TRUE and TEST_FALSE macros for boolean
checks instead of TEST_EQUAL with boolean literals.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/tests/class_tests/openms/source/PEFFFile_test.cpp`:
- Line 1628: The assertion on line 1628 uses
TEST_EQUAL(headers[0].has_annotation_identifiers, false) which does not follow
the coding guidelines for boolean assertions. Replace this with
TEST_FALSE(headers[0].has_annotation_identifiers) to match the class-test
conventions that prefer TEST_TRUE and TEST_FALSE macros for boolean checks
instead of TEST_EQUAL with boolean literals.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c6b583a-468f-47fe-850a-85445ea63fa8

📥 Commits

Reviewing files that changed from the base of the PR and between 1b9c029 and 9bdc7aa.

📒 Files selected for processing (9)
  • src/tests/class_tests/openms/data/PEFFFile_UniPEFF_test.peff
  • src/tests/class_tests/openms/source/PEFFFile_test.cpp
  • src/tests/topp/CMakeLists.txt
  • src/tests/topp/UniPEFF_2_input_compact.xml
  • src/tests/topp/UniPEFF_2_output_compact.peff
  • src/tests/topp/UniPEFF_2_output_omitmods.peff
  • src/tests/topp/UniPEFF_2_output_omitproc.peff
  • src/tests/topp/UniPEFF_2_output_omitvar.peff
  • src/tests/topp/UniPEFF_2_output_prefix.peff
✅ Files skipped from review due to trivial changes (7)
  • src/tests/topp/UniPEFF_2_output_compact.peff
  • src/tests/topp/UniPEFF_2_input_compact.xml
  • src/tests/topp/UniPEFF_2_output_omitproc.peff
  • src/tests/topp/UniPEFF_2_output_omitvar.peff
  • src/tests/topp/UniPEFF_2_output_prefix.peff
  • src/tests/topp/UniPEFF_2_output_omitmods.peff
  • src/tests/class_tests/openms/data/PEFFFile_UniPEFF_test.peff

timosachsenberg and others added 3 commits June 23, 2026 10:53
…e parser

Addresses the tag-team Opus+codex code review:

1. (Opus P0) UniPEFF.cpp main_(): when a spool file failed to open, the
   lambda ran `prefixes.push_back(prefix)` BEFORE the open attempt, and on
   failure returned without registering the prefix in `spools`. Later
   `spools[p].count` then default-constructed a `PrefixSpool` for that
   prefix, yielding `# NumberOfEntries=0` and an empty ifstream — the file
   could silently contain a malformed 0-entry DB block whose entries were
   nowhere. Now we open the spool BEFORE registering the prefix, latch a
   `spool_open_failed` flag in the parse callback, and abort the whole run
   with CANNOT_WRITE_OUTPUT_FILE + a user-actionable message. Verified by
   running `-out /dev/null` (exit code 5, clean error, no malformed output).

2. (codex P2 / option B) UniPEFF emitter now writes \PName as a single-element
   list `\PName=(value)` rather than as a bare scalar. PEFF 1.0 allows both
   forms for single-value keys; the list form is unambiguous to parse — a
   scalar value containing a balanced parenthetical (legal under PEFF's
   "only UNPAIRED parens must be escaped" rule, and the common case for
   UniProt names like "Insulin (Fragment)" or "...(EC 2.7.10.2)...") would
   otherwise be silently truncated by a paren-list-greedy reader. All
   committed UniPEFF goldens regenerated to match. This breaks byte-exact
   parity with the upstream C# UniPEFF on the PName key only; everything
   else still byte-matches, and a real-data run on human SwissProt confirms
   PEFFFile::load() now returns the full protein name.

3. (codex P2 / option C) PEFFFile parser: PName parsing now accepts BOTH
   the list form and the scalar form. A value whose first non-whitespace
   char is '(' is parsed as a paren list (existing behaviour); otherwise
   the whole value is taken verbatim as the single name. This guards
   against silent truncation of scalar PName values containing embedded
   balanced parentheticals — the same shape the upstream C# UniPEFF emits.
   A new PEFFFile_test [EXTRA] section covers the scalar case.

4. PEFFFile_test round-trip section now asserts e1.protein_names content
   (not just size); without (2) above, it returned 'test' instead of the
   full "Kitchen-sink protein (test) ..." name. The asserted string is the
   escape-preserved form because parseParenList_ deliberately passes
   PEFF escape sequences (\|, \\, \\)) through to the caller; un-escaping
   is the caller's responsibility (matches existing behaviour on every
   other parenthesized PEFF list).

All 19 UniPEFF/UniProtXMLFile/PEFFFile tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Five follow-ups from the tag-team review, none of which were blocking but
all of which improve robustness / UX / convention compliance:

1. (Opus P1) Snake_case TOPP flag names. Rename:
     -AnnotationIdentifiers            -> -annotation_identifiers
     -OmitMolecularProcessing          -> -omit_molecular_processing
     -OmitAminoAcidModifications       -> -omit_amino_acid_modifications
     -OmitSequenceVariations           -> -omit_sequence_variations
   Matches the convention used by DatabaseFilter, DecoyDatabase, Digestor,
   and the rest of the TOPP suite. All test CMake lines updated.

2. (Opus P1) Defensive SAX handler: UniProtXMLHandler now matches against
   local_name (with fallback to qname when empty). Real UniProtKB XML
   carries xmlns="http://uniprot.org/uniprot"; a future switch to
   namespace-aware Xerces would deliver qname as "uniprot:entry" but
   local_name as "entry". Today (namespace-off mode, Xerces default)
   local_name is empty and we fall through to qname unchanged.

3. (Opus P1) toAscii() transliteration table now covers the full Latin
   Extended-A block (U+0100..U+017F, ~120 entries) in addition to Latin-1
   Supplement. Closes the silent-? gap with C# NFKD on common Slavic,
   Baltic and Hungarian diacritics in UniProt taxonomy names (Č, Đ, Ł,
   Ő, Ř, Š, Ť, Ű, Ž, …).

4. (Opus P1) OBO fallback warning now reports both total occurrences and
   distinct accession count: "2886 modification name(s) across 37 distinct
   accession(s) fell back to ...". Tells the user "your OBO is 37 terms
   out of date" (actionable refresh) rather than the previous ambiguous
   single number. A new OboFallbackTracker struct threads the set through
   writePeffEntry() in place of the previous size_t counter.

5. (codex P3 / round-trip quality) PEFFFile::parseParenList_ now reverses
   PEFF escape rules on the way out: \\, \|, \(, \) -> \, |, (, ).
   Previously the function preserved the raw on-wire form, forcing every
   consumer to do its own un-escape (or, more likely, silently exposing
   escape sequences in PEFFEntry fields). New helper peffUnescape() in
   PEFFFile.cpp's anonymous namespace is also applied to the new scalar
   PName parsing path. The PEFFFile_test round-trip assertion updated to
   the now-correct logical content ("Kitchen-sink protein (test) |
   alpha\\beta :-)" instead of the previously-escaped form).

All 19 UniPEFF/UniProtXMLFile/PEFFFile tests pass.

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

Codex pass #3 found a regression in commit fe011da. parseParenList_'s
un-escape ran BEFORE the structured-tuple parsers' splitByPipeEscapeAware
call, so a valid \ModRes=(1|MOD:00046|A\|B) became "1|MOD:00046|A|B"
after un-escape, and the pipe split then treated the escaped pipe as a
field separator — name became "A", optional_tag became "B".

Fix: parseParenList_ returns items with PEFF escapes intact. Per-field
un-escape is applied at each call site that takes the item as a scalar
(PName list, AltAC, Proteoform) or inside each tuple parser AFTER
splitByPipeEscapeAware has done its job:

  parseModification_      -> peffUnescape(name), peffUnescape(optional_tag)
  parseVariantSimple_     -> peffUnescape(optional_tag)
  parseVariantComplex_    -> peffUnescape(replacement), peffUnescape(optional_tag)
  parseProcessedRegion_   -> peffUnescape(name), peffUnescape(optional_tag)
  parseDisulfideBond_     -> peffUnescape(optional_tag)
  AltAC, Proteoform, PName (list & scalar) -> peffUnescape() at call site

Numeric fields (positions), CV accessions (which never contain reserved
chars per PEFF spec), and disulfide id strings stay raw.

New regression test [EXTRA] section asserts a \ModResPsi=(1|MOD:00046|name
with \\| pipe) tuple parses with name="name with | pipe" and
optional_tag="" — would have caught fe011da's bug.

All 19 UniPEFF/UniProtXMLFile/PEFFFile tests pass.

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.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/openms/source/FORMAT/PEFFFile.cpp (1)

2177-2190: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Only treat PName as list form when the full value is a paren list.

Line 2178 classifies any value whose first non-whitespace character is ( as list form. A valid scalar such as \PName=(Fragment) insulin still gets truncated to Fragment, leaving the balanced-parenthetical scalar bug partially unfixed.

🐛 Proposed direction
-        size_t first_non_ws = value.find_first_not_of(" \t");
-        const bool is_list_form = (first_non_ws != std::string::npos && value[first_non_ws] == '(');
+        const bool is_list_form = isCompleteParenList_(value);

Implement isCompleteParenList_() so it returns true only when the value is entirely composed of adjacent parenthesized items plus surrounding whitespace. Otherwise, preserve the whole scalar and unescape it once.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/FORMAT/PEFFFile.cpp` around lines 2177 - 2190, The current
logic for determining if a value is in list form uses only the first
non-whitespace character check (checking if it's `(`), which incorrectly
classifies scalar values like `(Fragment) insulin` as list form and truncates
them. Create a new method called `isCompleteParenList_()` that validates the
entire value is fully composed of adjacent parenthesized items plus surrounding
whitespace. Replace the simple character-based check on line 2178 with a call to
this new method, so that only truly complete paren lists are treated with
parseParenList_(), while all other cases (including partial paren expressions)
treat the whole value as a single scalar to be unescaped once.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/source/FORMAT/PEFFFile.cpp`:
- Around line 30-33: The code is double-unescaping PEFF fields because
splitByPipeEscapeAware() already decodes escape sequences like \\, \|, \(, and
\), but then peffUnescape() is called again on the already-decoded values.
Remove the peffUnescape() calls in parseModification_(), parseVariantSimple_(),
parseVariantComplex_(), and parseProcessedRegion_() that are applied after
splitting with splitByPipeEscapeAware(). Instead, use a preserving splitter (one
that does not decode escape sequences) before the per-field peffUnescape()
calls, so escaping is only handled once per field.

In `@src/tests/class_tests/openms/source/PEFFFile_test.cpp`:
- Around line 1642-1645: Update the stale comment in the test file that
incorrectly describes how escape handling is performed. The comment currently
states that parseParenList_'s un-escape pass reverses PEFF reserved-char
escapes, but this behavior has changed. Revise the comment to accurately reflect
that parseParenList_() now keeps escapes intact and the PName call site is
responsible for calling peffUnescape() to handle the escaping, ensuring the
comment points future readers to the correct layer where this logic is
performed.

---

Outside diff comments:
In `@src/openms/source/FORMAT/PEFFFile.cpp`:
- Around line 2177-2190: The current logic for determining if a value is in list
form uses only the first non-whitespace character check (checking if it's `(`),
which incorrectly classifies scalar values like `(Fragment) insulin` as list
form and truncates them. Create a new method called `isCompleteParenList_()`
that validates the entire value is fully composed of adjacent parenthesized
items plus surrounding whitespace. Replace the simple character-based check on
line 2178 with a call to this new method, so that only truly complete paren
lists are treated with parseParenList_(), while all other cases (including
partial paren expressions) treat the whole value as a single scalar to be
unescaped once.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91707614-2c5e-4f9d-8eb3-df2b997cdbab

📥 Commits

Reviewing files that changed from the base of the PR and between 65b7236 and 5125254.

📒 Files selected for processing (5)
  • src/openms/source/FORMAT/HANDLERS/UniProtXMLHandler.cpp
  • src/openms/source/FORMAT/PEFFFile.cpp
  • src/tests/class_tests/openms/source/PEFFFile_test.cpp
  • src/tests/topp/CMakeLists.txt
  • src/topp/UniPEFF.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/openms/source/FORMAT/HANDLERS/UniProtXMLHandler.cpp
  • src/tests/topp/CMakeLists.txt
  • src/topp/UniPEFF.cpp

Comment thread src/openms/source/FORMAT/PEFFFile.cpp Resolved
timosachsenberg and others added 2 commits June 23, 2026 11:43
Four findings from CodeRabbit's automated review of the post-Opus+codex
state:

1. (Major) Double-unescape in structured-tuple parsers.
   `splitByPipeEscapeAware()` already decodes \\, \|, \(, \) per-field, so
   the peffUnescape() calls I added in commit fe011da to parseModification_,
   parseVariantSimple_, parseVariantComplex_ and parseProcessedRegion_ were
   running a SECOND decode pass. A legitimate on-wire "\\\\" (representing
   a literal "\\") would survive the split as "\\" and the redundant pass
   would collapse it to "\". Removed the redundant calls; the only place a
   per-field un-escape is still needed is parseDisulfideBond_ — its
   description field is extracted with a plain find('|')+substr, not via
   splitByPipeEscapeAware. New regression test [EXTRA] section asserts a
   `\ModResPsi=(1|MOD:00046|name with \\\\ backslashes)` tuple parses with
   name="name with \\ backslashes" (two literal backslashes preserved).

2. (Major) PName list-form classification too greedy.
   The previous check `is_list_form = value[first_non_ws] == '('` would
   misclassify a legitimate scalar starting with a parenthesised qualifier,
   e.g. "(R)-amino acid hydroxylase", as list form and silently truncate
   the name to "R". The new check requires the trimmed value to be a
   sequence of paren-balanced groups (starts with '(', ends with ')',
   every zero-depth point is immediately followed by another '(') — only
   then do we treat it as a list.

3. (Minor) ptmlist.txt DR parsing brittle for CRLF.
   The accession extraction uses fixed offsets `rest.size() - 10` / `-9`;
   a Windows-edited ptmlist.txt with CRLF line endings would shift the
   end of "rest" by one and corrupt the accession. Trim trailing whitespace
   (including '\r') before parsing.

4. (Trivial nitpicks)
   - Add Doxygen comment for the EntryCallback public type alias in
     UniProtXMLHandler.h.
   - Mention .xml.gz support in the TOPP.doxygen subpage one-liner.
   - Use TEST_FALSE instead of TEST_EQUAL(..., false).
   - Refresh stale escape-handling comment in PEFFFile_test.

All 19 UniPEFF / UniProtXMLFile / PEFFFile tests pass (one new regression
test added).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
CI's Doxygen_Warning_test failed on this PR with two classes of warnings
introduced by the recent edits:

1. `@type`, `@description`, `@dataset` (3 sites in UniProtXMLFile.h) —
   I used these as XML attribute references in field doc comments
   (`feature/@type`, `feature/@description`, `entry/@dataset`), but
   Doxygen parses an `@` followed by an identifier as a command and
   warns "Found unknown command '@type'". Escape with backslash:
   `feature/\@type`, etc.

2. `\PName \GName \NcbiTaxId \TaxName \Length \SV \EV \PE \ID \AltAC
   \ModResPsi \ModResUnimod \ModRes \VariantSimple \VariantComplex
   \Processed \DisulfideBond` (16 sites in the UniPEFF @page block) —
   I listed these as bare PEFF descriptor-line tag names; Doxygen
   sees `\Word` and treats them as Doxygen commands. Double-backslash
   each so the renderer prints a literal `\X`: `\\PName`, `\\GName`, …
   Matches the pattern already used elsewhere in OpenMS (e.g. PEFFFile.h).

No source behavior changes; this is purely a doc-comment escaping fix.
All 19 UniPEFF / UniProtXMLFile / PEFFFile tests still pass locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg merged commit b40fd92 into develop Jun 23, 2026
42 checks passed
@timosachsenberg
timosachsenberg deleted the feat/topp-unipeff-tool branch June 23, 2026 14:06
timosachsenberg added a commit that referenced this pull request Jun 24, 2026
…9650, #9651 (#9652)

- Add PR reference (#9650) to the error-message improvement entry (was issue #9636 only)
- Add PR reference (#9642) to ProSE end-of-search report entry
- Add PR reference (#9643) to PSMFeatureExtractor andes support entry
- Add PR reference (#9649) to UniPEFF new-tool entry
- Add Build System entry for #9648: Boost.Spirit → charconv, 30-40% faster build
- Add Build System entry for #9651: missing <thread> header fix for clang 21+


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

Co-authored-by: Claude <[email protected]>
KyowonJeong added a commit to t0mdavid-m/OpenMS that referenced this pull request Oct 21, 2026
…on as the library class UniPEFFConverter

UniPEFF (UniProtKB XML -> PEFF 1.0; Timo Sachsenberg's port of David L. Tabb's C# tool, OpenMS develop b40fd92, OpenMS#9649) with
UniProtXMLFile, its SAX handler, the bundled UniProt ptmlist and the tool's tests. The conversion moved unchanged from the tool into
UniPEFFConverter, so that FLASHTnT can read UniProtKB XML; the tool keeps its options and calls it. This branch has no PEFF file type,
so -out is not restricted by extension. Output byte-identical to the develop tool: the 9 TOPP golden tests (run by hand) and the
E. coli K-12 proteome (Option A and B); UniProtXMLFile_test passes.

Co-Authored-By: Claude Opus 5.5 <[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