BjornFJohansson / pydna

Clone with Python! Data structures for double stranded DNA & simulation of homologous recombination, Gibson assembly, cut & paste cloning.
Other
160 stars 39 forks source link

Dseqrecord.shifted with argument 0 does not return a copy of the sequence, but the sequence itself #194

Closed manulera closed 5 months ago

manulera commented 5 months ago

This can be problematic if a function is using the value to shifted as an argument, and this can be zero. In that case, this unintended behaviour happens:

from pydna.dseqrecord import Dseqrecord
from Bio.SeqFeature import SeqFeature, SimpleLocation

dseqr = Dseqrecord('ACCGGGTTTT', circular=True)
dseqr.features = [SeqFeature(SimpleLocation(0, 3, 1), type='misc_feature')]

# Shift by zero, returns the same sequence
dseqr_shifted = dseqr.shifted(0)

print(dseqr is dseqr_shifted) # Should be False, but it's True

# Add a feature to the shifted sequence
dseqr_shifted.features += [SeqFeature(SimpleLocation(3, 9, 1), type='misc_feature')]

print(len(dseqr.features)) #Should be 1, but it's 2
print(len(dseqr_shifted.features)) # Should be 2, it's 2