"1.4) Write a function to translate DNA sequences in all 6 frames into peptide sequences! The longest peptide sequence per DNA sequence should be returned!\n"
1.4) Write a function to translate DNA sequences in all 6 frames into peptide sequences! The longest peptide sequence per DNA sequence should be returned!
%% Cell type:code id: tags:
```
"""
Translates a DNA sequence in all 6 frames into peptide sequences
and yields the peptide sequences.
"""
def translate_all_frames(sequence):
for i in range(3):
yield translate(sequence[i:])
rev_comp = get_reverse_complement(sequence)
for i in range(3):
yield translate(rev_comp[i:])
"""
Find a longest valid peptide sequence, meaning one that starts with
M, in a peptide sequence.
"""
def get_longest_peptide_sequence(sequence):
longest_length = 0
longest_peptide_sequence = ""
current_sequence = []
currently_in_sequence = False
for peptide in sequence:
if currently_in_sequence:
# encounter a stop codon
if peptide == "*":
if current_sequence:
# update longest observed sequence and length if necessary