Skip to content

Commit 1d0d031

Browse files
committed
feature: add string export method
1 parent 4167d76 commit 1d0d031

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

openms_python/py_aasequence.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import Optional, Literal
66
import pyopenms as oms
77

88

@@ -391,4 +391,27 @@ def has_suffix(self, suffix: str) -> bool:
391391
bool: True if sequence ends with suffix.
392392
"""
393393
return self._sequence.hasSuffix(oms.AASequence.fromString(suffix))
394+
395+
396+
# ===================== Exporting =======================
397+
def to_string(self, modified=True, mod_format: Optional[Literal['unimod', 'bracket']] = 'unimod') -> str:
398+
"""
399+
Get string representation of the sequence.
400+
401+
Returns:
402+
str: Amino acid sequence as string.
394403
404+
Example:
405+
>>> seq = Py_AASequence.from_string("PEPTIDE")
406+
>>> seq_str = seq.to_string()
407+
"""
408+
if not modified:
409+
return self.unmodified_sequence
410+
411+
else:
412+
if mod_format == 'unimod':
413+
return self._sequence.toUniModString()
414+
elif mod_format == 'bracket':
415+
return self._sequence.toBracketString()
416+
else:
417+
raise ValueError(f"Unsupported mod_format: {mod_format}, supported are 'unimod' and 'bracket'")

0 commit comments

Comments
 (0)