This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can Biopython Parse Gzipped Xml From Blast?

I have been using blast+ with the xml output format (-m7 in the older days, and outfmt 5 with ncbi-blast+). Since the XML files are huge, I have been gzipping them. I have also been using Biopython to parse the XML files. Is there a way to handle the gzipped file directly in (Bio)python?

Presently, I

gunzip output.xml.gz
and use something like:

from Bio.Blast import NCBIXML  
blast_file = open ('output.xml')
blast_records = NCBIXML.parse(blast_file)

Thanks!

blast xml biopython parsing

1 answer

Using the gzip module:

import gzip
from Bio.Blast import NCBIXML

blast_file = gzip.open('output.xml.gz', 'rb')
blast_records = NCBIXML.parse(blast_file)

Excellent, thanks a lot. Solved a major problem!

Log in to answer this question.