001、 利用循环结构实现
[root@PC1 test01]# ls a.fa test.py [root@PC1 test01]# cat a.fa ## 测试RNA序列 AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA [root@PC1 test01]# cat test.py ## 翻译程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file = open("a.fa", "r") file = in_file.read().strip() in_file.close() table = { 'UUU':'F','CUU':'L','AUU':'I','GUU':'V', 'UUC':'F','CUC':'L','AUC':'I','GUC':'V', 'UUA':'L','CUA':'L','AUA':'I','GUA':'V', 'UUG':'L','CUG':'L','AUG':'M','GUG':'V', 'UCU':'S','CCU':'P','ACU':'T','GCU':'A', 'UCC':'S','CCC':'P','ACC':'T','GCC':'A', 'UCA':'S','CCA':'P','ACA':'T','GCA':'A', 'UCG':'S','CCG':'P','ACG':'T','GCG':'A', 'UAU':'Y','CAU':'H','AAU':'N','GAU':'D', 'UAC':'Y','CAC':'H','AAC':'N','GAC':'D', 'UAA':'Stop','CAA':'Q','AAA':'K','GAA':'E', 'UAG':'Stop','CAG':'Q','AAG':'K','GAG':'E', 'UGU':'C','CGU':'R','AGU':'S','GGU':'G', 'UGC':'C','CGC':'R','AGC':'S','GGC':'G', 'UGA':'Stop','CGA':'R','AGA':'R','GGA':'G', 'UGG':'W','CGG':'R','AGG':'R','GGG':'G' } str1 = "" if len(file) % 3 != 0: print("no integrate sequence!") exit else: for i in range(0, len(file), 3): idx = file[i:i+3] if table[idx] == "Stop": exit else: str1 += table[idx] print(str1) [root@PC1 test01]# python test.py ## 翻译结果 MAMAPRTEINSTRING
002、解法2
[root@PC1 test01]# ls a.fa test.py [root@PC1 test01]# cat a.fa ## 测试RNA序列 AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA [root@PC1 test01]# cat test.py ## 翻译程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file = open("a.fa", "r") file = in_file.read().strip() table = { 'UUU':'F','CUU':'L','AUU':'I','GUU':'V', 'UUC':'F','CUC':'L','AUC':'I','GUC':'V', 'UUA':'L','CUA':'L','AUA':'I','GUA':'V', 'UUG':'L','CUG':'L','AUG':'M','GUG':'V', 'UCU':'S','CCU':'P','ACU':'T','GCU':'A', 'UCC':'S','CCC':'P','ACC':'T','GCC':'A', 'UCA':'S','CCA':'P','ACA':'T','GCA':'A', 'UCG':'S','CCG':'P','ACG':'T','GCG':'A', 'UAU':'Y','CAU':'H','AAU':'N','GAU':'D', 'UAC':'Y','CAC':'H','AAC':'N','GAC':'D', 'UAA':'Stop','CAA':'Q','AAA':'K','GAA':'E', 'UAG':'Stop','CAG':'Q','AAG':'K','GAG':'E', 'UGU':'C','CGU':'R','AGU':'S','GGU':'G', 'UGC':'C','CGC':'R','AGC':'S','GGC':'G', 'UGA':'Stop','CGA':'R','AGA':'R','GGA':'G', 'UGG':'W','CGG':'R','AGG':'R','GGG':'G' } str1 = "" while(len(file) >= 3): idx = file[0:3] if table[idx] != "Stop": str1 += table[idx] else: break file = file[3:] print(str1) [root@PC1 test01]# python3 test.py ## 翻译结果 MAMAPRTEINSTRING
标签:python,RNA,PC1,Stop,test,file,序列,test01,root From: https://www.cnblogs.com/liujiaxin2018/p/17660750.html