
    Xf0
                     >    d Z ddlmZ  G d de          Zd Zd ZdS )z5Parse Cluster Buster position frequency matrix files.    )motifsc                       e Zd ZdZ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                 @    d                     d | D                       S )zBReturn a string representation of the motifs in the Record object.
c              3   4   K   | ]}t          |          V  d S )N)str).0motifs     8lib/python3.11/site-packages/Bio/motifs/clusterbuster.py	<genexpr>z!Record.__str__.<locals>.<genexpr>   s(      66U666666    )join)selfs    r   __str__zRecord.__str__   s#    yy66666666r   N)__name__
__module____qualname____doc__r    r   r   r   r      s-         
7 7 7 7 7r   r   c                 v   d}t                      }g g g g dd}| D ]}|                                }|r|                    d          ra|dk    r2t          j        d          }||_        |                    |           |dd                                         }g g g g d|dz  }|                    d	          r|                                }t          |          d
k    rfdt          g d|          D              t          j        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                 f    g | ]-\  }}|                              t          |                    .S r   )appendfloat)r
   
nucleotidenucleotide_countnucleotide_countss      r   
<listcomp>zread.<locals>.<listcomp>4   sJ       8J(8 **5<<UCS=T=TUU  r   )
r   strip
startswithr   Motifnamer%   splitlenzip)handle	motif_nbrrecord
motif_nameliner   matrix_columnsr)   s          @r   readr8      sz   
 IXXF r<<J  zz|| 	s## >>"L&ARSSSE!+EJMM%(((!!""X^^--
*,2BR$H$H!Q		??3'' !%~&&!++   <?000.= =    L&1BCCCEEJ
MM%Mr   c                 :   g }| D ]}d|j          d}|                    |           t          |j        d         |j        d         |j        d         |j        d                   D ]}|                     dj        |             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%   r1   r    formatr   )r   linesmr6   ACGT_countstexts         r   writer?   B   s    E V V16~~~THSM18C=!(3-#
 
 	V 	VK LLF?FTUUUU	V 775>>DKr   N)r   Bior   listr   r8   r?   r   r   r   <module>rB      sr    < ;      7 7 7 7 7T 7 7 7( ( (V    r   