Skip to content

Commit

Permalink
Fix #122
Browse files Browse the repository at this point in the history
  • Loading branch information
levitsky committed Sep 8, 2023
1 parent 68a8ac7 commit 021e9b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pyteomics/mgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ def _pepmass_repr(k, pepmass):


def _charge_repr(k, charge):
return '{}={}'.format(k.upper(), aux.Charge(charge) if isinstance(charge, int) else aux.ChargeList(charge))
try:
val = aux.Charge(charge)
except (TypeError, aux.PyteomicsError):
val = aux.ChargeList(charge)
return '{}={}'.format(k.upper(), val)


def _default_repr(key, val):
Expand Down
2 changes: 1 addition & 1 deletion pyteomics/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

__version__ = '4.6.2'
__version__ = '4.6.3a1'

from collections import namedtuple
import re
Expand Down
2 changes: 2 additions & 0 deletions tests/test_mgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,13 @@ def test_charge_repr_single(self):
self.assertEqual(mgf._charge_repr('charge', [2]), 'CHARGE=2+')
self.assertEqual(mgf._charge_repr('charge', aux.Charge(2)), 'CHARGE=2+')
self.assertEqual(mgf._charge_repr('charge', aux.ChargeList([2])), 'CHARGE=2+')
self.assertEqual(mgf._charge_repr('charge', np.int64(2)), 'CHARGE=2+')

def test_charge_repr_multiple(self):
self.assertEqual(mgf._charge_repr('charge', [2, 3]), 'CHARGE=2+ and 3+')
self.assertEqual(mgf._charge_repr('charge', aux.ChargeList([2, 3])), 'CHARGE=2+ and 3+')
self.assertEqual(mgf._charge_repr('charge', '2+, 3+'), 'CHARGE=2+ and 3+')
self.assertEqual(mgf._charge_repr('charge', np.array([2, 3])), 'CHARGE=2+ and 3+')


if __name__ == "__main__":
Expand Down

0 comments on commit 021e9b1

Please sign in to comment.