I'm analyzing an RNA sequence in which I need to reed the codons. I first need to split up my nucleotide string into a list of three pairs, but I have to give my function a reading_frame parameter that either starts reading the string at index 1, 2, or 3.
I made this code and do not know why it will not work, I get an incompletely read list whenever I do it for any index.
sequence = self.sequence.upper()
split_sequence = []
while len(sequence) >= 3:
split_sequence.append(sequence[reading_frame:reading_frame + 3])
reading_frame = reading_frame + 3
sequence = sequence[reading_frame:]
return split_sequence
I also tried to use conditionals and regex but can't figure out how I would do the regex for the index(reading_frame) 1 and 2
if reading_frame == 0:
split_sequence = re.findall(r'...', sequence)
if reading_frame == 1:
split_sequence = re.findall(r'', sequence)
if reading_frame == 2:
split_sequence = re.findall(r'', sequence)
Any ideas on how to fix these methods, or is there any easier way to do this? Thanks!