o
    Rŀg^                     @   s|   d Z ddlmZ ddlmZ ddlmZ ddlmZ g dZeZeZG dd dZ	d	d
 Z
edkr<ddlmZ e  dS dS )zCode to work with the KEGG Ligand/Compound database.

Functions:
 - parse - Returns an iterator giving Record objects.

Classes:
 - Record - A representation of a KEGG Ligand/Compound.
    )_default_wrap)_struct_wrap)
_wrap_kegg)_write_kegg)r    ) $   r	   )-r   r	   r	   c                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )Recorda  Holds info from a KEGG Ligand/Compound record.

    Attributes:
     - entry       The entry identifier.
     - name        A list of the compound names.
     - formula     The chemical formula for the compound
     - mass        The molecular weight for the compound
     - pathway     A list of 3-tuples: ('PATH', pathway id, pathway)
     - enzyme      A list of the EC numbers.
     - structures  A list of 2-tuples: (database, list of struct ids)
     - dblinks     A list of 2-tuples: (database, list of link ids)

    c                 C   s4   d| _ g | _d| _d| _g | _g | _g | _g | _dS )zInitialize as new record.r   N)entrynameformulamasspathwayenzyme
structuresdblinksself r   N/var/www/html/myenv/lib/python3.10/site-packages/Bio/KEGG/Compound/__init__.py__init__,   s   
zRecord.__init__c                 C   sD   |   |   |   |   |   |   |   |   d S )z.Return a string representation of this Record.///)_entry_name_formula_mass_pathway_enzyme_structures_dblinksr   r   r   r   __str__7   s$   zRecord.__str__c                 C      t d| jgS )NENTRY)r   r   r   r   r   r   r   E      zRecord._entryc                 C      t ddd | jD S )NNAMEc                 S      g | ]}t |td qS 	wrap_ruler   	name_wrap.0liner   r   r   
<listcomp>J       z Record._name.<locals>.<listcomp>)r   r   r   r   r   r   r   H      zRecord._namec                 C   r#   )NFORMULA)r   r   r   r   r   r   r   M   r%   zRecord._formulac                 C   r#   )NMASS)r   r   r   r   r   r   r   P   r%   zRecord._massc                 C   s>   g }| j D ]}||d d |d   qtddd |D S )Nr     r	   PATHWAYc                 S      g | ]
}t |td dqS )   r*   r   id_wrapr.   r   r   r   r1   X       z#Record._pathway.<locals>.<listcomp>)r   appendr   r   sr   r   r   r   r   S   s   
zRecord._pathwayc                 C   r&   )NENZYMEc                 S   r(   r)   r,   r.   r   r   r   r1   ]   r2   z"Record._enzyme.<locals>.<listcomp>)r   r   r   r   r   r   r   [   r3   zRecord._enzymec                 C   sH   g }| j D ]}||d d d|d  d  qtddd |D S )Nr   : r6   r	   
STRUCTURESc                 S   r8   )   r*   )r   struct_wrapr.   r   r   r   r1   e   r<   z&Record._structures.<locals>.<listcomp>)r   r=   joinr   r>   r   r   r   r    `   s   
&zRecord._structuresc                 C   sD   g }| j D ]}||d d d|d   qtddd |D S )Nr   rA   r   r	   DBLINKSc                 S   r8   )	   r*   r:   r.   r   r   r   r1   m   r<   z#Record._dblinks.<locals>.<listcomp>)r   r=   rE   r   r>   r   r   r   r!   h   s   
"zRecord._dblinksN)__name__
__module____qualname____doc__r   r"   r   r   r   r   r   r   r    r!   r   r   r   r   r      s    r   c                 c   s   t  }| D ]}|dd dkr|V  t  }q|dd dkr%|dd }|dd  }|dkr;| }|d |_q|dkrK|d	}|j| q|d
krj|ri|dd }|dd }| }|j| |sQq|dkr|d\}}	d||	f}
|j|
 q|dkr||_q|dv r||_	q|dkrd|v r|d\}}| }||f}|j
| q|j
d }|\}}||  ||f}||j
d< qdS )aC  Parse a KEGG Ligan/Compound file, returning Record objects.

    This is an iterator function, typically used in a for loop.  For
    example, using one of the example KEGG files in the Biopython
    test suite,

    >>> with open("KEGG/compound.sample") as handle:
    ...     for record in parse(handle):
    ...         print("%s %s" % (record.entry, record.name[0]))
    ...
    C00023 Iron
    C00017 Protein
    C00099 beta-Alanine
    C00294 Inosine
    C00298 Trypsin
    C00348 all-trans-Undecaprenyl phosphate
    C00349 2-Methyl-3-oxopropanoate
    C01386 NH2Mec

    N   r      z            zENTRY       r   zNAME        ;zENZYME      r9   zPATHWAY     r6   PATHzFORMULA     )zMASS        zEXACT_MASS  zDBLINKS     :)r   stripsplitr   r   r=   r   r   r   r   r   extend)handlerecordr0   keyworddatawordscolumnr   mapr   r   keyvaluesrowr   r   r   parseq   sZ   



r_   __main__)run_doctestN)rK   Bio.KEGGr   r   r   r   r-   r;   rD   r   r_   rH   
Bio._utilsra   r   r   r   r   <module>   s   	T@
