Fix ProForma writer for ranges bearing multiple modifications (§4.5)#116
Open
trishorts wants to merge 1 commit into
Open
Fix ProForma writer for ranges bearing multiple modifications (§4.5)#116trishorts wants to merge 1 commit into
trishorts wants to merge 1 commit into
Conversation
The writer threw "Can't nest ranges within each other" for a range carrying more than one modification (e.g. "(SEQ)[mod1][mod2]", ProForma 2.0 section 4.5). Each modification on a range is parsed as a separate tag spanning the same start/end, and the writer's internal-tag loop mistook those co-located modifications for nested ranges. Treat a tag whose start and end match the current range as another modification on that range and emit it as a consecutive descriptor after the range closes; genuine nested ranges still throw. Adds a constructed unit test and a parse/write round-trip regression test; full suite green (235 passed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JNnpzBNwfnTbZxtZdtAzLG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProFormaWriter.WriteStringthrowsProFormaParseException: "Can't nest ranges within each other."whenever a term contains a sequence range that carries more than one modification — the ProForma 2.0 §4.5 construct(SEQ)[mod1][mod2]…. The parser accepts these strings, so they cannot currently be round-tripped: parsing succeeds but writing the resulting term fails.Reproduce
This also blocks real specification examples (e.g. the §4.5 insulin-style range bearing multiple oxidations and half-cystines).
Root cause
Each modification on a range is parsed as a separate
ProFormaTagspanning the same(ZeroBasedStartIndex, ZeroBasedEndIndex)— the parser keeps the range open across consecutive)[mod][mod]until the next residue resets it. When the writer reaches the range, its inner loop scans the tags that fall within the range and unconditionally throws for any whosestart != end. But a co-located range modification legitimately hasstart != end(it spans the whole range), so these were mistaken for nested ranges.Fix
In the range branch of
WriteString, a tag whose start and end equal the current range's start and end is treated as another modification on that same range and emitted as a consecutive[descriptor]after the range closes. Genuinely nested ranges (a differentstart != endinside the range) still throw as before.After
Tests
WriteMultipleModificationsOnSameRange— constructs a range carrying two modifications and assertsSE(QUEN)[+14.05][Oxidation]CE.RoundTripMultipleModificationsOnRange— parse→write round-trip of a four-modification range.🤖 Generated with Claude Code
https://claude.ai/code/session_01JNnpzBNwfnTbZxtZdtAzLG