
:>"^h                 @   sR   d  Z  d d l m Z Gd d   d e  Z d d   Z Gd 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   sD   d |  _  d |  _ d |  _ d |  _ i  |  _ | r@ |  j |  d S)zInitialize the class. N)sidresiduessccssunid	hierarchy_process)selfline r   1/tmp/pip-build-ww9dw3qa/biopython/Bio/SCOP/Cla.py__init__'   s    					zRecord.__init__c       	      C   s   | j    } | j d  } t |  d k r= t d |   | \ |  _ } } |  _ |  _ } t j |  |  _ | |  j _	 t
 |  j  |  _ x? | j d  D]. } | j d  \ } } t
 |  |  j | <q Wd  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   s   g  } | j  |  j  | t |  j  j d  7} | j  |  j  | j  |  j  | j  d j d d   |  j j	   D   d j t
 t |   d S)zCRepresent the SCOP classification record as a tab-separated string. r   c             s   s0   |  ]& \ } } d  j  | 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__)__name__
__module____qualname____doc__r   r
   r'   r   r   r   r   r      s   
r   c             c   s2   x+ |  D]# } | j  d  r q t |  Vq Wd 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    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   s   t  j |   | |  _ t |  j d  p } d } x` | j   } | sG P| j d  rY q4 t |  } | j } | d k	 r | |  | <| j   } q4 WWd QRXd S)zWCreate CLA index.

        Arguments:
         - filename - The file to index

        rU    r,   N)	dictr   filenameopenreadliner-   r   r   tell)r   r4   fpositionr   recordr   r   r   r   r   a   s    		
zIndex.__init__c          	   C   sW   t  j |  |  } t |  j d  , } | j |  | j   } t |  } Wd QRX| S)z%Return an item from the indexed file.r1   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   r0   ^   s   r0   N)r+   r   r   objectr   r/   r3   r0   r   r   r   r   <module>   s   :