Problem

  1. 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.
  2. The RNA codon table dictates the details regarding the encoding of specific codons into the amino acid alphabet.

从rna到protein

问题:
input: 对于给定的rna sequence
output: 蛋白质序列

  1. input: AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA
  2. output: 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()

  1. <a name="vYyPi"></a>
  2. ## solution-2
  3. 利用`re`库的函数,速度比较慢
  4. ```python
  5. import re
  6. def rna2protein2(seq, nbase = 3, start_at = 0, base_dict = pro_dic):
  7. seq_use = seq[start_at:]
  8. seq_all = re.findall(r".{nbase}",seq_use)
  9. protein_seq = "".join(map(lambda x: pro_dic[x], seq_all))
  10. return protein_seq
  11. def main():
  12. print(rna2protein("AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA"))
  13. if __name__ == '__main__':
  14. main()