From c3d461e22a381548e7bb2090b3f650de904bb137 Mon Sep 17 00:00:00 2001 From: Alex Payne Date: Thu, 12 Jan 2023 13:22:46 +0000 Subject: [PATCH] mappy check index flags before mapping mappy creates a CIGAR string by default (`-c` flag) and so is incompatible with indexes that are created using the `--idx-no-seq` flag. The previous implementation of mappy did not check for the `MM_I_NO_SEQ` flag and would seg fault when attempting to map a read or retrieve a reference sequence from the index. This patch adds a check to both `mappy.Aligner.seq` and `mappy.Aligner.map` and returns `None` if there is no index sequences. I've chose `None` as this is inline with the behaviour of mappy for reads that do not align/retreiving sequences that aren't in the index, however it might be better to raise an exception so that this error is distinct and can be communicated to the caller. --- python/mappy.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/mappy.pyx b/python/mappy.pyx index cf47632..61e80ed 100644 --- a/python/mappy.pyx +++ b/python/mappy.pyx @@ -172,6 +172,7 @@ cdef class Aligner: cdef cmappy.mm_mapopt_t map_opt if self._idx == NULL: return + if ((self.map_opt.flag & 4) and (self._idx.flag & 2)): return map_opt = self.map_opt if max_frag_len is not None: map_opt.max_frag_len = max_frag_len if extra_flags is not None: map_opt.flag |= extra_flags @@ -217,6 +218,7 @@ cdef class Aligner: cdef int l cdef char *s if self._idx == NULL: return + if ((self.map_opt.flag & 4) and (self._idx.flag & 2)): return s = cmappy.mappy_fetch_seq(self._idx, name.encode(), start, end, &l) if l == 0: return None r = s[:l] if isinstance(s, str) else s[:l].decode()