o
    Rŀg0
                     @   s4   d Z ddlmZ G dd deZdd Zdd Zd	S )
z5Parse Cluster Buster position frequency matrix files.    )motifsc                   @   s   e Zd ZdZdd ZdS )RecordzClass to store the information in a Cluster Buster matrix table.

    The record inherits from a list containing the individual motifs.
    c                 C   s   d dd | D S )zBReturn a string representation of the motifs in the Record object.
c                 s   s    | ]}t |V  qd S )N)str).0motif r   L/var/www/html/myenv/lib/python3.10/site-packages/Bio/motifs/clusterbuster.py	<genexpr>   s    z!Record.__str__.<locals>.<genexpr>)join)selfr   r   r	   __str__   s   zRecord.__str__N)__name__
__module____qualname____doc__r   r   r   r   r	   r      s    r   c                    s   d}t  }g g g g d d}| D ]R}| }|rb|drD|dkr0tjd d}||_|| |dd  }g g g g d |d7 }q|d	rJq| }t|d
krb fddt	g d|D  qtjd d}||_|| |S )zRead motifs in Cluster Buster position frequency matrix format from a file handle.

    Cluster Buster motif format: http://zlab.bu.edu/cluster-buster/help/cis-format.html
    r   )ACGT >GATC)alphabetcounts   N#   c                    s"   g | ]\}} |  t|qS r   )appendfloat)r   
nucleotidenucleotide_countnucleotide_countsr   r	   
<listcomp>4   s    zread.<locals>.<listcomp>)
r   strip
startswithr   Motifnamer   splitlenzip)handle	motif_nbrrecord
motif_nameliner   matrix_columnsr   r"   r	   read   s:   





r2   c                 C   sp   g }| D ],}d|j  d}|| t|jd |jd |jd |jd D ]
}|dj|  q%qd|}|S )	zWReturn the representation of motifs in Cluster Buster position frequency matrix format.r   r   r   r   r   r   z {:0.0f}	{:0.0f}	{:0.0f}	{:0.0f}
r   )r(   r   r+   r   formatr   )r   linesmr0   ACGT_countstextr   r   r	   writeB   s   
 
r8   N)r   Bior   listr   r2   r8   r   r   r   r	   <module>   s
   +