Skip to content

Commit

Permalink
Contig stitcher: simplify sliding_window implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jan 17, 2024
1 parent 722e04b commit ca3e291
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions micall/core/contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from math import ceil, floor
from mappy import Aligner
from functools import cached_property, reduce
from itertools import accumulate, takewhile
from itertools import accumulate, takewhile, tee, islice, chain
from gotoh import align_it
from queue import LifoQueue
import logging
from Bio.Seq import Seq

from micall.utils.cigar_tools import Cigar, connect_cigar_hits, CigarHit
from micall.utils.consensus_aligner import CigarActions
Expand Down Expand Up @@ -167,16 +168,10 @@ def sliding_window(sequence: Iterable[T]) -> Iterable[Tuple[Optional[T], T, Opti
the current item, and the next item (None if the last item) in the sequence.
"""

if not sequence:
return

yield (None, sequence[0], sequence[1] if len(sequence) > 1 else None)

for i in range(1, len(sequence) - 1):
yield (sequence[i - 1], sequence[i], sequence[i + 1])

if len(sequence) > 1:
yield (sequence[-2], sequence[-1], None)
a, b, c = tee(sequence, 3)
prevs = chain([None], a)
nexts = chain(islice(c, 1, None), [None])
return zip(prevs, b, nexts)


def combine_contigs(parts: List[AlignedContig]) -> AlignedContig:
Expand Down

0 comments on commit ca3e291

Please sign in to comment.