使用登录号从ENA数据库的ftp服务器下载数据

2024-05-16 00:12:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想下载ENA数据库中给出的一些生物体的完整蛋白质序列(在ENA部分的基因组下),以及我所掌握的信息,即大约2500个登录号。在

我试着用分类法在ftp服务器上更深入地查找它们。但找不到任何相关的东西。一个接一个的下载不是一个理想的解决方案。在

因此,如果您知道R或python中的任何包可以帮我吗?在


Tags: 服务器信息数据库基因组ftp序列蛋白质解决方案
2条回答

我找到了解决我主观问题的方法:

curl -F accessions=@<input_file_path> http://www.ebi.ac.uk/ena/data/download?
display=<output_format> 
-o<output_file_name>

我觉得我的这个旧剧本可能有用。在

有一点需要注意的是,基因组是从NCBI而不是ENA下载的,但我认为这些数据库中的很多都是相互同步的。所以你还是可以找到你想要的。在

如果您只想从给定的登录号(~2500)下载这些基因组,那么这个可能不起作用(除非您可能在下载之前对返回的search_results进行过滤;Entrez.efetch)。在

#!/usr/bin/env python

from Bio import Entrez

search_term = raw_input("Organism name: ")

Entrez.email = "your_email@isp.com"   # required by NCBI
search_handle = Entrez.esearch(db="nucleotide", term=search_term, usehistory="y", property='complete genome')
search_results = Entrez.read(search_handle)
search_handle.close()

gi_list = search_results["IdList"]
count = int(search_results["Count"])
webenv = search_results["WebEnv"]
query_key = search_results["QueryKey"]

batch_size = 5    # download sequences in batches so NCBI doesn't time you out

with open("ALL_SEQ.fasta", "w") as out_handle:
    for start in range(0, count, batch_size):
        end = min(count, start+batch_size)
        print "Going to download record %i to %i" % (start+1, end)
        fetch_handle = Entrez.efetch(db="nucleotide", rettype="fasta", retmode="text",retstart=start, retmax=batch_size, webenv=webenv, query_key=query_key)
        data = fetch_handle.read()
        fetch_handle.close()
        out_handle.write(data)

print ("\nDownload completed")

相关问题 更多 >