Skip to content

Map MaxQuant modification labels to ProForma tags in MSMSReader - #156

Open
rpinho wants to merge 1 commit into
CompOmics:mainfrom
rpinho:fix-138-maxquant-modifications
Open

rpinho wants to merge 1 commit into
CompOmics:mainfrom
rpinho:fix-138-maxquant-modifications

Conversation

@rpinho

@rpinho rpinho commented Nov 26, 2026

Copy link
Copy Markdown

Summary

MSMSReader previously copied MaxQuant short modification codes (such as (ox), (ac), (de), (gl)) and descriptive labels (such as (Oxidation (M)), (Acetyl (Protein N-term))) verbatim into ProForma brackets. On MaxQuant exports this either raises ModificationException on descriptive labels or silently resolves short codes to the wrong Unimod entry — for example, in #138 _ACVINGM(ox)QLK_ parsed to ACVINGM[ox]QLK/2, where [ox] matched Unimod:6 (Carboxymethyl, +58.005479 Da, theoretical mass 1133.5573 Da) instead of Oxidation (+15.994915 Da, theoretical mass 1091.5467 Da).

Who hits this: proteomics users reading MaxQuant msms.txt files with psm_utils.io.maxquant.MSMSReader (or read_file(..., filetype="msms")) whose modified sequences contain MaxQuant short codes or descriptive modification labels (#138).

Changes

  • psm_utils/io/maxquant.py:
    • Add site-aware default mappings (_NAMED_MODIFICATIONS and _SHORT_MODIFICATIONS) and cross-check short codes against the row's Modifications summary when present (disambiguating site-dependent tags such as N-terminal (ca) -> Carbamyl vs cysteine (ca) -> Carbamidomethyl, and N-terminal Q (gl) -> Gln->pyro-Glu vs corroborated lysine (gl) -> GG).
    • Add optional modification_mapping: Mapping[str, str] | None = None to MSMSReader: caller entries override built-ins by exact label, while modification_mapping={} opts out to preserve raw labels.
    • Warn once per reader per unmapped non-Unimod/non-PSI-MOD label and keep the original label; emit an INFO log when mapping is applied.
    • Replace regex substitution in _parse_peptidoform with balanced-parenthesis parsing that handles nested parentheses and distinguishes true C-terminal modifications from modifications on the C-terminal amino acid.
  • psm_utils/psm_list.py:
  • tests/test_io/test_maxquant.py, tests/test_psm_list.py, tests/test_data/issue_138_msms.txt:
    • Add 15 regression tests covering the exact Peptidoforms parsed from MaxQuant output are not always valid #138 line (ACVINGM[Oxidation]QLK/2, 1091.5467 Da while preserving metadata["Mass"] == "1148.5682"), descriptive/short site disambiguation, C-terminal residue vs C-term placement, modification_mapping overrides and {} opt-out, deduplicated warnings, and rename_modifications logging.

Note on fixed modifications: MaxQuant omits fixed modifications (such as carbamidomethylation on C in the #138 example) from Modified sequence; this PR maps only labels present in Modified sequence and leaves metadata["Mass"] untouched.

Verification

  • All 15 new regression tests fail on main (ab50a617) and pass with this patch; the full test suite passes (142 passed).
  • Replaying all 35,556 rows of example_files/msms.txt.gz clears all 6,609 short tags ((ac), (de), (ox), (gl)), eliminating 6,230 theoretical-mass discrepancies > 0.05 Da (0 discrepancies patched).
  • ruff check, ruff format --check, and mypy pass on all modified files.
  • Found and written with AI agents; a separate cross-family AI referee independently reproduced Peptidoforms parsed from MaxQuant output are not always valid #138 and verified the patch and edge cases before this PR.

Fixes #138

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Peptidoforms parsed from MaxQuant output are not always valid

1 participant