55from typing import Optional , Literal
66import pyopenms as oms
77import warnings
8+ from .py_residue import Py_Residue
89
910
1011class Py_AASequence :
@@ -242,20 +243,20 @@ def __getitem__(self, index):
242243 if step != 1 :
243244 raise ValueError ("Step slicing is not supported for amino acid sequences" )
244245 return Py_AASequence .from_native (self ._sequence .getSubsequence (start , stop - start ))
245- else :
246+ else : # isinstance(index, int)
246247 # Handle negative indices
247248 if index < 0 :
248249 index = len (self ) + index
249250 if index >= len (self ):
250251 raise IndexError (f"Index { index } out of range for sequence of length { len (self )} " )
251- residue = self ._sequence .getSubsequence (index , 1 )
252- return Py_AASequence .from_native (residue )
252+ residue = self ._sequence .getResidue (index )
253+ return Py_Residue .from_native (residue )
253254
254255 def __iter__ (self ):
255256 """Iterate over residues."""
256257 for i in range (len (self )):
257258 yield self [i ]
258- def __add__ (self , other : Py_AASequence | str ) -> Py_AASequence :
259+ def __add__ (self , other : Py_AASequence | str | Py_Residue ) -> Py_AASequence :
259260 """
260261 Concatenate sequences.
261262
@@ -279,6 +280,8 @@ def __add__(self, other: Py_AASequence | str) -> Py_AASequence:
279280 combined_str = self .sequence + other .sequence
280281 elif isinstance (other , str ):
281282 combined_str = self .sequence + other
283+ elif isinstance (other , Py_Residue ):
284+ combined_str = self .sequence + other .one_letter_code
282285 else :
283286 return NotImplemented
284287 return Py_AASequence .from_string (combined_str )
@@ -296,6 +299,9 @@ def __radd__(self, other: str) -> Py_AASequence:
296299 if isinstance (other , str ):
297300 combined_str = other + self .sequence
298301 return Py_AASequence .from_string (combined_str )
302+ if isinstance (other , Py_Residue ):
303+ combined_str = other .one_letter_code + self .sequence
304+ return Py_AASequence .from_string (combined_str )
299305 return NotImplemented
300306
301307 def __mul__ (self , times : int ) -> Py_AASequence :
0 commit comments