Problem
The 20 commonly occurring amino acids are abbreviated by using 20 letters from the English alphabet (all letters except for B, J, O, U, X, and Z). Protein strings are constructed from these 20 symbols. Henceforth, the term genetic string will incorporate protein strings along with DNA strings and RNA strings.The RNA codon table dictates the details regarding the encoding of specific codons into the amino acid alphabet.
从rna到protein
问题:input: 对于给定的rna sequenceoutput: 蛋白质序列
input: AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGAoutput: MAMAPRTEINSTRING
思路:
- 拆分序列,然后翻译成protein,可以利用生成器实现快速转换
solution -1
```python pro_dic = {‘GCU’:’A’, ‘GCC’:’A’, ‘GCA’:’A’, ‘GCG’:’A’, ‘CGU’:’R’, ‘CGC’:’R’, ‘CGA’:’R’, ‘CGG’:’R’, ‘AGA’:’R’, ‘AGG’:’R’, ‘UCU’:’S’, ‘UCC’:’S’, ‘UCA’:’S’, ‘UCG’:’S’, ‘AGU’:’S’, ‘AGC’:’S’, ‘AUU’:’I’, ‘AUC’:’I’, ‘AUA’:’I’, ‘UUA’:’L’, ‘UUG’:’L’, ‘CUU’:’L’, ‘CUC’:’L’, ‘CUA’:’L’, ‘CUG’:’L’, ‘GGU’:’G’, ‘GGC’:’G’, ‘GGA’:’G’, ‘GGG’:’G’, ‘GUU’:’V’, ‘GUC’:’V’, ‘GUA’:’V’, ‘GUG’:’V’, ‘ACU’:’T’, ‘ACC’:’T’, ‘ACA’:’T’, ‘ACG’:’T’, ‘CCU’:’P’, ‘CCC’:’P’, ‘CCA’:’P’, ‘CCG’:’P’, ‘AAU’:’N’, ‘AAC’:’N’, ‘GAU’:’D’, ‘GAC’:’D’, ‘UGU’:’C’, ‘UGC’:’C’, ‘CAA’:’Q’, ‘CAG’:’Q’, ‘GAA’:’E’, ‘GAG’:’E’, ‘CAU’:’H’, ‘CAC’:’H’, ‘AAA’:’K’, ‘AAG’:’K’, ‘UUU’:’F’, ‘UUC’:’F’, ‘UAU’:’Y’, ‘UAC’:’Y’, ‘AUG’:’M’, ‘UGG’:’W’,’UAG’:’’, ‘UGA’:’’, ‘UAA’:’’}
def rna2protein(seq, nbase = 3, start_at = 0, base_dict = pro_dic): pos_all = (pos for pos in range(start_at, len(seq)) if pos % nbase == 0) seq_all = (seq[pos : pos + nbase] for pos in pos_all) seq_filter = filter(lambda x: len(x) >= nbase, seq_all) protein_seq = “”.join(map(lambda x: pro_dic[x], seq_filter)) return protein_seq
def main(): rna2protein(“AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA”)
if name == ‘main‘: main()
<a name="vYyPi"></a>## solution-2利用`re`库的函数,速度比较慢```pythonimport redef rna2protein2(seq, nbase = 3, start_at = 0, base_dict = pro_dic):seq_use = seq[start_at:]seq_all = re.findall(r".{nbase}",seq_use)protein_seq = "".join(map(lambda x: pro_dic[x], seq_all))return protein_seqdef main():print(rna2protein("AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA"))if __name__ == '__main__':main()
