Skip to content

Commit

Permalink
peptidoform: Add iter and len methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfG committed Sep 19, 2023
1 parent aea3bc0 commit 02cc6ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions psm_utils/peptidoform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import Iterable, List, Tuple, Union

import numpy as np
from pyteomics import mass, proforma

Expand Down Expand Up @@ -69,6 +71,12 @@ def __eq__(self, __o: Peptidoform) -> bool:
except AttributeError:
raise NotImplementedError("Object is not a Peptidoform")

def __iter__(self) -> Iterable[Tuple[str, Union[None, List[proforma.TagBase]]]]:
return self.parsed_sequence.__iter__()

def __len__(self) -> int:
return self.parsed_sequence.__len__()

@property
def proforma(self) -> str:
"""
Expand Down
26 changes: 26 additions & 0 deletions tests/test_peptidoform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
from pyteomics import proforma

from psm_utils.peptidoform import Peptidoform


class TestPeptidoform:

def test__len__(self):
test_cases = [
("ACDEFGHIK", 9),
("[ac]-AC[cm]DEFGHIK", 9),
("[ac]-AC[Carbamidomethyl]DEFGHIK", 9),
("[Acetyl]-AC[cm]DEFGK", 7),
("<[cm]@C>[Acetyl]-ACDK", 4),
("<[Carbamidomethyl]@C>[ac]-ACDEFGHIK", 9),
]

for test_case_in, expected_out in test_cases:
peptidoform = Peptidoform(test_case_in)
assert len(peptidoform) == expected_out

def test__iter__(self):
for aa, mods in Peptidoform("ACDEM[U:35]K"):
assert isinstance(aa, str)
if mods is not None:
assert isinstance(mods, list)
for mod in mods:
assert isinstance(mod, proforma.TagBase)


def test_rename_modifications(self):
label_mapping = {"ac": "Acetyl", "cm": "Carbamidomethyl"}

Expand Down

0 comments on commit 02cc6ef

Please sign in to comment.