fix: correct tuple index in ProForma.__getitem__ slicing#213
Conversation
When slicing a ProForma sequence containing a grouped modification (e.g. "#g1"), the loop variable i was reassigned to the (position, tag) tuple returned by find_tags_by_id instead of just the position, then used directly as subseq[i]. Since __getitem__ only accepts int or slice, this raised a TypeError. Use tag_hits[0][0] to pass the position instead of the full tuple. Signed-off-by: Mike German <mike@stepsventures.com>
|
Thank you for reporting this. I believe this is amongst the many historical bugs being fixed in #212. Manually testing your example with that branch worked as expected. Could you please test that branch for your use-case? |
|
Confirmed, thanks @mobiusklein. I checked out from pyteomics import proforma
sub = proforma.ProForma.parse("EMEVT[#g1]S[#g1]ES[#g1]PEK")[2:9]
# -> "EVT[#g1]S[#g1]ES[#g1]P", group_ids == ['#g1']No more If it's useful, the regression test I added here ( |
Bug
Slicing a
ProFormasequence that has a grouped modification (e.g.#g1) raises aTypeError.In
ProForma.__getitem__, when handling a slice, the code loops overtag_hitsfromfind_tags_by_id(group_id, include_position=True), which returns a list of(position, tag)tuples. The loop variableigets reassigned totag_hits[0], the whole tuple, and is then used directly assubseq[i].__getitem__only acceptsintorslice, so indexing with a tuple fails.Repro:
Fix
Use
tag_hits[0][0](the position) instead of the full tuple.Testing
test_slice_grouped_modificationintests/test_proforma.py, which fails with theTypeErrorabove on the old code and passes with the fix.tests/test_proforma.pysuite: 62 passed, 0 failed, no regressions.