三联密码表 gencode={ 'ATA':'I','ATC':'I','ATT':'I','ATG':'M', 'ACA':'T','ACC':'T','ACG':'T','ACT':'T', 'AAC':'N','AAT':'N','AAA':'K','AAG':'K', 'AGC':'S','AGT':'S','AGA':'R','AGG':'R', 'CTA':'L','CTC':'L','CTG':'L','CTT':'L', 'CCA':'P'
三联密码表
gencode = {'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',
'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',
'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',
'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',
'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',
'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',
'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',
'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',
'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',
'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A',
'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E',
'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G',
'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S',
'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L',
'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_',
'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W'}
测试
dna = "ATGTTCGGTGATGCTACGTAACGT"def translate(dna):
amino_acid_sequence = ""
for start in range(0,len(dna) - 2, 3):
stop = start + 3
codon = dna[start:stop]
aa = gencode.get(codon.upper(),'X') #当指定键的值不存在时,返回X
amino_acid_sequence = amino_acid_sequence + aa
return(amino_acid_sequence)
print(translate(dna))
#用assert断言一个表达式,为 false时触发异常
# input sequence is easy
assert(translate_dna("ATGTTCGGT")) == "MFG"
# input sequence has incomplete codons at the end
assert(translate_dna("ATCGATCGAT")) == "IDR"
# input sequence contains N
assert(translate_dna("ACGANCGAT")) == "TXD"
结果
MFGDAT_R
作者:Bioinfarmer
若要及时了解动态信息,请关注同名微信公众号:Bioinfarmer。