如何使用python编程将一组DNA序列转换为蛋白质序列?

时间:2016-11-27 21:50:49

标签: python python-3.x bioinformatics dna-sequence

我正在使用python创建一个程序,将一组DNA序列转换为氨基酸(蛋白质)序列。然后我需要找到一个特定的子序列,并计算出这个特定子序列所在的序列数。这是我到目前为止的代码:

#Open cDNA_sequences file and read in line by line
with open('cDNA_sequences.csv', 'r') as results:

    for line in results:

        columns = line.rstrip("\n").split(",") #remove end of line characters and split commas to produce a list
        ensemblID = columns[0] #ensemblID is first element in our list
        dna_seq = columns[1] #dna_seq is second element in our list
        genetic code = {


        "UUU":"F", "UUC":"F", "UUA":"L", "UUG":"L",
        "UCU":"S", "UCC":"s", "UCA":"S", "UCG":"S",
        "UAU":"Y", "UAC":"Y", "UAA":"STOP", "UAG":"STOP",
        "UGU":"C", "UGC":"C", "UGA":"STOP", "UGG":"W",
        "CUU":"L", "CUC":"L", "CUA":"L", "CUG":"L",
        "CCU":"P", "CCC":"P", "CCA":"P", "CCG":"P",
        "CAU":"H", "CAC":"H", "CAA":"Q", "CAG":"Q",
        "CGU":"R", "CGC":"R", "CGA":"R", "CGG":"R",
        "AUU":"I", "AUC":"I", "AUA":"I", "AUG":"M",
        "ACU":"T", "ACC":"T", "ACA":"T", "ACG":"T",
        "AAU":"N", "AAC":"N", "AAA":"K", "AAG":"K",
        "AGU":"S", "AGC":"S", "AGA":"R", "AGG":"R",
        "GUU":"V", "GUC":"V", "GUA":"V", "GUG":"V",
        "GCU":"A", "GCC":"A", "GCA":"A", "GCG":"A",
        "GAU":"D", "GAC":"D", "GAA":"E", "GAG":"E",
        "GGU":"G", "GGC":"G", "GGA":"G", "GGG":"G",} #genetic code, telling into which amino acids the DNA triplets translate

        for i in range (0, len(dna_seq), 3):
            codon = dna_seq[i:i+3]
            protein += genetic_code [codon]
        print (protein)                    

    enterokinase_motif = "DDDDK"
    proline_motif = "DDDDKP"
    motif_number = 0
    if enterokinase_motif in line:
        motif_number = motif_number + 1;
    elif proline_number in line:
        motif_number = motif_number;
    else: 
        motif_number = motif_number
    print ("The number of sequences containing one or more enterokinase motifs is []".format(motif_number))

我在编写用于将DNA序列转换为蛋白质序列的代码时遇到问题。

2 个答案:

答案 0 :(得分:4)

您应该阅读Biopython。它提供了与生物学和生物信息学相关的便捷功能和课程。

它有一个功能可以满足您的需求:Bio.Seq.translate

这里有代码示例:

>>> coding_dna = "GTGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG"
>>> translate(coding_dna)
'VAIVMGR*KGAR*'
>>> translate(coding_dna, stop_symbol="@")
'VAIVMGR@KGAR@'
>>> translate(coding_dna, to_stop=True)
'VAIVMGR'

答案 1 :(得分:0)

使用您的密码子图表并考虑终止密码子。 这是一个 python 单线:

print([gencode[i] for i in re.findall(r"[A-Z]{3}", re.sub("AUG(.+)","", input("DNA: ").translate(str().maketrans({"A":"U","T":"A","C":"G","G":"C"}))))])