我正在尝试使用 Biopython 从 NCBI 获取登录号的 fasta 序列。通常序列已成功下载。但偶尔我会收到以下错误:
http.client.IncompleteRead: IncompleteRead(61808640 bytes read)
我已经搜索过答案How to handle IncompleteRead: in python
我已经尝试过最佳答案 https://stackoverflow.com/a/14442358/4037275 。这是工作。然而,问题是,它下载了部分序列。还有什么办法吗。谁能指出我正确的方向吗?
from Bio import Entrez
from Bio import SeqIO
Entrez.email = "my email id"
def extract_fasta_sequence(NC_accession):
"This takes the NC_accession number and fetches their fasta sequence"
print("Extracting the fasta sequence for the NC_accession:", NC_accession)
handle = Entrez.efetch(db="nucleotide", id=NC_accession, rettype="fasta", retmode="text")
record = handle.read()
最佳答案
您需要添加 try/except 来捕获此类常见的网络错误。请注意,异常 httplib.IncompleteRead 是更通用的 HTTPException 的子类,请参阅:https://docs.python.org/3/library/http.client.html#http.client.IncompleteRead
例如http://lists.open-bio.org/pipermail/biopython/2011-October/013735.html
另请参阅https://github.com/biopython/biopython/pull/590会捕获使用 NCBI Entrez API 可能出现的一些其他错误(NCBI 应该处理但没有处理的错误)。
关于python - 如何处理IncompleteRead : in biopython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38516984/