-
Notifications
You must be signed in to change notification settings - Fork 27
/
translate.py
104 lines (82 loc) · 3.98 KB
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/env python3
import sys
def translate_sequence(rna_sequence, genetic_code):
"""Translates a sequence of RNA into a sequence of amino acids.
Translates `rna_sequence` into string of amino acids, according to the
`genetic_code` given as a dict. Translation begins at the first position of
the `rna_sequence` and continues until the first stop codon is encountered
or the end of `rna_sequence` is reached.
If `rna_sequence` is less than 3 bases long, or starts with a stop codon,
an empty string is returned.
"""
pass
def get_all_translations(rna_sequence, genetic_code):
"""Get a list of all amino acid sequences encoded by an RNA sequence.
All three reading frames of `rna_sequence` are scanned from 'left' to
'right', and the generation of a sequence of amino acids is started
whenever the start codon 'AUG' is found. The `rna_sequence` is assumed to
be in the correct orientation (i.e., no reverse and/or complement of the
sequence is explored).
The function returns a list of all possible amino acid sequences that
are encoded by `rna_sequence`.
If no amino acids can be translated from `rna_sequence`, an empty list is
returned.
"""
pass
def get_reverse(sequence):
"""Reverse orientation of `sequence`.
Returns a string with `sequence` in the reverse order.
If `sequence` is empty, an empty string is returned.
"""
pass
def get_complement(sequence):
"""Get the complement of `sequence`.
Returns a string with the complementary sequence of `sequence`.
If `sequence` is empty, an empty string is returned.
"""
pass
def reverse_and_complement(sequence):
"""Get the reversed and complemented form of `sequence`.
Returns a string that is the reversed and complemented sequence
of `sequence`.
If `sequence` is empty, an empty string is returned.
"""
pass
def get_longest_peptide(rna_sequence, genetic_code):
"""Get the longest peptide encoded by an RNA sequence.
Explore six reading frames of `rna_sequence` (the three reading frames of
`rna_sequence`, and the three reading frames of the reverse and complement
of `rna_sequence`) and return (as a string) the longest sequence of amino
acids that it encodes, according to the `genetic_code`.
If no amino acids can be translated from `rna_sequence` nor its reverse and
complement, an empty string is returned.
"""
pass
if __name__ == '__main__':
genetic_code = {'GUC': 'V', 'ACC': 'T', 'GUA': 'V', 'GUG': 'V', 'ACU': 'T', 'AAC': 'N', 'CCU': 'P', 'UGG': 'W', 'AGC': 'S', 'AUC': 'I', 'CAU': 'H', 'AAU': 'N', 'AGU': 'S', 'GUU': 'V', 'CAC': 'H', 'ACG': 'T', 'CCG': 'P', 'CCA': 'P', 'ACA': 'T', 'CCC': 'P', 'UGU': 'C', 'GGU': 'G', 'UCU': 'S', 'GCG': 'A', 'UGC': 'C', 'CAG': 'Q', 'GAU': 'D', 'UAU': 'Y', 'CGG': 'R', 'UCG': 'S', 'AGG': 'R', 'GGG': 'G', 'UCC': 'S', 'UCA': 'S', 'UAA': '*', 'GGA': 'G', 'UAC': 'Y', 'GAC': 'D', 'UAG': '*', 'AUA': 'I', 'GCA': 'A', 'CUU': 'L', 'GGC': 'G', 'AUG': 'M', 'CUG': 'L', 'GAG': 'E', 'CUC': 'L', 'AGA': 'R', 'CUA': 'L', 'GCC': 'A', 'AAA': 'K', 'AAG': 'K', 'CAA': 'Q', 'UUU': 'F', 'CGU': 'R', 'CGC': 'R', 'CGA': 'R', 'GCU': 'A', 'GAA': 'E', 'AUU': 'I', 'UUG': 'L', 'UUA': 'L', 'UGA': '*', 'UUC': 'F'}
rna_seq = ("AUG"
"UAC"
"UGG"
"CAC"
"GCU"
"ACU"
"GCU"
"CCA"
"UAU"
"ACU"
"CAC"
"CAG"
"AAU"
"AUC"
"AGU"
"ACA"
"GCG")
longest_peptide = get_longest_peptide(rna_sequence = rna_seq,
genetic_code = genetic_code)
assert isinstance(longest_peptide, str), "Oops: the longest peptide is {0}, not a string".format(longest_peptide)
message = "The longest peptide encoded by\n\t'{0}'\nis\n\t'{1}'\n".format(
rna_seq,
longest_peptide)
sys.stdout.write(message)
if longest_peptide == "MYWHATAPYTHQNISTA":
sys.stdout.write("Indeed.\n")