
:>"^‹  ã               @   s.   d  Z  d d l Z d d „  Z d d „  Z d S)zLocal Composition Complexity.é    Nc             C   sƒ  t  j d ƒ } t |  ƒ } y |  j ƒ  } Wn$ t k
 rQ t |  ƒ j ƒ  } Yn Xd g } d g } xN t | ƒ D]@ } | j | d t | ƒ t  j | d t | ƒ ƒ | ƒ qq W|  d | … } | j	 d ƒ }	 | j	 d ƒ }
 | j	 d ƒ } | j	 d ƒ } | |	 } | |
 } | | } | | } | j | | | | ƒ |  d } x/t | | ƒ D]} | | d | | d … } | | d k r¤| j | d	 ƒ nÍ| d k r˜|	 d 8}	 | j
 d ƒ r|
 d 7}
 | |	 } | |
 } | j | | | | ƒ qq| j
 d ƒ rN| d 7} | |	 } | | } | j | | | | ƒ qq| j
 d ƒ rq| d 7} | |	 } | | } | j | | | | ƒ nÙ| d k rŒ|
 d 8}
 | j
 d ƒ rø|	 d 7}	 | |	 } | |
 } | j | | | | ƒ qq| j
 d ƒ rB| d 7} | |
 } | | } | j | | | | ƒ qq| j
 d ƒ rq| d 7} | |
 } | | } | j | | | | ƒ nå| d k r€| d 8} | j
 d ƒ rì|	 d 7}	 | |	 } | | } | j | | | | ƒ qq| j
 d ƒ r6|
 d 7}
 | |
 } | | } | j | | | | ƒ qq| j
 d ƒ rq| d 7} | | } | | } | j | | | | ƒ nñ | d k rq| d 8} | j
 d ƒ rà|	 d 7}	 | |	 } | | } | j | | | | ƒ n‘ | j
 d ƒ r*|
 d 7}
 | |
 } | | } | j | | | | ƒ nG | j
 d ƒ rq| d 7} | | } | | } | j | | | | ƒ | 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éÿÿÿÿr   )ÚmathÚlogÚlenÚupperÚAttributeErrorÚstrÚ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   ú5/tmp/pip-build-ww9dw3qa/biopython/Bio/SeqUtils/lcc.pyÚlcc_mult   sÀ    		8












































r    c             C   s«  t  |  ƒ } y |  j ƒ  } Wn$ t k
 rB t |  ƒ j ƒ  } Yn Xt j d ƒ } d |  k rg d } n= | j d ƒ t | ƒ t j | j d ƒ t | ƒ ƒ | } d |  k r¹ d } n= | j d ƒ t | ƒ t j | j d ƒ t | ƒ ƒ | } d |  k rd } n= | j d ƒ t | ƒ t j | j d ƒ t | ƒ ƒ | } d |  k r]d } n= | j d ƒ t | ƒ t j | j 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   r   Úlcc_simp   s.    	'	'	'	'r!   )Ú__doc__r	   r    r!   r   r   r   r   Ú<module>   s   r