<p>I had the same problem. I'm pretty sure you can calculate it yourself using the following:</p>
<ol>
<li><p>The length of your sequence (seq_len)</p>
</li>
<li><p>The value from the <code>&lt;Hsp_query-from&gt;</code> tag from the hit (<code>&lt;Hsp_query-from&gt;</code>)</p>
</li>
<li><p>The value from the <code>&lt;Hsp_query-to&gt;</code> tag from the hit (<code>&lt;Hsp_query-to&gt;</code>)</p>
</li>
</ol>
<p>It can be calculated by:</p>
<pre><code>query_cover = (&lt;Hsp_query-to&gt; - &lt;Hsp_query-from&gt; + 1) / seq_len * 100
</code></pre>
<p>Please note that I did not get this from any documentation. I figured it out by staring at the xml output returned from the Biopython <code>NCBIWWW.qblast()</code> function. This solution seems to match with the results I get by blasting the same sequence on the interactive web portal.</p>

CC BY-SA 4.0
2021-07-09T18:57:40.437Z
2021-07-10T18:02:26.130Z
2021-07-10T18:02:26.130Z
Dennis
<pre class="lang-py prettyprint-override"><code>record = NCBIXML.read(result_handle_xml)
query_len = record.query_length
for alignment in record.alignments:
    _ = alignment.hsps.__next__()
    query_cover = (_.query_end - _.query_start + 1) / query_len * 100
</code></pre>

CC BY-SA 4.0
2022-04-07T08:57:40.390Z
2022-04-07T08:57:40.390Z
Vovin
<p>I need to extract (or to calculate precisely) the query coverage from Blast output. I am using NCBIWWW.qblast to query Blast in XML format.</p>

<p>Is it possible to know the query coverage parsing the XML output? If yes, how?</p>

<pre><code>result_handle_xml = NCBIWWW.qblast("blastp","pdb",my_query.seq,format_type='XML')
</code></pre>

<p><a href="https://www.ncbi.nlm.nih.gov/books/NBK279684/" rel="nofollow noreferrer">here</a> it suggest to use '-6 qcovs', but only for BLAST command line version and only for tabular format</p>

<p>This is the fasta file that I open:</p>

<pre><code>&gt;sp|P02489|CRYAA_HUMAN Alpha-crystallin A chain OS=Homo sapiens 
GN=CRYAA PE=1 SV=2
MDVTIQHPWFKRTLGPFYPSRLFDQFFGEGLFEYDLLPFLSSTISPYYRQSLFRTVLDSG
ISEVRSDRDKFVIFLDVKHFSPEDLTVKVQDDFVEIHGKHNERQDDHGYISREFHRRYRL
PSNVDQSALSCSLSADGMLTFCGPKIQTGLDATHAERAIPVSREEKPTSAPSS
</code></pre>

CC BY-SA 3.0
2017-12-28T10:30:22.387Z
Please [edit] your question and include an example of the file you are trying to parse. We can't really help you parse data you don't show.
terdon
CC BY-SA 3.0
2017-12-28T16:55:57.070Z
I see you edited, but you still haven't shown us the file you are trying to parse. Is the information even there? Please add an example so we know what you're working with.
terdon
CC BY-SA 3.0
2017-12-28T21:19:42.693Z
According to [this](https://www.biostars.org/p/180510), the answer is 'no'.
heathobrien
CC BY-SA 4.0
2023-09-02T13:30:49.460Z
@AndreaSpinelli please consider the answers provided and whether these answered your question. If so please remember to "accept" an answer, it helps with site stats
M__
<python><blast><parsing>
Biopython - extracting query coverage from XML Blast output
# Biopython - extracting query coverage from XML Blast output

(Asked by: username_0 on 2017-12-28)

I need to extract (or to calculate precisely) the query coverage from Blast output. I am using NCBIWWW.qblast to query Blast in XML format.
Is it possible to know the query coverage parsing the XML output? If yes, how?
result_handle_xml = NCBIWWW.qblast("blastp","pdb",my_query.seq,format_type='XML')

here it suggest to use '-6 qcovs', but only for BLAST command line version and only for tabular format
This is the fasta file that I open:
>sp|P02489|CRYAA_HUMAN Alpha-crystallin A chain OS=Homo sapiens 
GN=CRYAA PE=1 SV=2
MDVTIQHPWFKRTLGPFYPSRLFDQFFGEGLFEYDLLPFLSSTISPYYRQSLFRTVLDSG
ISEVRSDRDKFVIFLDVKHFSPEDLTVKVQDDFVEIHGKHNERQDDHGYISREFHRRYRL
PSNVDQSALSCSLSADGMLTFCGPKIQTGLDATHAERAIPVSREEKPTSAPSS

**Tags:** python, blast, parsing
> **Comments:**
> **username_1**: Please [edit] your question and include an example of the file you are trying to parse. We can't really help you parse data you don't show.  
> **username_1**: I see you edited, but you still haven't shown us the file you are trying to parse. Is the information even there? Please add an example so we know what you're working with.  
> **username_2**: According to [this](https://www.biostars.org/p/180510), the answer is 'no'.  
> **username_3**: @AndreaSpinelli please consider the answers provided and whether these answered your question. If so please remember to "accept" an answer, it helps with site stats  

---

## 2 answers

### Answer by username_4 on 2021-07-09. Score: 2

I had the same problem. I'm pretty sure you can calculate it yourself using the following:

The length of your sequence (seq_len)

The value from the  tag from the hit ()

The value from the  tag from the hit ()


It can be calculated by:
query_cover = ( -  + 1) / seq_len * 100

Please note that I did not get this from any documentation. I figured it out by staring at the xml output returned from the Biopython NCBIWWW.qblast() function. This solution seems to match with the results I get by blasting the same sequence on the interactive web portal.


---

### Answer by username_5 on 2022-04-07. Score: 1

record = NCBIXML.read(result_handle_xml)
query_len = record.query_length
for alignment in record.alignments:
    _ = alignment.hsps.__next__()
    query_cover = (_.query_end - _.query_start + 1) / query_len * 100


---

