o
    RŀgR                     @   s:   d Z ddlmZ G dd dZdd ZG dd deZd	S )
aq  Handle the SCOP CLAssification file, which describes SCOP domains.

The file format is described in the scop
"release notes.":http://scop.mrc-lmb.cam.ac.uk/scop/release-notes.html
The latest CLA file can be found
"elsewhere at SCOP.":http://scop.mrc-lmb.cam.ac.uk/scop/parse/

"Release 1.73": http://scop.mrc-lmb.cam.ac.uk/scop/parse/dir.cla.scop.txt_1.73
(July 2008)

   )Residuesc                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
RecordaL  Holds information for one SCOP domain.

    Attributes:
     - sid - SCOP identifier. e.g. d1danl2
     - residues - The domain definition as a Residues object
     - sccs - SCOP concise classification strings.  e.g. b.1.2.1
     - sunid - SCOP unique identifier for this domain
     - hierarchy - A dictionary, keys are nodetype, values are sunid,
       describing the location of this domain in the SCOP hierarchy. See
       the Scop module for a description of nodetypes. This used to be a
       list of (key,value) tuples in older versions of Biopython (see
       Bug 3109).

    Nc                 C   s4   d| _ d| _d| _d| _i | _|r| | dS dS )zInitialize the class. N)sidresiduessccssunid	hierarchy_process)selfline r   @/var/www/html/myenv/lib/python3.10/site-packages/Bio/SCOP/Cla.py__init__'   s   zRecord.__init__c           	      C   s   |  }|d}t|dkrtd| |\| _}}| _| _}t|| _|| j_	t
| j| _|dD ]}|d\}}t
|| j|< q6d S )N	   z!I don't understand the format of ,=)rstripsplitlen
ValueErrorr   r   r   r   r   pdbidintr	   )	r   r   columnsr   r   r	   htkeyvaluer   r   r   r
   1   s   
zRecord._processc                 C   sp   g }| | j |t| jd7 }| | j | | j | ddd | j	 D  dt
t|d S )zCRepresent the SCOP classification record as a tab-separated string. r   c                 s   s&    | ]\}}d  |t|fV  qdS )r   N)joinstr).0r   r   r   r   r   	<genexpr>I   s    
z!Record.__str__.<locals>.<genexpr>r   
)appendr   r    r   r   r   r   r   r	   itemsmap)r   sr   r   r   __str__@   s   
zRecord.__str__)N)__name__
__module____qualname____doc__r   r
   r(   r   r   r   r   r      s
    

r   c                 c   s&    | D ]}| drqt|V  qdS )zmIterate over a CLA file as Cla records for each line.

    Arguments:
     - handle - file-like object.

    #N)
startswithr   )handler   r   r   r   parseQ   s   
r0   c                   @   s    e Zd ZdZdd Zdd ZdS )Indexz?A CLA file indexed by SCOP identifiers for rapid random access.c                 C   s   t |  || _t| j-}d}	 | }|sn|drqt|}|j}|dur-|| |< | }qW d   dS 1 s=w   Y  dS )zWCreate CLA index.

        Arguments:
         - filename - The file to index

            Tr-   N)	dictr   filenameopenreadliner.   r   r   tell)r   r4   fpositionr   recordr   r   r   r   r   a   s$   

"zIndex.__init__c                 C   sV   t | |}t| j}|| | }t|}W d   |S 1 s$w   Y  |S )z%Return an item from the indexed file.N)r3   __getitem__r5   r4   seekr6   r   )r   r   r9   r8   r   r:   r   r   r   r;   x   s   


zIndex.__getitem__N)r)   r*   r+   r,   r   r;   r   r   r   r   r1   ^   s    r1   N)r,   r   r   r   r0   r3   r1   r   r   r   r   <module>   s
   :