Skip to content

Fix numerous logic errors from historical lack of tests#212

Merged
levitsky merged 8 commits into
levitsky:masterfrom
mobiusklein:fix/proforma-coverage-fixes
Jul 14, 2026
Merged

Fix numerous logic errors from historical lack of tests#212
levitsky merged 8 commits into
levitsky:masterfrom
mobiusklein:fix/proforma-coverage-fixes

Conversation

@mobiusklein

Copy link
Copy Markdown
Contributor

Addresses the lingering issue from #209

Fix #211, making tag resolution failure a non-fatal error at parse time. Still invokes resolvers, but doesn't crash if they fail.

Amongst other things, I plugged a bunch of holes in the hand-rolled state machine where state transitions didn't exist, or had muddled invariant management for bizarre scenarios.

@levitsky

Copy link
Copy Markdown
Owner

Thank you! I see that you also implemented a Chimeric type.

The tests pass for me locally on Python 3.12 but they do fail on 3.11:

$ python -m unittest test_proforma.ProFormaTest.test_fragments
E
======================================================================
ERROR: test_fragments (test_proforma.ProFormaTest.test_fragments)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/levitsky/pyteomics/tests/test_proforma.py", line 166, in test_fragments
    for o, e in zip(i.fragments("b"), b_expected):
                    ^^^^^^^^^^^^^^^^
  File "/home/levitsky/pyteomics/pyteomics/proforma.py", line 4222, in fragments
    intervals = sorted(intervals, key=lambda x: x.start, reverse=reverse)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object cannot be interpreted as an integer

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)

@mobiusklein

Copy link
Copy Markdown
Contributor Author

Okay, no clue where that None to int coercion is happening. Either cosmic rays or non-deterministic behavior. All set on my end though.

@levitsky

levitsky commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Thank you. Before merging, I want to try it out and add some more tests potentially around Chimeric. For example, this doesn't work as I expected:

In [1]: from pyteomics import proforma

In [2]: proforma.ProForma.parse('PEPTIDE', chimeric=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 proforma.ProForma.parse('PEPTIDE', chimeric=True)

File ~/pyteomics/pyteomics/proforma.py:4084, in ProForma.parse(cls, string, chimeric, **kwargs)
   4082 result = parse(string, chimeric=chimeric, **kwargs)
   4083 if chimeric:
-> 4084     return Chimeric([cls(*component) for component in result], result.chimeric)
   4085 return cls(*result)

AttributeError: 'list' object has no attribute 'chimeric'

I will have more time next week to look into it.

@mobiusklein

Copy link
Copy Markdown
Contributor Author

I missed the fast path, thank you for checking that. I also realized I could actually use pattern matching freely in unit tests now that Py310 is the minimal version, which caught another syntactic issue.

@levitsky levitsky left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

I noticed an issue with ProteoformCombinator that I missed before because I didn't bother to test fixed modifications. I took a guess at a fix because the semantics of those ModificationRuleDirective creation methods and the class itself are not entirely clear to me, and multiple errors shown by static type checkers don't help.

Could you check if ProteoformCombinator._apply_fixed_modifications makes sense?

@levitsky

Copy link
Copy Markdown
Owner

Thanks again! Should I merge now?

@mobiusklein

mobiusklein commented Jul 14, 2026 via email

Copy link
Copy Markdown
Contributor Author

@levitsky levitsky merged commit 9331cc9 into levitsky:master Jul 14, 2026
15 checks passed
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.

Support for unresolved modification tags in ProForma

2 participants