BjornFJohansson / pydna

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

Different behaviour of __getitem__ in Dseqrecord and Dseq #161

Closed manulera closed 9 months ago

manulera commented 12 months ago

Illustrated by this example, see <<<<<<<<<<<<<

Not sure which of the two should be kept, probably the one of Dseqrecord to be consistent with the string behaviour, and use shift instead of seq[n:n] to rotate the origin.

print(Seq('AAAA')[0:0])
# empty sequence

print(SeqRecord(Seq('AAAA'))[0:0].seq)
# empty sequence

print(Dseq('AAAA', circular=True)[0:0])
# AAAA

print(Dseq('AAAA', circular=False)[0:0])
# Empty sequence

print(Dseq('AAAA', circular=True)[1:1])
# AAAA

print(Dseq('AAAA', circular=False)[1:1])
# Empty sequence <<<<<<<<<<<<<

print(Dseqrecord('AAAA', circular=True)[0:0].seq)
# AAAA

print(Dseqrecord('AAAA', circular=False)[0:0].seq)
# Empty sequence

print(Dseqrecord('AAAA', circular=True)[1:1].seq)
# Empty sequence <<<<<<<<<<<<<

print(Dseqrecord('AAAA', circular=False)[1:1].seq)
# Empty sequence
manulera commented 10 months ago

The Dseqrecord('AAAA', circular=True)[1:1] is problematic and I think should be considered a bug, I think it would be desirable to have it work as [0:0].

from pydna.dseqrecord import Dseqrecord

seq = Dseqrecord('AAAA', circular=True)
print(seq[0:0].seq)
print(seq[0:len(seq)].seq)

seq = Dseqrecord('AAAA', circular=True)
print(seq[1:1].seq)
print(seq[1:1+len(seq)].seq)

# prints
# AAAA
# AAAA
# empty string
# empty string
manulera commented 10 months ago

@BjornFJohansson dixit: Behaviour should be like the Dseq