3
b:                 @   sJ   dddZ dddZdddZdddZdd
dZdddZdddZdS )      I@c             C   s   t | ||\}}|S )a8  
    Abstract: Returns the NG50 value of the passed list of numbers.
    Comments: Works for any percentage (e.g. NG60, NG70) with optional argument
    Usage: NG50(numlist, reference_length)

    Based on the definition from this SEQanswers post
    http://seqanswers.com/forums/showpost.php?p=7496&postcount=4
    (modified Broad Institute's definition
    https://www.broad.harvard.edu/crd/wiki/index.php/N50)

    See SEQanswers threads for details:
    http://seqanswers.com/forums/showthread.php?t=2857
    http://seqanswers.com/forums/showthread.php?t=2332
    )NG50_and_LG50)numlistreference_length
percentageng50lg50 r   8/home/psgendb/BIRCHDEV/pkg/quast-5.2.0/quast_libs/N50.pyNG50   s    r
   c             C   s   t | ||\}}|S )z
    Abstract: Returns the LG50 value of the passed list of numbers.
    Comments: Works for any percentage (e.g. LG60, LG70) with optional argument
    Usage: LG50(numlist, reference_length)
    )r   )r   r   r   r   r   r   r   r	   LG50   s    r   c             C   s   t | t| |S )z
    Abstract: Returns the N50 value of the passed list of numbers.
    Comments: Works for any percentage (e.g. N60, N70) with optional argument
    Usage: N50(numlist)
    )r
   sum)r   r   r   r   r	   N50%   s    r   c             C   s   t | t| |S )z
    Abstract: Returns the L50 value of the passed list of numbers.
    Comments: Works for any percentage (e.g. L60, L70) with optional argument
    Usage: L50(numlist)
    )r   r   )r   r   r   r   r	   L50.   s    r   Fc       	      C   sv   |dkst |dkst |r(| jdd |}|d|  d }d}x0| D ](}||8 }|d7 }||krF|}||fS qFW dS )Ng        g      Y@T)reverse       )NN)AssertionErrorsort)	r   r   r   Z	need_sortslimitr   lr   r   r   r	   r   7   s    
r   c             C   s   t | t| |S )N)r   r   )r   r   r   r   r	   N50_and_L50I   s    r   Nc             C   s   yrt | dkstdtdd | D s0td|r>t|}ntt| }|dksZtdttdd | D | S  tk
r   d	S X d	S )
z
    numlist - length of contigs
    metric explanation http://lh3.github.io/2020/04/08/a-new-metric-on-assembly-contiguity
    r   zEmpty list as inputc             S   s   g | ]}t |tttfqS r   )
isinstanceintfloatcomplex).0ir   r   r	   
<listcomp>T   s    zau_metric.<locals>.<listcomp>zNon-numerical inputg        zall contigs are 0c             S   s   g | ]}|d  qS )   r   )r   nr   r   r	   r   Z   s    N)lenr   allr   r   )r   r   Zdenumr   r   r	   	au_metricM   s    
r#   )r   )r   )r   )r   )r   F)r   )N)r
   r   r   r   r   r   r#   r   r   r   r	   <module>   s   



	
	

