U
    H$xe                     @   s   d Z ddlmZmZ ddlmZ ddlmZ G dd deZG dd	 d	eZ	G d
d deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )z!
Filtering criteria (predicates)
    )ABCabstractmethod   )expected_errors)ModificationInfoc                   @   s2   e Zd ZeeedddZeedddZ	dS )	Predicate)inforeturnc                 C   s   dS )zA
        Return True if the filtering criterion matches.
        N selfreadr   r
   r
   2lib/python3.8/site-packages/cutadapt/predicates.pytest   s    zPredicate.test)r	   c                 C   s   d dd | jD dd S )z
        Return a short name for this predicate based on the class name such as "too_long",
        "too_many_expected_errors".
        This is used as identifier in the JSON report.
         c                 s   s&   | ]}|  rd |  n|V  qdS )_N)isupperlower).0Zchr
   r
   r   	<genexpr>   s    z3Predicate.descriptive_identifier.<locals>.<genexpr>r   N)join__name__)clsr
   r
   r   descriptive_identifier   s
    
z Predicate.descriptive_identifierN)
r   
__module____qualname__r   r   boolr   classmethodstrr   r
   r
   r
   r   r   
   s   r   c                   @   s4   e Zd ZdZedddZdd Zeddd	Zd
S )TooShortz?Select reads that are shorter than the specified minimum lengthminimum_lengthc                 C   s
   || _ d S Nr    )r   r!   r
   r
   r   __init__    s    zTooShort.__init__c                 C   s   d| j  dS )NzTooShort(minimum_length=)r    r   r
   r
   r   __repr__#   s    zTooShort.__repr__r   c                 C   s   t || jk S r"   )lenr!   r   r
   r
   r   r   &   s    zTooShort.testN	r   r   r   __doc__intr#   r&   r   r   r
   r
   r
   r   r      s   r   c                   @   s4   e Zd ZdZedddZdd Zeddd	Zd
S )TooLongz>Select reads that are longer than the specified maximum lengthmaximum_lengthc                 C   s
   || _ d S r"   r-   )r   r.   r
   r
   r   r#   -   s    zTooLong.__init__c                 C   s   d| j  dS )NzTooLong(maximum_length=r$   r-   r%   r
   r
   r   r&   0   s    zTooLong.__repr__r'   c                 C   s   t || jkS r"   )r(   r.   r   r
   r
   r   r   3   s    zTooLong.testNr)   r
   r
   r
   r   r,   *   s   r,   c                   @   s4   e Zd ZdZedddZdd Zeddd	Zd
S )TooManyExpectedErrorsz
    Select reads whose expected number of errors, according to the quality
    values, exceeds a threshold.

    The idea comes from usearch's -fastq_maxee parameter
    (http://drive5.com/usearch/).
    
max_errorsc                 C   s
   || _ d S r"   r0   )r   r1   r
   r
   r   r#   @   s    zTooManyExpectedErrors.__init__c                 C   s   d| j  dS )Nz!TooManyExpectedErrors(max_errors=r$   r0   r%   r
   r
   r   r&   C   s    zTooManyExpectedErrors.__repr__r'   c                 C   s   t |j| jkS r"   )r   	qualitiesr1   r   r
   r
   r   r   F   s    zTooManyExpectedErrors.testN	r   r   r   r*   floatr#   r&   r   r   r
   r
   r
   r   r/   7   s   r/   c                   @   s4   e Zd ZdZedddZdd Zeddd	Zd
S )TooHighAverageErrorRatez
    Select reads that have an average error rate above the threshold.
    This works better than TooManyExpectedErrors for reads that are expected to
    have varying lengths, such as for long read sequencing technologies.
    max_error_ratec                 C   s0   d|  k rdk s&n t d| d|| _d S )Ng              ?z0max_error_rate must be between 0.0 and 1.0, got .)
ValueErrorr7   )r   r7   r
   r
   r   r#   Q   s
    
z TooHighAverageErrorRate.__init__c                 C   s   d| j  S )Nz'TooHighAverageErrorRate(max_error_rate=r6   r%   r
   r
   r   r&   X   s    z TooHighAverageErrorRate.__repr__r'   c                 C   s   t |jt| | jkS r"   )r   r2   r(   r7   r   r
   r
   r   r   [   s    zTooHighAverageErrorRate.testNr3   r
   r
   r
   r   r5   J   s   r5   c                   @   s4   e Zd ZdZedddZdd Zeddd	Zd
S )TooManyNz
    Select reads that have too many 'N' bases.

    Both a raw count or a proportion (relative to the sequence length) can be used.
    )countc                 C   s    |dkst |dk | _|| _dS )z
        count -- if it is below 1.0, it will be considered a proportion, and above and equal to
        1 will be considered as discarding reads with a number of N's greater than this cutoff.
        r   r8   N)AssertionErroris_proportioncutoff)r   r<   r
   r
   r   r#   f   s    
zTooManyN.__init__c                 C   s   d| j  d| j dS )NzTooManyN(cutoff=z, is_proportion=r$   )r?   r>   r%   r
   r
   r   r&   o   s    zTooManyN.__repr__r'   c                 C   sF   |j  d}| jr8t|dkr&dS |t| | jkS || jkS d S )Nnr   F)Zsequencer   r<   r>   r(   r?   )r   r   r   Zn_countr
   r
   r   r   r   s    zTooManyN.testNr3   r
   r
   r
   r   r;   _   s   	r;   c                   @   s&   e Zd ZdZdd ZedddZdS )CasavaFiltereda  
    Select reads that have failed the CASAVA filter according to the read header.
    The headers look like ``xxxx x:Y:x:x`` (with a ``Y``). Reads that pass the filter
    have an ``N`` instead of ``Y``.

    Reads with unrecognized headers are not selected.
    c                 C   s   dS )NzCasavaFiltered()r
   r%   r
   r
   r   r&      s    zCasavaFiltered.__repr__r'   c                 C   s"   |j d\}}}|dd dkS )N r      z:Y:)name	partition)r   r   r   r   rightr
   r
   r   r      s    zCasavaFiltered.testNr   r   r   r*   r&   r   r   r
   r
   r
   r   rA   |   s   rA   c                   @   s&   e Zd ZdZdd ZedddZdS )DiscardUntrimmedz;
    Select reads for which no adapter match was found
    c                 C   s   dS )NzDiscardUntrimmed()r
   r%   r
   r
   r   r&      s    zDiscardUntrimmed.__repr__r'   c                 C   s   |j  S r"   )matchesr   r
   r
   r   r      s    zDiscardUntrimmed.testNrG   r
   r
   r
   r   rH      s   rH   c                   @   s&   e Zd ZdZdd ZedddZdS )DiscardTrimmedzE
    Select reads for which at least one adapter match was found
    c                 C   s   dS )NzDiscardTrimmed()r
   r%   r
   r
   r   r&      s    zDiscardTrimmed.__repr__r'   c                 C   s
   t |jS r"   )r   rI   r   r
   r
   r   r      s    zDiscardTrimmed.testNrG   r
   r
   r
   r   rJ      s   rJ   N)r*   abcr   r   Zqualtrimr   Z	modifiersr   r   r   r,   r/   r5   r;   rA   rH   rJ   r
   r
   r
   r   <module>   s   