diff --git a/pyteomics/proforma.py b/pyteomics/proforma.py index 0aefccc3..184c98a2 100644 --- a/pyteomics/proforma.py +++ b/pyteomics/proforma.py @@ -3835,7 +3835,7 @@ def __getitem__(self, i: Union[int, slice]): # not the actual modification definition. Update the first occurrence of the # localization marker with a group id marked modification tag. if all(not isinstance(v, LocalizationMarker) for _, v in tag_hits): - i = tag_hits[0] + i = tag_hits[0][0] val: TagBase for val in self.find_tags_by_id(group_id, include_position=False): if not isinstance(val, LocalizationMarker): diff --git a/tests/test_proforma.py b/tests/test_proforma.py index 1cbe78e7..5ee1c363 100644 --- a/tests/test_proforma.py +++ b/tests/test_proforma.py @@ -129,6 +129,16 @@ def test_slice(self): assert i[1:].n_term is None assert i[1:].c_term is not None + def test_slice_grouped_modification(self): + # Regression test: slicing a sequence with a grouped modification tag + # (e.g. "#g1") used to raise a TypeError because the tag position tuple + # returned by find_tags_by_id was used directly as a sequence index. + seq = "EMEVT[#g1]S[#g1]ES[#g1]PEK" + i = ProForma.parse(seq) + sub = i[2:9] + self.assertEqual(str(sub), "EVT[#g1]S[#g1]ES[#g1]P") + self.assertEqual(sub.group_ids, ['#g1']) + def test_charge_adducts(self): sequences = ['PEPTIDE/1[+2Na+,-H+]', 'PEPTIDE/-1[+e-]', 'PEPTIDE/1[+2H+,+e-]'] charges = [1, -1, 1]