This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to parse NCBI Blast XML to retrieve "hsp_query-from in Biopython?

Hey,

I have a question concerning parsng NCBI BLAST XML outputs. I can parse the hsp score of the BLAST results. Unfortunately, I face difficulties parsing other entries in the XML.

I need to parse hsp_query-from, hsp_query-to, hsp_align-len, and hsp_identity.

This code works:

    for record in NCBIXML.parse(result_handle):
    for alignment in record.alignments:
        for hsp in alignment.hsps:
            hsp_score = hsp.score

How can I get the other entries? Especially hsp_query-from seems to be tricky because "from" is reserved by python.

I appreciate your help a lot!

Best, Philipp

biopython parse xml

1 answer

  • hsp_query-from: hsp.query_start
  • hsp_query-to: hsp.query_end
  • hsp_align-len: hsp.align_length
  • hsp_identity: hsp.identities

You can lookup the keywords in the source code of the NCBIXML parser at http://biopython.org/DIST/docs/api/Bio.Blast.NCBIXML-pysrc.html to find the respective parameters.

Log in to answer this question.