Skip to content

Commit

Permalink
Add support for sign missing in proforma string
Browse files Browse the repository at this point in the history
  • Loading branch information
wfondrie committed May 8, 2024
1 parent 8519369 commit e603993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions depthcharge/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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}-")
Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e603993

Please sign in to comment.