gpt4 book ai didi

python - 如何从 python 中的多个登录号返回来自 ncbi 的相应 fasta 蛋白质序列?

转载 作者:行者123 更新时间:2023-12-01 03:56:52 24 4
gpt4 key购买 nike

我在使用 python 脚本下载文本文件中多个登录号的 fasta 序列时遇到一些困难。我可以对单个入藏号执行此操作,例如:

import sys
from Bio import Entrez
Entrez.email = "X@Y.com"
handle = Entrez.efetch(db="protein", id="EAS03220", rettype="fasta")
print(handle.read())

但是当我尝试将文件作为列表提供给它(见下文)时,我会收到错误。

import sys
from Bio import Entrez
Entrez.email = "X@Y.com"

accessions = []
for line in open(sys.argv[1],"r"):
line = line.strip()
accessions.append(line)

for num in accessions:
handle = Entrez.efetch(db="protein", id="num", rettype="fasta")
print(handle.read())

这是我的输入文件的外观示例:

EAS06781
EAS07087
EAS07113
EAS07200
EAS07226
EAS07230

我确信解决方案很简单,但我已经阅读论坛、NCBI 帮助页面和 Python 初学者书籍几个小时了,但一无所获!提前致谢。

最佳答案

您将number作为string传递,而不是作为变量传递。尝试删除引号,它应该可以工作。

handle = Entrez.efetch(db="protein", id=num, rettype="fasta")

关于python - 如何从 python 中的多个登录号返回来自 ncbi 的相应 fasta 蛋白质序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37302177/

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