U
    H$xeë  ã                   @   s2   d dl mZmZ d dlmZmZ G dd„ dƒZdS )é    )ÚdefaultdictÚCounter)ÚDefaultDictÚTuplec                   @   s˜   e Zd ZdZddœdd„Zddœdd„Zddœdd	„Zedœd
d„Ze	eef dœdd„Z
e	eef dœdd„Zeeeef edœdd„ƒZdd„ ZdS )ÚReadLengthStatisticszB
    Keep track of the lengths of written reads or read pairs
    N)Úreturnc                 C   s   t tƒ| _t tƒ| _d S ©N)r   ÚintÚ_written_lengths1Ú_written_lengths2©Úself© r   ú2lib/python3.8/site-packages/cutadapt/statistics.pyÚ__init__
   s    
zReadLengthStatistics.__init__c                 C   s   | j t|ƒ  d7  < dS )z'Add a single-end read to the statisticsé   N)r
   Úlen)r   Úreadr   r   r   Úupdate   s    zReadLengthStatistics.updatec                 C   s0   | j t|ƒ  d7  < | jt|ƒ  d7  < dS )z'Add a paired-end read to the statisticsr   N)r
   r   r   )r   Úread1Zread2r   r   r   Úupdate2   s    zReadLengthStatistics.update2c                 C   s   t | j ¡ ƒS )z,Return number of written reads or read pairs)Úsumr
   Úvaluesr   r   r   r   Úwritten_reads   s    z"ReadLengthStatistics.written_readsc                 C   s   |   | j¡|   | j¡fS r   )Ú_compute_total_bpr
   r   r   r   r   r   Ú
written_bp   s    

þzReadLengthStatistics.written_bpc                 C   s   t | jƒt | jƒfS r   )r   r
   r   r   r   r   r   Úwritten_lengths#   s    z$ReadLengthStatistics.written_lengths)Úcountsr   c                 C   s   t dd„ |  ¡ D ƒƒS )Nc                 s   s   | ]\}}|| V  qd S r   r   )Ú.0ÚlengthÚcountr   r   r   Ú	<genexpr>(   s     z9ReadLengthStatistics._compute_total_bp.<locals>.<genexpr>)r   Úitems)r   r   r   r   r   &   s    z&ReadLengthStatistics._compute_total_bpc                 C   sX   |  ¡ \}}| ¡ D ]\}}| j|  |7  < q| ¡ D ]\}}| j|  |7  < q8| S r   )r   r"   r
   r   )r   ÚotherZwritten_lengths1Zwritten_lengths2r   r    r   r   r   Ú__iadd__*   s    zReadLengthStatistics.__iadd__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r   r   r   r   r   Ústaticmethodr   r   r$   r   r   r   r   r      s   r   N)Úcollectionsr   r   Útypingr   r   r   r   r   r   r   Ú<module>   s   