使用python获取基于关键字的蛋白质FASTA序列

时间:2017-07-25 08:42:27

标签: python biopython ncbi genbank

我想从Entrez收集蛋白质FASTA序列和python 2.7。我正在寻找任何具有以下关键词的蛋白质:"终止酶"和"大"以他们的名义。到目前为止,我得到了这段代码:

from Bio import Entrez
Entrez.email = "example@example.org"


searchResultHandle = Entrez.esearch(db="protein", term="terminase large", retmax=1000)
searchResult = Entrez.read(searchResultHandle)
ids = searchResult["IdList"]

handle = Entrez.efetch(db="protein", id=ids, rettype="fasta", retmode="text")
record = handle.read()

out_handle = open('myfasta.fasta', 'w')
out_handle.write(record.rstrip('\n'))

然而,它可以从各种生物体中获得几种终止酶,而我只需要终止形式的噬菌体(特别是病毒[taxid 10239],宿主细菌。我设法从NCBI获得病毒的nuccore登录ID我我感兴趣,但我不知道如何将这两种信息结合起来。 id文件如下所示:

NC_001341
NC_001447
NC_028834
NC_023556
...

我是否需要访问每个ID的每个gb文件并在其中搜索我想要的蛋白质?

1 个答案:

答案 0 :(得分:1)

找到我要找的东西。在:

searchResultHandle = Entrez.esearch(db="protein", term="terminase large", retmax=1000)

我已添加:

searchterm = "(terminase large subunit AND viruses[Organism]) AND Caudovirales AND refseq[Filter]"
searchResultHandle = Entrez.esearch(db="protein", term=searchterm, retmax=6000)

将我的搜索记录到所需的病毒中。虽然它没有被主机过滤,但是被分类组过滤了,但这对我的工作来说已经足够了。

感谢@Llopis提供更多帮助