Skip to content

Commit

Permalink
mappy check index flags before mapping
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexomics authored and lh3 committed Apr 20, 2023
1 parent c41518a commit c3d461e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/mappy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c3d461e

Please sign in to comment.