cut DNA nucleotide string

Asked

Viewed 71 times

0

Could someone help me in this matter:

I have a nucleotide sequence (letters: A,T,C,G), need to remove part of this sequence and leave only nine nucleotides starting with ATG and ending with TAA... example

AATG ATGCGTTAA AGTCAT

I only need the middle sequence...

2 answers

0

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!!

-2


May make:

todosOsNucleotideos = "AATG ATGCGTTAA AGTCAT"
apenasATGCGTTAA = todosOsNucleotideos[5:14]
  • I’m in Python, sorry I didn’t mention before!! Can help me tbm?

  • I adjusted the answer, then add this information to your question.

  • hasn’t worked yet !!

  • Oops, my bad, I got it right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.