From 07f39030a24dca2d50448541e572598e59f79e7c Mon Sep 17 00:00:00 2001
From: rlyu <rlyu@svi.edu.au>
Date: Mon, 1 Aug 2022 15:10:04 +1000
Subject: [PATCH] improve countAllele

---
 src/sgcocaller/utils.nim | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/sgcocaller/utils.nim b/src/sgcocaller/utils.nim
index 9935127..86d13bf 100755
--- a/src/sgcocaller/utils.nim
+++ b/src/sgcocaller/utils.nim
@@ -67,8 +67,9 @@ proc get_base_offset*(position:int, align: Record): int =
     if off <= position:
       continue
     over = off - position
-    # get the base 
-    base_offset = qoff - over-1
+    base_offset = qoff - over - 1
+    if($event.op == 'N') or ($event.op == 'D') or ($event.op == 'H'): 
+      base_offset = -1
     break 
   return base_offset    
 
@@ -147,6 +148,8 @@ proc countAllele*(ibam:Bam, maxTotalReads:int,
     if not barcodeTable.hasKey(currentCB): continue
     base_off = get_base_offset(position = stopPos, align = aln) 
     base = aln.base_at(base_off)
+    if base_off < 0:
+      continue
     if aln.base_quality_at(base_off).cint < minbsq: 
       continue
     total_reads+=1
-- 
GitLab