-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmrna.py
More file actions
31 lines (22 loc) · 887 Bytes
/
mrna.py
File metadata and controls
31 lines (22 loc) · 887 Bytes
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
# Given: A protein string of length at most 1000 aa.
# Return: The total number of different RNA strings from which the protein could have been
# translated, modulo 1,000,000. (Don't neglect the importance of the stop codon in protein translation.)
from utils import RNA_CODON_TABLE
## test cases
SAMPLE_DATASET = "MA"
SAMPLE_OUTPUT = "12"
def main(protein_string):
# for stop codons
counter = 3
for amino_acid in protein_string:
counter *= sum([bool(value) for key, value in RNA_CODON_TABLE.items() if value == amino_acid])
print counter % 1000000
return str(counter % 1000000)
if __name__ == "__main__":
## Test
# main(SAMPLE_DATASET)
assert main(SAMPLE_DATASET) == SAMPLE_OUTPUT
# Prod
with open("./datasets/rosalind_mrna.txt", 'r') as fptr:
protein_string = fptr.read().strip()
main(protein_string)