翻译我的序列?

时间:2012-01-02 12:36:32

标签: python sorting python-3.x translation sequences

我必须编写一个脚本来翻译这个序列:

dict = {"TTT":"F|Phe","TTC":"F|Phe","TTA":"L|Leu","TTG":"L|Leu","TCT":"S|Ser","TCC":"S|Ser",
              "TCA":"S|Ser","TCG":"S|Ser", "TAT":"Y|Tyr","TAC":"Y|Tyr","TAA":"*|Stp","TAG":"*|Stp",
              "TGT":"C|Cys","TGC":"C|Cys","TGA":"*|Stp","TGG":"W|Trp", "CTT":"L|Leu","CTC":"L|Leu",
              "CTA":"L|Leu","CTG":"L|Leu","CCT":"P|Pro","CCC":"P|Pro","CCA":"P|Pro","CCG":"P|Pro",
              "CAT":"H|His","CAC":"H|His","CAA":"Q|Gln","CAG":"Q|Gln","CGT":"R|Arg","CGC":"R|Arg",
              "CGA":"R|Arg","CGG":"R|Arg", "ATT":"I|Ile","ATC":"I|Ile","ATA":"I|Ile","ATG":"M|Met",
              "ACT":"T|Thr","ACC":"T|Thr","ACA":"T|Thr","ACG":"T|Thr", "AAT":"N|Asn","AAC":"N|Asn",
              "AAA":"K|Lys","AAG":"K|Lys","AGT":"S|Ser","AGC":"S|Ser","AGA":"R|Arg","AGG":"R|Arg",
              "GTT":"V|Val","GTC":"V|Val","GTA":"V|Val","GTG":"V|Val","GCT":"A|Ala","GCC":"A|Ala",
              "GCA":"A|Ala","GCG":"A|Ala", "GAT":"D|Asp","GAC":"D|Asp","GAA":"E|Glu",
              "GAG":"E|Glu","GGT":"G|Gly","GGC":"G|Gly","GGA":"G|Gly","GGG":"G|Gly"}

seq = "TTTCAATACTAGCATGACCAAAGTGGGAACCCCCTTACGTAGCATGACCCATATATATATATATA"
a=""

for y in range( 0, len ( seq)):
    c=(seq[y:y+3])
    #print(c)
    for  k, v in dict.items():
        if seq[y:y+3] == k:
            alle_amino = v[::3] #alle aminozuren op rijtje, a1.1 -a2.1- a.3.1-a1.2 enzo
            print (v)

使用这个脚本我可以得到彼此相差3帧的氨基酸,但是我怎样才能对它进行分类并将第1帧中的所有氨基酸彼此相邻,并且每个氨基酸来自第2帧的所有氨基酸。另外,第3帧也一样吗?

例如,我的结果必须是:

+3 SerIleLeuAlaStpProLysTrpGluProProTyrValAlaStpProIleTyrIleTyrTle

+2 PheAsnThrSerMetThrLysValGlyThrProLeuArgSerMetThrHisIleTyrIleTyr

+1 PheGlnTyrStpHisAspGlnSerGlyAsnProLeuThrStpHisAspProTyrIleTyrIle

TTTCAATACTAGCATGACCAAAGTGGGAACCCCCTTACGTAGCATGACCCATATATATATATATA

我使用Python 3。

  
    

我还有一个问题:我可以通过我自己的脚本中的某些更改来制作此结果吗?

  

3 个答案:

答案 0 :(得分:5)

你可以使用(注意使用biopython翻译方法会更容易得多):

dictio = {your dictionary here}

def translate(seq):
    x = 0
    aaseq = []
    while True:
        try:
            aaseq.append(dicti[seq[x:x+3]])
            x += 3
        except (IndexError, KeyError):
            break
    return aaseq

seq = "TTTCAATACTAGCATGACCAAAGTGGGAACCCCCTTACGTAGCATGACCCATATATATATATATA"

for frame in range(3):
    print('+%i' %(frame+1), ''.join(item.split('|')[1] for item in translate(seq[frame:])))

