I am new to Biopython and I have a performance issue when parsing genbank files.
I have to parse a lot of gb files, from which I have the accession numbers. After parsing, I only want to examine the taxonomy and the organelle of the file. Right now, I have this code:
from Bio import SeqIO
from Bio import Entrez
gb_acc1 = Entrez.efetch(db='nucleotide', id=access1, rettype='gb', retmode='text') #Where access1 contents the accession number
rec = SeqIO.read(gb_acc1, 'genbank')
cache[access1] = rec #where cache is just a dictionary where saving the gb files already downloaded
feat = cache[access1].features[0]
if 'organelle' in feat.qualifiers.keys(): #And the code goes on
In order to look for the taxonomy I have:
gi_h = Entrez.efetch(db='nucleotide', id=access, rettype='gb', retmode='text')
gi_rec = SeqIO.read(gi_h, 'genbank')
cache[access]=gi_rec
if cache[access].annotations['taxonomy'][1] == 'Fungi':
fungi += 1 #And the code goes on
This (the whole script) works fine. My problem is that I am downloading the whole gb file (which sometimes is huge) just to look into these 2 features: the organelle and the taxonomy. If I could only download this part of the gb file my script would be much faster, but I have not figured out if this is possible.
Does someone know if this can be done, and if so, how? Thanks a lot in advance