From 3afd902dd2d139a7ef1a19556787e8383a2cd9ba Mon Sep 17 00:00:00 2001
From: Stefan Bienert <stefan.bienert@unibas.ch>
Date: Tue, 17 Jun 2014 18:03:35 +0200
Subject: [PATCH] Handling non-matching hits in BLAST

---
 modules/bindings/pymod/blast.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/modules/bindings/pymod/blast.py b/modules/bindings/pymod/blast.py
index e2a6f373e..08359de4d 100644
--- a/modules/bindings/pymod/blast.py
+++ b/modules/bindings/pymod/blast.py
@@ -83,7 +83,13 @@ def ParseBlastOutput(string, seqid_thres=0, evalue_thres=float("infinity")):
     bit_score=float(_GetValue(hsp, 'Hsp_bit-score'))
     score=float(_GetValue(hsp, 'Hsp_score'))
     evalue=float(_GetValue(hsp, 'Hsp_evalue'))
-    identity=float(_GetValue(hsp, 'Hsp_identity'))
+    try:
+      identity=float(_GetValue(hsp, 'Hsp_identity'))
+    except AssertionError:
+      # The Hsp_identity tag is not a 'must' in the BLAST XML format. It
+      # describes the number of matching characters. Hence we assume, if it is
+      # missing, there are 0 matches.
+      identity=0
     hsp_align_len=float(_GetValue(hsp, 'Hsp_align-len'))
     seqid=identity/hsp_align_len
     query_offset=_GetInt(hsp, 'Hsp_query-from')-1
-- 
GitLab