注意我使用dicti更改了字典的名称(而不是覆盖dict)。


一些评论可以帮助您理解:

translate接受序列并以列表的形式返回,其中每个项目对应于编码该位置的三联体的氨基酸翻译。像:

aaseq = ["L|Leu","L|Leu","P|Pro", ....]

你可以在translate内处理更多这些数据(只获得一个或三个字母代码),或者按照我的方式将其返回处理。

translate

中调用
''.join(item.split('|')[1] for item in translate(seq[frame:]))

每帧。对于帧值为0,1或2,它发送seq [frame:]作为要翻译的参数。也就是说,您正在发送与三个不同阅读框相对应的序列,并将它们串行处理。然后,在

   ''.join(item.split('|')[1]

我将每个氨基酸的一个和三个字母的代码分开,然后在索引1(第二个)处取一个。然后他们加入一个字符串

答案 1 :(得分:1)

不太漂亮,但做你想做的事

dct = {"TTT":"F|Phe","TTC":"F|Phe","TTA":"L|Leu","TTG":"L|Leu","TCT":"S|Ser","TCC":"S|Ser", 
"TCA":"S|Ser","TCG":"S|Ser", "TAT":"Y|Tyr","TAC":"Y|Tyr","TAA":"*|Stp","TAG":"*|Stp", 
"TGT":"C|Cys","TGC":"C|Cys","TGA":"*|Stp","TGG":"W|Trp", "CTT":"L|Leu","CTC":"L|Leu", 
"CTA":"L|Leu","CTG":"L|Leu","CCT":"P|Pro","CCC":"P|Pro","CCA":"P|Pro","CCG":"P|Pro", 
"CAT":"H|His","CAC":"H|His","CAA":"Q|Gln","CAG":"Q|Gln","CGT":"R|Arg","CGC":"R|Arg", 
"CGA":"R|Arg","CGG":"R|Arg", "ATT":"I|Ile","ATC":"I|Ile","ATA":"I|Ile","ATG":"M|Met", 
"ACT":"T|Thr","ACC":"T|Thr","ACA":"T|Thr","ACG":"T|Thr", "AAT":"N|Asn","AAC":"N|Asn", 
"AAA":"K|Lys","AAG":"K|Lys","AGT":"S|Ser","AGC":"S|Ser","AGA":"R|Arg","AGG":"R|Arg", 
"GTT":"V|Val","GTC":"V|Val","GTA":"V|Val","GTG":"V|Val","GCT":"A|Ala","GCC":"A|Ala", 
"GCA":"A|Ala","GCG":"A|Ala", "GAT":"D|Asp","GAC":"D|Asp","GAA":"E|Glu", 
"GAG":"E|Glu","GGT":"G|Gly","GGC":"G|Gly","GGA":"G|Gly","GGG":"G|Gly"}


seq = "TTTCAATACTAGCATGACCAAAGTGGGAACCCCCTTACGTAGCATGACCCATATATATATATATA"

def get_amino_list(s):
    for y in range(3):
        yield [s[x:x+3] for x in range(y, len(s) - 2, 3)]

for n, amn in enumerate(get_amino_list(seq), 1):
    print ("+%d " % n + "".join(dct[x][2:] for x in amn))

print(seq)

答案 2 :(得分:1)

这是我的解决方案。我打电话给你的" dict"变量" aminos"。函数method3返回" |"右侧的值列表。要将它们合并为一个字符串,只需将它们加入""。

通过查看您的代码,我相信您的aminos dict包含所有可能的三个字母组合。因此,我已经删除了验证这一点的检查。结果它应该运行得更快。

def overlapping_groups(seq, group_len=3):
    """Returns `N` adjacent items from an iterable in a sliding window style
    """
    for i in range(len(seq)-group_len):
        yield seq[i:i+group_len]

def method3(seq, aminos):
    return [aminos[k][2:] for k in overlapping_groups(seq, 3)]

for i in range(3):
    print("%d: %s" % (i, "".join(method3(seq[i:], aminos))))