
:>"^ÿ  ã               @   sJ   d  Z  d d l Z e j d ƒ Z e j d ƒ Z Gd d „  d e ƒ Z d S)z.A collection of residues from a PDB structure.é    Nz^(\w\w\w\w)(?:$|\s+|_)(.*)z \(?(\w:)?(-?\w*)-?(-?\w*)\)?(.*)c               @   s=   e  Z d  Z d Z d d d „ Z d d „  Z d d „  Z d S)	ÚResiduesaà  A collection of residues from a PDB structure.

    This class provides code to work with SCOP domain definitions. These
    are concisely expressed as one or more chain fragments. For example,
    "(1bba A:10-20,B:)" indicates residue 10 through 20 (inclusive) of
    chain A, and every residue of chain B in the pdb structure 1bba. The pdb
    id and brackets are optional. In addition "-" indicates every residue of
    a pbd structure with one unnamed chain.

    Start and end residue ids consist of the residue sequence number and an
    optional single letter insertion code. e.g. "12", "-1", "1a", "1000"


    pdbid -- An optional PDB id, e.g. "1bba"

    fragments -- A sequence of tuples (chainID, startResID, endResID)

    Nc             C   s/   d |  _  f  |  _ | d k	 r+ |  j | ƒ d S)zInitialize the class.Ú N)ÚpdbidÚ	fragmentsÚ_parse)ÚselfÚstr© r	   ú6/tmp/pip-build-ww9dw3qa/biopython/Bio/SCOP/Residues.pyÚ__init__$   s    		zResidues.__init__c       	      C   sW  | j  ƒ  } t j | ƒ } | d  k	 rH | j d ƒ |  _ | j d ƒ } | d k sl | d k sl | d k rp d  Sg  } xË | j d ƒ D]º } t j | ƒ } | d  k r· t d | ƒ ‚ | j ƒ  \ } } } } | d k rë t d | ƒ ‚ | r$| d
 d k rt d	 | ƒ ‚ | d  d … } n d } | j	 | | | f ƒ q† Wt
 | ƒ |  _ d  S)Né   é   r   ú-z(-)ú,z#I don't understand the format of %sú:z"I don't understand the chain in %séÿÿÿÿr   )ÚstripÚ	_pdbid_reÚmatchÚgroupr   ÚsplitÚ_fragment_reÚ
ValueErrorÚgroupsÚappendÚtupler   )	r   r   Úmr   ÚlÚchainÚstartÚendZpostfixr	   r	   r
   r   +   s,    $zResidues._parsec             C   s±   d } |  j  r |  j  d } |  j s- | d Sg  } xj |  j D]_ \ } } } g  } | ri | j d | ƒ | r† | j d | | f ƒ | j d j | ƒ ƒ q= W| d j | ƒ S)z/Represent the SCOP residues record as a string.r   ú r   z%s:z%s-%sr   )r   r   r   Újoin)r   ÚprefixÚstrsr   r   r    Úsr	   r	   r
   Ú__str__K   s    		zResidues.__str__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r	   r	   r	   r
   r      s    r   )r*   ÚreÚcompiler   r   Úobjectr   r	   r	   r	   r
   Ú<module>   s   