From 2a9b6faf0685cd0a2fa6488db291b4c0d30b3978 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Thu, 7 May 2020 20:43:36 +1000 Subject: [PATCH] add get_blocks to Alignment --- nesoni/sam.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nesoni/sam.py b/nesoni/sam.py index d3c30ee..012fdde 100644 --- a/nesoni/sam.py +++ b/nesoni/sam.py @@ -174,6 +174,22 @@ def next_reference_name(self): return self.mrnm @property def next_reference_start(self): return self.mpos + def get_blocks(self): + pos = self.reference_start + + blocks = [ ] + n = 0 + for char in self.cigar: + if '0' <= char <= '9': + n = n*10+(ord(char)-48) + else: + if char == 'M': + blocks.append((pos,pos+n)) + if char in ('M','D','N','P','=','X'): #'MDNP=X': + pos += n + n = 0 + + return blocks