The following program extracts the codons in the frame specified by frame
(0
, 1
or 2
). After working out where to end the loop over the sequence string, we append the slices of three characters to the codon
list.
seq = 'AGTCTTATATCT'
frame = 0 # or 1 or 2
seq_length = len(seq[frame:])
end = seq_length - seq_length % 3
codons = []
for i in range(frame, end, 3):
codons.append(seq[i:i+3])
print(codons)