B
    ‰°bg  ã               @   s0   d Z dd„ Zdd„ ZG dd„ deƒZdd„ Zd	S )
a+  Parse the enzyme.dat file from Enzyme at ExPASy.

See https://www.expasy.org/enzyme/

Tested with the release of 03-Mar-2009.

Functions:
 - read       Reads a file containing one ENZYME entry
 - parse      Reads a file containing multiple ENZYME entries

Classes:
 - Record     Holds ENZYME data.

c             c   s   xt | ƒ}|sP |V  qW dS )z¡Parse ENZYME records.

    This function is for parsing ENZYME files containing multiple
    records.

    Arguments:
     - handle   - handle to the file.

    N)Ú__read)ÚhandleÚrecord© r   ú0lib/python3.7/site-packages/Bio/ExPASy/Enzyme.pyÚparse   s
    
r   c             C   s    t | ƒ}|  ¡ }|rtdƒ‚|S )z¥Read one ENZYME record.

    This function is for parsing ENZYME files containing
    exactly one record.

    Arguments:
     - handle   - handle to the file.

    z!More than one ENZYME record found)r   ÚreadÚ
ValueError)r   r   Z	remainderr   r   r   r   (   s
    
r   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚRecordað  Holds information from an ExPASy ENZYME record as a Python dictionary.

    Each record contains the following keys:

    - ID: EC number
    - DE: Recommended name
    - AN: Alternative names (if any)
    - CA: Catalytic activity
    - CF: Cofactors (if any)
    - PR: Pointers to the Prosite documentation entrie(s) that
      correspond to the enzyme (if any)
    - DR: Pointers to the Swiss-Prot protein sequence entrie(s)
      that correspond to the enzyme (if any)
    - CC: Comments

    c             C   sN   t  | ¡ d| d< d| d< g | d< d| d< d| d< g | d< g | d< g | d	< d
S )zInitialize the class.Ú ÚIDÚDEÚANÚCAÚCFÚCCÚPRÚDRN)ÚdictÚ__init__)Úselfr   r   r   r   L   s    
zRecord.__init__c             C   sP   | d r@| d r*d| j j| d | d f S d| j j| d f S nd| j j S d S )Nr   r   z%s (%s, %s)z%s (%s)z%s ( ))Ú	__class__Ú__name__)r   r   r   r   Ú__repr__X   s
    zRecord.__repr__c             C   sr   d| d  d| d  dt | d ƒ d| d  d	 d
| d  dt | d ƒ dt | d ƒ dt| d ƒ g}d |¡S )NzID: r   zDE: r   zAN: r   zCA: 'r   ú'zCF: r   zCC: r   zPR: r   zDR: %d Recordsr   Ú
)ÚreprÚlenÚjoin)r   Úoutputr   r   r   Ú__str__a   s    


zRecord.__str__N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   :   s   	r	   c       
      C   s  d }xþ| D ]ô}|d d… |dd …   ¡  }}|dkrHtƒ }||d< q|dkrb|d  |7  < q|dkr®|d rž|d d  d¡sž|d d  d| 7  < n|d  |¡ q|d	krÈ|d	  |7  < q|d
kr|  d¡ d¡}x8|D ]0}| d¡\}}| ¡ | ¡ g}	|d
  |	¡ qèW q|dkrR|d rH|d  d| 7  < n||d< q|dkrŽ| d¡slt‚|dd …   d¡}|d  |¡ q|dkrð| d¡r¼|d  |dd … ¡ n2| d¡r|d r|d d  |dd … 7  < q|dkr|r|S qqW |rtdƒ‚d S )Né   é   r   r   r   éÿÿÿÿÚ.ú r   r   ú;ú,r   r   z	PROSITE; é	   r   z-!- é   z    é   z//zUnexpected end of stream)	Úrstripr	   ÚendswithÚappendÚsplitÚstripÚ
startswithÚAssertionErrorr   )
r   r   ÚlineÚkeyÚvalueZ	pair_dataZpairZt1Zt2Úrowr   r   r   r   r   sN    







r   N)r"   r   r   r   r	   r   r   r   r   r   Ú<module>   s   8