o
    UݢgW                     @  s4   d Z ddlmZ ddlmZ dd
dZdddZdS )zUtils for math operations.    )annotations)IterablelengthsIterable[int]fractionfloatreturnintc                 C  sF   t | dd} t| }d}| D ]}||7 }||| kr|  S qtd)z.Calculates the N50 for a given set of lengths.T)reverser   zthis should be impossible)sortedsumArithmeticError)r   r   Z
tot_lengthZ
cum_lengthlength r   [/oak/stanford/groups/akundaje/marinovg/programs/cellranger-9.0.1/lib/python/tenkit/stats.pyNX   s   r   afloat | int | str | bytesbc                 C  s(   t | } t |}|dkrt dS | | S )z:Handles 0 division and conversion to floats automatically.r   NaN)r   )r   r   r   r   r   robust_divide   s
   r   N)r   r   r   r   r   r	   )r   r   r   r   r   r   )__doc__
__future__r   collections.abcr   r   r   r   r   r   r   <module>   s
   
