如何处理 IncompleteRead: 在 biopython 中

How to handle IncompleteRead: in biopython

我正在尝试使用 Biopython 从 NCBI 获取登录号的 fasta 序列。通常序列已成功下载。但偶尔我会收到以下错误:

http.client.IncompleteRead: IncompleteRead(61808640 bytes read)

我已经搜索了答案How to handle IncompleteRead: in python

我试过最佳答案 。这是工作。但是,问题是,它会下载部分序列。有没有别的办法。谁能指出我正确的方向?

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 应该处理但没有处理的错误)。