1

我试图在我的 cds 中找到起始和终止密码子。我使用了正则表达式,但是当我运行这个 python 脚本时,我得到了一个空的终止密码子列表。任何帮助是极大的赞赏。

std_code = {"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"}

cds = ("ATGCTAGCGGTAAATCGTGAATAGGCCTAA")
for i in range (0, len(cds),3):
    print cds[i:i+3]

def translate (cds, std_code):
    protein = ""
    for i in range (0,len(cds),3):
        codon = cds[i:i+3]
        protein = protein + std_code[codon]
    return protein
print translate(cds, std_code)
def codon_usage(cds):
    usage = {}
    for i in range(0,len(cds),3):
        codon = cds[i:i+3]
        if usage.has_key(codon):
            usage[codon] += 1
        else:
            usage[codon] = 1
    return usage
print codon_usage(cds)


import re
pat = '(ATG)+?(?:TAA|TGA|TAG)'
reg = re.compile(pat)
def stop_codons(cds, messages=None,s=0,reg=reg):
    stop_codons = []
    while True:
        ma = reg.search(cds[s:])
        if ma:
            if ma.group(1) == 'ATG':
                break
            else:
                stop_codons.append(ma.group.upper())
                s = s + ma.start() + 1
        else:
            break
    return stop_codons
print stop_codons(cds, messages=None, s=0,reg=reg)      
4

2 回答 2

3

你考虑过使用Biopython吗?它具有各种用于处理序列的内置工具,如果您正在做与生物信息学相关的任何事情,可以为您节省大量时间。特别是,该Seq对象正是您要查找的内容:

>>> from Bio.Seq import Seq
>>> from Bio.Alphabet import generic_dna
>>> my_dna = Seq("AGTACACTGGT", generic_dna)
>>> my_dna
Seq('AGTACACTGGT', DNAAlphabet())
>>> my_dna.find("ACT")
5

我强烈建议阅读教程API 文档以查找有关字母、密码子表 ( Bio.Data.CodonTable) 等内容的信息。

于 2013-03-19T14:19:42.303 回答
2

stop_codons我发现您的功能存在一些问题。首先,您的正则表达式:

(ATG)+?(?:TAA|TGA|TAG)

正如它所写的,这是搜索起始密码子的重复,然后是终止密码子。如果你写的正则表达式匹配,它只会返回起始密码子,没有别的。如果您想在起始密码子之后找到第一个终止密码子,您可以尝试:

(?<=ATG)(?:[ACGT]{3})*(TAA|TGA|TAG)

其次,如果您的正则表达式与起始密码子匹配,它将打破循环并返回您的列表stop_codons,假设您传递给此函数的每个序列在停止之前都包含一个起始密码子,则总是会导致返回一个空列表. 希望这可以帮助。

于 2013-03-19T14:39:55.507 回答