@@ -118,25 +118,22 @@ def test_py_aasequence_iteration():
118118 seq = Py_AASequence .from_string ("PEPTIDE" )
119119 residues = list (seq )
120120
121- assert residues == ["P" , "E" , "P" , "T" , "I" , "D" , "E" ]
121+ assert [ res . sequence for res in residues ] == ["P" , "E" , "P" , "T" , "I" , "D" , "E" ]
122122 assert len (residues ) == 7
123123
124124
125125def test_py_aasequence_indexing ():
126126 """Test indexing into sequence."""
127127 seq = Py_AASequence .from_string ("PEPTIDE" )
128128
129- assert seq [0 ] == "P"
130- assert seq [1 ] == "E"
131- assert seq [6 ] == "E"
129+ assert seq [0 ]. sequence == "P"
130+ assert seq [1 ]. sequence == "E"
131+ assert seq [6 ]. sequence == "E"
132132
133133 # Test out of bounds
134134 with pytest .raises (IndexError ):
135135 _ = seq [7 ]
136136
137- with pytest .raises (IndexError ):
138- _ = seq [- 1 ]
139-
140137
141138def test_py_aasequence_string_representation ():
142139 """Test string representations."""
@@ -258,3 +255,37 @@ def test_py_aasequence_with_native_aasequence():
258255
259256 assert seq .sequence == "PEPTIDE"
260257 assert seq .native is native
258+
259+
260+ def test_py_aasequence_to_string ():
261+ """Test to_string method with different options."""
262+ seq = Py_AASequence .from_string ("PEPTIDEM(Oxidation)" )
263+
264+ # Default should return modified string in default format
265+ mod_str = seq .to_string ()
266+ assert mod_str == "PEPTIDEM(Oxidation)"
267+
268+ # Unmodified should return unmodified sequence
269+ unmod_str = seq .to_string (modified = False )
270+ assert unmod_str == "PEPTIDEM"
271+
272+ # Bracket format
273+ bracket_str = seq .to_string (modified = True , mod_format = 'bracket' )
274+ assert bracket_str == "PEPTIDEM[147]"
275+
276+ # unimod format
277+ unimod_str = seq .to_string (modified = True , mod_format = 'unimod' )
278+ assert unimod_str == "PEPTIDEM(UniMod:35)"
279+
280+ # Invalid format should raise error
281+ with pytest .raises (ValueError ):
282+ _ = seq .to_string (modified = True , mod_format = 'invalid_format' )
283+
284+
285+ def test_slicing ():
286+ aa_seq = Py_AASequence .from_string ('PEPTIDEM(Oxidation)R' )
287+ assert aa_seq [0 ].sequence == 'P'
288+ assert aa_seq [- 1 ].sequence == 'R'
289+ assert aa_seq [1 :4 ].sequence == 'EPT'
290+ assert aa_seq [- 2 :].sequence == 'M(Oxidation)R'
291+
0 commit comments