diff --git a/depthcharge/primitives.py b/depthcharge/primitives.py index b7b3e3a..0318247 100644 --- a/depthcharge/primitives.py +++ b/depthcharge/primitives.py @@ -73,7 +73,12 @@ def __post_init__(self) -> None: continue try: - mod = [MassModification(mod)] + try: + mass = mod[0].value + except (IndexError, AttributeError): + mass = mod + + mod = [MassModification(float(mass))] except ValueError: try: mod = [GenericModification(mod)] @@ -116,7 +121,7 @@ def split(self) -> list[str]: except (AttributeError, ValueError): modstr = f"[{mods[0].mass:+0.6f}]" else: - modstr = f"[{sum([m.mass for m in mods]):+0.6f}]" + modstr = f"[{sum(m.mass for m in mods):+0.6f}]" if not idx: out.append(f"{modstr}-") diff --git a/tests/unit_tests/test_primitives.py b/tests/unit_tests/test_primitives.py index 19fb2bc..2a586de 100644 --- a/tests/unit_tests/test_primitives.py +++ b/tests/unit_tests/test_primitives.py @@ -50,6 +50,12 @@ def test_peptide_init(): assert parsed.split() == expected +def test_almost_proforma(): + """Test a peptide lacking an explicit sign.""" + parsed = Peptide.from_proforma("LES[79.0]LIEK") + assert parsed.split() == ["L", "E", "S[79.000000]", "L", "I", "E", "K"] + + def test_peptide_from_proforma(): """Test proforma parsing.""" parsed = Peptide.from_proforma("LESLIEK/2")