First of all, you can not assign some values and name a variable like start+1
, start+2
and so on. Next, as it is related to bioinformatics you can tag your question as bioinformatics. Also, you are repeating many of the stuffs three times that is too bad as a programmer. However, you can try with the following snippet:
class Codons(object):
def __init__(self, seq):
self.seq = seq
def codons(self, frame_one, frame_two, frame_three):
while frame_one <=len(self.seq):
yield (self.seq[frame_one:frame_one+3])
frame_one += 3
while frame_two <=len(self.seq):
yield (self.seq[frame_two:frame_two+3])
frame_two += 3
while frame_three <=len(self.seq):
yield (self.seq[frame_three:frame_three+3])
frame_three += 3
test_codons = Codons("ATCGTG-")
val = test_codons.codons(0,1,2)
print("Codons are: ")
for i in val:
print(i)
print("")
And let us know if it worked for you. Cheers!!