Skip to content

Commit

Permalink
feat: add support for bwa aln -N
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Jan 21, 2025
1 parent fb2b5ed commit 94bf79c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions pybwa/libbwaaln.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cdef extern from "bwtaln.h":
int BWA_MODE_GAPE
int BWA_MODE_COMPREAD
int BWA_MODE_LOGGAP
int BWA_MODE_NONSTOP

int __cigar_op(uint16_t __cigar)
int __cigar_len(uint16_t __cigar)
Expand Down
2 changes: 2 additions & 0 deletions pybwa/libbwaaln.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BwaAlnOptions:
stop_at_max_best_hits: int | None = None,
max_hits: int | None = 3,
log_scaled_gap_penalty: bool | None = None,
find_all_hits: bool | None = None,
threads: int | None = None,
) -> None: ...
max_mismatches: int # -n <int>
Expand All @@ -38,6 +39,7 @@ class BwaAlnOptions:
stop_at_max_best_hits: int # -R <int>
max_hits: int # bwa samse -n <int>
log_scaled_gap_penalty: bool = True # -L
find_all_hits: bool = False # -N
with_md: bool = True # bwa samse -d
threads: int # -t <int>

Expand Down
21 changes: 18 additions & 3 deletions pybwa/libbwaaln.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ cdef class BwaAlnOptions:
gap_extension_penalty (int | None): :code:`-E <int>`
stop_at_max_best_hits (int | None): :code:`-R <int>`
max_hits (int | None): :code:`bwa samse -n <int>`
log_scaled_gap_penalty (in | None): :code:`-L`
log_scaled_gap_penalty (bool | None): :code:`-L`
find_all_hits (bool | None): :code:`-N`
with_md (bool): output the MD to each alignment in the XA tag, otherwise use :code:`"."`
threads (int): the number of threads to use
"""
Expand All @@ -56,6 +57,7 @@ cdef class BwaAlnOptions:
stop_at_max_best_hits: int | None = None,
max_hits: int | None = 3,
log_scaled_gap_penalty: bool | None = None,
find_all_hits: bool | None = None,
with_md: bool | None = False,
threads: int | None = None
):
Expand Down Expand Up @@ -83,6 +85,8 @@ cdef class BwaAlnOptions:
self.max_hits = max_hits
if log_scaled_gap_penalty is not None:
self.log_scaled_gap_penalty = 1 if log_scaled_gap_penalty else 0
if find_all_hits is not None:
self.find_all_hits = find_all_hits
if with_md is not None:
self.with_md = with_md
if threads is not None:
Expand Down Expand Up @@ -186,14 +190,25 @@ cdef class BwaAlnOptions:

property log_scaled_gap_penalty:
""":code:`bwa aln -L`"""
def __get__(self) -> int:
def __get__(self) -> bool:
return self._delegate.mode & BWA_MODE_LOGGAP > 0
def __set__(self, value: int):
def __set__(self, value: bool):
if value:
self._delegate.mode |= BWA_MODE_LOGGAP
else:
self._delegate.mode &= ~BWA_MODE_LOGGAP

property find_all_hits:
""":code:`bwa aln -N`"""
def __get__(self) -> bool:
return self._delegate.mode & BWA_MODE_NONSTOP > 0
def __set__(self, value: bool):
if value:
self._delegate.mode |= BWA_MODE_NONSTOP
self.stop_at_max_best_hits = 0x7fffffff
else:
self._delegate.mode &= ~BWA_MODE_NONSTOP

property with_md:
""":code:`bwa samse -d
Expand Down

0 comments on commit 94bf79c

Please sign in to comment.