B
    ‰°b{  ã               @   s    d Z ddlZdd„ Zdd„ ZdS )zLocal Composition Complexity.é    Nc          	   C   sp  t  d¡}t| ƒ}t| ƒ ¡ }dg}dg}x@t|ƒD ]4}| |d t|ƒ t  |d t|ƒ ¡|  ¡ q4W | d|… }| d¡}	| d¡}
| d¡}| d¡}||	 }||
 }|| }|| }| || | |  ¡ | d }xˆt|| ƒD ]v}||d || d … }||d kr.| |d ¡ n2|dkrü|	d8 }	| 	d¡r~|
d7 }
||	 }||
 }| || | |  ¡ nz| 	d¡r¼|d7 }||	 }|| }| || | |  ¡ n<| 	d¡r`|d7 }||	 }|| }| || | |  ¡ nd|dkrÊ|
d8 }
| 	d¡rL|	d7 }	||	 }||
 }| || | |  ¡ nz| 	d¡rŠ|d7 }||
 }|| }| || | |  ¡ n<| 	d¡r`|d7 }||
 }|| }| || | |  ¡ n–|dkr–|d8 }| 	d¡r|	d7 }	||	 }|| }| || | |  ¡ nz| 	d¡rX|
d7 }
||
 }|| }| || | |  ¡ n<| 	d¡r`|d7 }|| }|| }| || | |  ¡ nÊ|dkr`|d8 }| 	d¡ræ|	d7 }	||	 }|| }| || | |  ¡ nz| 	d¡r$|
d7 }
||
 }|| }| || | |  ¡ n<| 	d¡r`|d7 }|| }|| }| || | |  ¡ |d }qðW |S )	aÚ  Calculate Local Composition Complexity (LCC) values over sliding window.

    Returns a list of floats, the LCC values for a sliding window over
    the sequence.

    seq - an unambiguous DNA sequence (a string or Seq object)
    wsize - window size, integer

    The result is the same as applying lcc_simp multiple times, but this
    version is optimized for speed. The optimization works by using the
    value of previous window as a base to compute the next one.
    é   r   é   ÚAÚCÚTÚGéÿÿÿÿ)
ÚmathÚlogÚlenÚstrÚupperÚrangeÚappendÚfloatÚcountÚendswith)ÚseqÚwsizeÚl2Ztamseqr   ZcomponeZlccsalÚiZwindowZcant_aZcant_cZcant_tZcant_gÚterm_aÚterm_cÚterm_tÚterm_gÚtailÚx© r   ú/lib/python3.7/site-packages/Bio/SeqUtils/lcc.pyÚlcc_mult   sº    
0







r   c             C   s   t | ƒ}t| ƒ ¡ }t d¡}d| kr,d}n.| d¡t|ƒ t | d¡t|ƒ ¡|  }d| krhd}n.| d¡t|ƒ t | d¡t|ƒ ¡|  }d| kr¤d}n.| d¡t|ƒ t | d¡t|ƒ ¡|  }d| kràd}n.| d¡t|ƒ t | d¡t|ƒ ¡|  }|| | |  S )ab  Calculate Local Composition Complexity (LCC) for a sequence.

    seq - an unambiguous DNA sequence (a string or Seq object)

    Returns the Local Composition Complexity (LCC) value for the entire
    sequence (as a float).

    Reference:
    Andrzej K Konopka (2005) Sequence Complexity and Composition
    https://doi.org/10.1038/npg.els.0005260
    r   r   r   r   r   r   )r   r   r   r	   r
   r   r   )r   r   r   r   r   r   r   r   r   r   r   Úlcc_simpz   s(    
r    )Ú__doc__r	   r   r    r   r   r   r   Ú<module>   s   m