o
    Rŀg                     @   sl   d Z ddlmZ ddlmZ ddlmZ g dZeZG dd dZdd	 Ze	d
kr4ddl
mZ e  dS dS )zCode to work with the KEGG Gene database.

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

Classes:
- Record - A representation of a KEGG Gene.

    )_default_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S )Recorda  Holds info from a KEGG Gene record.

    Attributes:
     - entry       The entry identifier.
     - name        A list of the gene names.
     - definition  The definition for the gene.
     - orthology   A list of 2-tuples: (orthology id, role)
     - organism    A tuple: (organism id, organism)
     - position    The position for the gene
     - motif       A list of 2-tuples: (database, list of link ids)
     - dblinks     A list of 2-tuples: (database, list of link ids)

    c                 C   s4   d| _ g | _d| _g | _d| _d| _g | _g | _dS )zInitialize new record.r   N)entryname
definition	orthologyorganismpositionmotifdblinksself r   J/var/www/html/myenv/lib/python3.10/site-packages/Bio/KEGG/Gene/__init__.py__init__*   s   
zRecord.__init__c                 C   s   |   |   |   d S )z.Return a string representation of this Record.///)_entry_name_dblinksr   r   r   r   __str__5   s   zRecord.__str__c                 C      t d| jgS )NENTRY)r   r   r   r   r   r   r   9      zRecord._entryc                 C   s   t ddd | jD S )NNAMEc                 S   s   g | ]}t |td qS )	wrap_rule)r   	name_wrap.0liner   r   r   
<listcomp>>   s    z Record._name.<locals>.<listcomp>)r   r   r   r   r   r   r   <   s   zRecord._namec                 C   r   )N
DEFINITION)r   r   r   r   r   r   _definitionA   r   zRecord._definitionc                 C   sD   g }| j D ]}||d d d|d   qtddd |D S )Nr   : r   r   DBLINKSc                 S   s   g | ]
}t |td dqS )	   r!   )r   id_wrapr$   r   r   r   r'   I   s    z#Record._dblinks.<locals>.<listcomp>)r   appendjoinr   )r   sr   r   r   r   r   D   s   
"zRecord._dblinksN)
__name__
__module____qualname____doc__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rS||_q|dkri|d\}}||f}|j| q|dkr||d\}}||f}	|	|_q|dkr||_	q|dkr|d\}
}| }|
|f}|j
| q|dkrd|v r|d\}
}| }|
|f}|j| q|jd }|\}
}||  |
|f}||jd< qdS )a  Parse a KEGG Gene 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/gene.sample") as handle:
    ...     for record in parse(handle):
    ...         print("%s %s" % (record.entry, record.name[0]))
    ...
    b1174 minE
    b1175 minD


    N   r      z            zENTRY       r   zNAME        ;zDEFINITION  zORTHOLOGY   z  zORGANISM    zPOSITION    zMOTIF       r*   zDBLINKS     :)r
   stripsplitr   r   r.   r   r   r   r   r   r   extend)handlerecordr&   keyworddatawordsidr   r   r   keyvaluesrowr   r   r   parseM   s\   


rF   __main__)run_doctestN)r4   Bio.KEGGr   r   r   r#   r-   r
   rF   r1   
Bio._utilsrH   r   r   r   r   <module>   s   
2>
