Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 生物信息学:找到给定基因组串的基因_Python_Python 3.x - Fatal编程技术网

Python 生物信息学:找到给定基因组串的基因

Python 生物信息学:找到给定基因组串的基因,python,python-3.x,Python,Python 3.x,生物学家使用字母a、C、T和G的序列来模拟基因组。基因是基因组的一种替代物,它在三重态ATG之后开始,在三重态TAG、TAA或TGA之前结束。此外,基因串的长度是3的倍数,并且该基因不包含任何三胞胎ATG、TAG、TAA和TGA 理想情况下: Enter a genome string: TTATGTTTTAAGGATGGGGCGTTAGTT #Enter TTT GGGCGT ----------------- Enter a genome string: TGTGTGTATAT No

生物学家使用字母a、C、T和G的序列来模拟基因组。基因是基因组的一种替代物,它在三重态ATG之后开始,在三重态TAG、TAA或TGA之前结束。此外,基因串的长度是3的倍数,并且该基因不包含任何三胞胎ATG、TAG、TAA和TGA

理想情况下:

Enter a genome string: TTATGTTTTAAGGATGGGGCGTTAGTT #Enter   
TTT
GGGCGT
-----------------
Enter a genome string: TGTGTGTATAT
No Genes Were Found
到目前为止,我已经:

def findGene(gene):
    final = ""
    genep = gene.split("ATG")
    for part in genep:
        for chr in part:
            for i in range(0, len(chr)):
                if genePool(chr[i:i + 3]) == 1:
                    break
                else:
                    final += (chr[i+i + 3] + "\n")
    return final

def genePool(part):
    g1 = "ATG"
    g2 = "TAG"
    g3 = "TAA"
    g4 = "TGA"
    if (part.count(g1) != 0) or (part.count(g2) != 0) or (part.count(g3) != 0) or (part.count(g4) != 0):
        return 1

def main():
    geneinput = input("Enter a genome string: ")
    print(findGene(geneinput))

main()
# TTATGTTTTAAGGATGGGGCGTTAGTT
我总是出错

老实说,这对我来说真的不起作用——我想我已经在这些代码行中走到了死胡同——一种新的方法可能会有所帮助

提前谢谢

我所犯的错误-

Enter a genome string: TTATGTTTTAAGGATGGGGCGTTAGTT
Traceback (most recent call last):
  File "D:\Python\Chapter 8\Bioinformatics.py", line 40, in <module>
    main()
  File "D:\Python\Chapter 8\Bioinformatics.py", line 38, in main
    print(findGene(geneinput))
  File "D:\Python\Chapter 8\Bioinformatics.py", line 25, in findGene
    final += (chr[i+i + 3] + "\n")
IndexError: string index out of range
输入基因组字符串:ttatgttttaggatggggcgttagtt
回溯(最近一次呼叫最后一次):
文件“D:\Python\Chapter 8\Bioinformatics.py”,第40行,在
main()
文件“D:\Python\Chapter 8\Bioinformatics.py”,第38行,主目录
打印(findGene(基因输入))
文件“D:\Python\Chapter 8\Bioinformatics.py”,第25行,findGene
最终+=(chr[i+i+3]+“\n”)
索引器错误:字符串索引超出范围
就像我之前所说的,我不确定我是否在正确的轨道上用我当前的代码来解决这个问题-任何带有伪代码的新想法都是值得赞赏的

这可以通过以下方法完成:

输出

['TTT', 'GGGCGT'] []
错误是什么?您计划将其用于大型数据集还是用于短片段?@mhawke我似乎遇到了围绕
[I:I+3]
的错误——例如,当切片(
[I:I+3]
部分)的索引空间用完时,我似乎遇到了问题。这有用吗?@Moritz不,只是基本的,就是我写的。正如你所说的,简短的片段。也许问题是如何写的,但基因可以包含ATG——它既是“开始”的指示器,也是一种内部元素(蛋氨酸的代码)。我不熟悉
re
。非常简短的解释谢谢@mhawke@MattRumbel:基本上,re模式寻找ATG,然后是最短的碱基序列,直到看到一个前哨三联体标签、TAA或TGA。这将与Stidgeon评论的序列中确实包含ATG的基因相匹配。(我不知道ATG是否应该包括在内,我不是生物学家)谢谢你的解释,这很容易理解understand@Matt字母必须以3个为一组进行匹配,因此
(.*)
应该类似于
((?:[ACTG]{3})*?)
@RootTwo:谢谢你指出这一点,我忽略了这个要求。 ['TTT', 'GGGCGT'] []
"ATG((?:[ACTG]{3})+?)(?:TAG|TAA|TGA)"g
    ATG matches the characters ATG literally (case sensitive)
    1st Capturing group ((?:[ACTG]{3})+?)
        (?:[ACTG]{3})+? Non-capturing group
            Quantifier: +? Between one and unlimited times, as few times as possible, expanding as needed [lazy]
            [ACTG]{3} match a single character present in the list below
                Quantifier: {3} Exactly 3 times
                ACTG a single character in the list ACTG literally (case sensitive)
    (?:TAG|TAA|TGA) Non-capturing group
        1st Alternative: TAG
            TAG matches the characters TAG literally (case sensitive)
        2nd Alternative: TAA
            TAA matches the characters TAA literally (case sensitive)
        3rd Alternative: TGA
            TGA matches the characters TGA literally (case sensitive)
    g modifier: global. All matches (don't return on first match)