2016-07-22 54 views
0

我想从NCBI使用Biopython模块获取fasta序列的登录号码。通常序列已成功下载。但是,一旦在一段时间我得到下面的错误如何处理IncompleteRead:在biopython

http.client.IncompleteRead:IncompleteRead

我寻觅的答案How to handle IncompleteRead: in python

(61808640个字节读)我已经尝试了上面的答案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() 

回答

0

您需要添加一个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应该处理的错误,但不要)。