def efetch_hit(term, seq_start, seq_stop):
""" Fetch the relevant part of a hit
"""
db = "nucleotide"
maxtry = 3
ntry = -1
downloaded = False
while ~downloaded and (ntry <= maxtry):
ntry += 1
try:
handle = Entrez.esearch(db=db, term=term)
record = Entrez.read(handle)
assert len(record['IdList']) == 1, \
"Sorry, I'm not ready to handle more than one record"
handle = Entrez.efetch(db=db, rettype="gb", retmode="text",
id=record['IdList'][0],
seq_start=seq_start, seq_stop=seq_stop)
content = handle.read()
downloaded = True
except:
nap = ntry*3
print "Fail to download (term). I'll take a nap of %s seconds ", \
" and try again."
time.sleep(ntry*3)
return content
评论列表
文章目录