o
    Uݢg                     @  sd   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 er&ddl
mZ dddZdddZdS )zmCode refactored out of align.py to avoid pulling in LibSSW.

Contains utilites that operate on CIGAR strings
    )annotationsN)Iterator)TYPE_CHECKING)ensure_binary)
PyAlignRescigar_stringbytesreturnIterator[tuple[int, bytes]]c                 C  sD   t | } td| dd }td| dd }tdd |D |S )zGet a list of length, CIGAR operation tuples for alignment.

    Args:
        cigar_string (bytes): CIGAR string

    Returns:
        tuple of (int, bytes): tuple of (length CIGAR operation, CIGAR operation).
    s	   [A-Za-z]+Ns   [0-9]+   c                 s  s    | ]}t |V  qd S )N)int).0number r   _/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/lib/python/cellranger/cigar.py	<genexpr>    s    z#get_cigar_tuples.<locals>.<genexpr>)r   resplitzip)r   Zcigar_numbersZcigar_lettersr   r   r   get_cigar_tuples   s   	r   	alignmentr   r   c                 C  s2   | j dusJ t| j }dd |D }t|ddS )zJGet the longest M (match or mismatch) operation in a list of cigar tuples.Nc                 s  s     | ]\}}|d kr|V  qdS )   MNr   )r   Zop_lenopr   r   r   r   '   s    z&get_max_word_length.<locals>.<genexpr>r   )default)r   r   max)r   cigar_tuplesZword_lengthsr   r   r   get_max_word_length#   s   
r   )r   r   r	   r
   )r   r   r	   r   )__doc__
__future__r   r   collections.abcr   typingr   sixr   Zstriped_smith_waterman.ssw_wrapr   r   r   r   r   r   r   <module>   s   
