o
    Rŀg~                     @   s    d Z ddlZdd Zdd ZdS )zLocal Composition Complexity.    Nc                 C   sR  t d}|  } t| }dg}g }t|D ]}||d | t |d |  |  q| d| }|d}|d}	|d}
|d}|| }||	 }||
 }|| }||| | |   | d }t|| D ]}| |d || d  }||d kr||d  n|dkr|d8 }|dr|	d7 }	|| }||	 }||| | |   np|dr|
d7 }
|| }||
 }||| | |   nQ|dr|d7 }|| }|| }||| | |   n2|dkrW|	d8 }	|dr|d7 }|| }||	 }||| | |   n	|dr8|
d7 }
||	 }||
 }||| | |   n|drV|d7 }||	 }|| }||| | |   n|dkr|
d8 }
|dr|d7 }|| }||
 }||| | |   n|dr|	d7 }	||	 }||
 }||| | |   n|dr|d7 }||
 }|| }||| | |   ne|dkr"|d8 }|dr|d7 }|| }|| }||| | |   n=|dr|	d7 }	||	 }|| }||| | |   n|dr"|
d7 }
||
 }|| }||| | |   |d }qm|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upperlenrangeappendcountendswith)seqwsizel4tamseqcomponelccsaliwindowcant_acant_ccant_tcant_gterm_aterm_cterm_tterm_gtailx r#   D/var/www/html/myenv/lib/python3.10/site-packages/Bio/SeqUtils/lcc.pylcc_mult   s   
*










r%   c                 C   s   t | }|  } td}d| vrd}n| d| t| d|  | }d| vr.d}n| d| t| d|  | }d| vrHd}n| d| t| d|  | }d| vrbd}n| d| t| d|  | }|| | |  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$   lcc_simpx   s    
&&&&r&   )__doc__r	   r%   r&   r#   r#   r#   r$   <module>   s   k