Skip to content

Commit

Permalink
perf(call): decode cigar optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Feb 2, 2024
1 parent deaae64 commit efd5385
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions strkit/call/cigar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import itertools

from typing import Generator, Iterable, Union
from typing import Iterable, Union

__all__ = [
"CoordPair",
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_aligned_pairs_from_cigar(
query_start: int = 0,
ref_start: int = 0,
matches_only: bool = False,
) -> Generator[CoordPair, None, None]:
) -> Iterable[CoordPair]:
"""
Given an iterable of CIGAR operations (op, count), yield aligned pairs of (query, ref).
:param cigar: Iterable of CIGAR operations
Expand All @@ -88,6 +88,10 @@ def get_aligned_pairs_from_cigar(

return itertools.chain.from_iterable(map(lambda c: ops[c[0]](c[1], qi, di), cigar))

def decode_cigar(encoded_cigar: list[int]) -> Generator[tuple[int, int], None, None]:
for item in encoded_cigar:
yield item & 15, item >> 4

def _decode_cigar_item(item: int) -> tuple[int, int]:
return item & 15, item >> 4


def decode_cigar(encoded_cigar: list[int]) -> Iterable[tuple[int, int]]:
return map(_decode_cigar_item, encoded_cigar)

0 comments on commit efd5385

Please sign in to comment.