The solution is to iterate over each nucleotide in the DNA sequence, take the nucleotide + the following two and check if this triad is "ATG". If so, we repeat the meso process until we find the AAR:
dna = "AATGATGCGTTAAAGTCAT"
result = ""
for index in range(len(dna)):
start = dna[index:index+3]
if start == 'ATG':
sliced_dna = dna[index:]
for subindex in range(len(sliced_dna)):
end = sliced_dna[subindex:subindex+3]
if end == 'TAA':
result = sliced_dna[:subindex+3]
print(result) # ATGCGTTAA
Note that the operation to find the beginning and the end of the sequence is basically the same - we could simplify this code by defining functions rather than for loops within for loops, but the operation is the same.
As I wrote, the program looks for the last sequence "TAA", if you want to stop at the first it will be necessary to use break
to stop the loops early.
thank you so much!! It worked out and I understood!!
– Thiely Fabian