B
    bT                 @   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   s0   d| _ d| _d| _d| _i | _|r,| | dS )zInitialize the class. N)sidresiduessccssunid	hierarchy_process)selfline r   +lib/python3.7/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| _x.|dD ] }|d\}}t
|| j|< qlW d S )N	   z#I don't understand the format of %s,=)rstripsplitlen
ValueErrorr   r   r   r   r   pdbidintr	   )	r   r   columnsr   r   r	   Z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>J   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(   x"| D ]}| drqt|V  qW dS )zmIterate over a CLA file as Cla records for each line.

    Arguments:
     - handle - file-like object.

    #N)
startswithr   )Zhandler   r   r   r   parseQ   s    

r.   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   st   t |  || _t| jP}d}xD| }|s0P |dr<q"t|}|j}|dk	rZ|| |< | }q"W W dQ R X dS )zWCreate CLA index.

        Arguments:
         - filename - The file to index

            r,   N)	dictr   filenameopenreadliner-   r   r   tell)r   r2   fpositionr   recordr   r   r   r   r   a   s    

zIndex.__init__c          	   C   s@   t | |}t| j }|| | }t|}W dQ R X |S )z%Return an item from the indexed file.N)r1   __getitem__r3   r2   seekr4   r   )r   r   r7   r6   r   r8   r   r   r   r9   x   s    
zIndex.__getitem__N)r(   r)   r*   r+   r   r9   r   r   r   r   r/   ^   s   r/   N)r+   r   r   r   r.   r1   r/   r   r   r   r   <module>   s   :