You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SeqRecord.reverse_complement() edits parent sequence in place #5015
ifisinstance(letter_annotations, dict):
answer.letter_annotations=letter_annotationselifletter_annotations:
# Copy the old per letter annotations, reversing themforkey, valueinself.letter_annotations.items():
answer.letter_annotations[key] =value[::-1]
This calls the .letters_annotations property which will initialize the dict as the internal value was still None. So it is just a delayed initialization.
This calls the .letters_annotations property which will initialize the dict as the internal value was still None. So it is just a delayed initialization.
But in general we don't want to initialize _per_letter_annotations if there is no need for it. Then I think reverse_complement should look at _per_letter_annotations instead of letter_annotations, and do nothing if _per_letter_annotations is None.
For context, in pydna we have an equality function for seqrecords which we use in tests. I know you specifically discourage this but it is quite handy to compare objects to be equal in tests. That's how it impacts us.
Activity
manulera commentedon Jun 18, 2025
I am happy to contribute the fix, but I don't really know where to start looking.
peterjc commentedon Jun 21, 2025
The sequence is NOT edited (as per the issue title):
Nor does the public property
.letter_annotationschange:Yes, it looks like the private property
._per_letter_annotationsgets initialised fromNoneto{}but that is an internal implementation detail.mdehoon commentedon Jun 21, 2025
Still it is strange that this happens.
peterjc commentedon Jun 21, 2025
It happens here in the reverse-complement method:
This calls the
.letters_annotationsproperty which will initialize the dict as the internal value was stillNone. So it is just a delayed initialization.mdehoon commentedon Jun 21, 2025
But in general we don't want to initialize
_per_letter_annotationsif there is no need for it. Then I thinkreverse_complementshould look at_per_letter_annotationsinstead ofletter_annotations, and do nothing if_per_letter_annotationsisNone.peterjc commentedon Jun 21, 2025
That would be better I suppose.
manulera commentedon Jun 23, 2025
For context, in pydna we have an equality function for seqrecords which we use in tests. I know you specifically discourage this but it is quite handy to compare objects to be equal in tests. That's how it impacts us.
Prevent side-effect in SeqRecord._per_letter_annotations
Prevent side-effect in SeqRecord._per_letter_annotations
Prevent side-effect in SeqRecord._per_letter_annotations