[BioPython] problem accessing ncbi through GenBank.NCBIDictionary

Peter biopython at maubp.freeserve.co.uk
Tue Sep 4 09:05:21 EDT 2007


Miguel Ortiz-Lombardía wrote:
> Hello everyone.
> 
> I'm trying to retrieve from NCBI a series of GeneBank records from a list
> read from a file.

How many GenBenk identifiers are we talking about? Just trying to get an 
idea of the scale of the problem.  It certainly sounds like either 
network failures or timeouts.  Have you try something like this?

from Bio import GenBank
from urllib2 import HTTPError
ncbi_dict = GenBank.NCBIDictionary("protein", "genbank")
ids = ['14598510', '16904191']
output = open('saved.gb','w')
for gbid in ids:
     print "Fetching %s" % gbid
     try :
         gb_record = ncbi_dict[gbid]
     except HTTPError, e :
         #Check error code?
         print str(e)
         print "Re-trying %s" % gbid
         gb_record = ncbi_dict[gbid]
     output.write(gb_record)
output.close()
print "Done"

Peter



More information about the BioPython mailing list