gpt4 book ai didi

python - 在 BioPython 中使用 Entrez 从 GenBank 检索和解析蛋白质序列

转载 作者:太空宇宙 更新时间:2023-11-04 06:07:58 25 4
gpt4 key购买 nike

很快就会很明显,我是 Python 和一般编码的新手。我有一个存储为文本文件的基因 ID 列表,我想使用 Entrez 函数搜索 GenBank 数据库并检索与 ID 对应的蛋白质序列。理想情况下,我希望最终产品是一个 FASTA 文件,因为此时我真的只对序列感兴趣。使用 Biopython 教程 ( http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec15 ),我想到了这个:

from Bio import Entrez
from Bio import SeqIO
Entrez.email = "me@mysite.com"
id_list = set(open('test.txt', 'rU'))
handle = Entrez.efetch(db="protein", id=id_list, rettype="fasta", retmode="text")
for seq_record in SeqIO.parse(handle, "fasta"):
print ">" + seq_record.id, seq_record.description
print seq_record.seq
handle.close()

但是当我运行它时,我得到了错误:

File "C:/Python27/Scripts/entrez_files.py", line 5, in <module>
handle = Entrez.efetch(db="protein", id=id_list, rettype="fasta", retmode="text")
File "C:\Python27\lib\site-packages\Bio\Entrez\__init__.py", line 145, in efetch
if ids.count(",") >= 200:
AttributeError: 'set' object has no attribute 'count'

我每次使用 rettype = 'fasta' 时都会遇到类似的错误。当我使用 rettype = 'gb' 时,我没有收到此错误,但我真的想以一个 fasta 文件结束。有人有什么建议吗?谢谢你!

编辑:抱歉,我忽略了包含输入文件的内容。在一个完美的世界中,代码将接受这样的输入格式:

gi|285016822|ref|YP_003374533.1|
gi|285018887|ref|YP_003376598.1|
gi|285016823|ref|YP_003374534.1|
gi|285016824|ref|YP_003374535.1|
....

但我也尝试过使用仅包含基因 ID (GI) 的简化版本,如下所示:

285016822 
285018887
285016823
285016824...

最佳答案

正如您在 efetch's source code 中看到的那样, id 参数必须有一个 count 方法。通常这将是具有单个 ID 的字符串或具有所有 ID 的 Python 列表。您正在使用 set,大概是为了消除重复的值,因此您可以转换为这样的列表:

id_list = set(open('test.txt', 'rU'))
id_list = list(id_list)

关于python - 在 BioPython 中使用 Entrez 从 GenBank 检索和解析蛋白质序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com