ó
ê9êHc           @   s  d  d l  Z  d  d l Z d  d l Td  d l m Z d  d l m Z d  d l Z d Z e j	 d ƒ Z
 i  Z d e d <d	 e d
 <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d  <d! e d" <d# e d$ <d% e d& <d' e d( <d' e d) <d* e d+ <d, e d- <d. „  Z d/ d0 „ Z d1 „  Z d2 e f d3 „  ƒ  YZ e d4 k rd  d l Z e ƒ  Z e j d5 e j d6 ƒ Z e d7 Z e e e j d6 ƒ Z x e D] Z e GHqÆWe j ƒ  GHe e ƒ GHe j d9 ƒ GHe d: GHe d7 d8 d6 j GHn  d S(;   iÿÿÿÿN(   t   *(   t   PDBException(   t   AbstractResiduePropertyMapsï  
Use the DSSP program to calculate secondary structure and accessibility.
You need to have a working version of DSSP (and a license, free for 
academic use) in order to use this. For DSSP, see U{http://www.cmbi.kun.nl/gv/dssp/}.

The DSSP codes for secondary structure used here are:

    - H        Alpha helix (4-12)
    - B        Isolated beta-bridge residue
    - E        Strand
    - G        3-10 helix
    - I        pi helix
    - T        Turn
    - S        Bend
    - -        None
s   [a-z]g     €Z@t   ALAg     à`@t   CYSg     `d@t   ASPg     @h@t   GLUg      h@t   PHEg      U@t   GLYg      g@t   HISg      e@t   ILEg      i@t   LYSg     €d@t   LEUg     €g@t   METg      c@t   ASNg      a@t   PROg     Àh@t   GLNg      o@t   ARGg     @`@t   SERg     Àa@t   THRt   VALg     `l@t   TRPg     Àk@t   TYRc         C   s@   |  d k r d S|  d k r  d S|  d k r0 d Sd s< t  ‚ d S(   sF   
    Secondary structure symbol to index.
    H=0
    E=1
    C=2
    t   Hi    t   Ei   t   Ci   N(   t   AssertionError(   t   ss(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyt   ss_to_index<   s    t   dsspc         C   sC   t  j ƒ  } t j | d |  | f ƒ t | ƒ \ } } | | f S(   sÇ  
    Create a DSSP dictionary from a PDB file.

    Example:
        >>> dssp_dict=dssp_dict_from_pdb_file("1fat.pdb")
        >>> aa, ss, acc=dssp_dict[('A', 1)]

    @param in_file: pdb file
    @type in_file: string

    @param DSSP: DSSP executable (argument to os.system)
    @type DSSP: string

    @return: a dictionary that maps (chainid, resid) to 
        amino acid type, secondary structure code and 
        accessibility.
    @rtype: {}
    s    %s > %s(   t   tempfilet   mktempt   ost   systemt   make_dssp_dict(   t   in_filet   DSSPt   out_filet   dictt   keys(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyt   dssp_dict_from_pdb_fileK   s    c         C   s4  i  } t  |  d ƒ } d } g  } xü | j ƒ  D]î } | j ƒ  } | d d k r\ d } q. n  | sh q. n  | d d k r~ q. n  t | d d !ƒ } | d } | d	 }	 | d
 }
 | d } | d k rÎ d } n  t | d d !ƒ } d | | f } |
 | | f | |	 | f <| j |	 | f ƒ q. W| j ƒ  | | f S(   s¶   
    Return a DSSP dictionary that maps (chainid, resid) to
    aa, ss and accessibility, from a DSSP file.

    @param filename: the DSSP output file
    @type filename: string
    t   ri    i   t   RESIDUEi	   t    i   i
   i   i   i   t   -i"   i&   (   t   opent	   readlinest   splitt   intt   appendt   close(   t   filenameR   t   fpt   startR'   t   lt   slt   resseqt   icodet   chainidt   aaR   t   acct   res_id(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyR"   e   s4    



	
R$   c           B   s   e  Z d  Z d d „ Z RS(   s¸  
    Run DSSP on a pdb file, and provide a handle to the 
    DSSP secondary structure and accessibility.

    Note that DSSP can only handle one model.

    Example:
        >>> p=PDBParser()
        >>> structure=parser.get_structure("1fat.pdb")
        >>> model=structure[0]
        >>> dssp=DSSP(model, "1fat.pdb")
        >>> # print dssp data for a residue
        >>> secondary_structure, accessibility=dssp[(chain_id, res_id)]
    R   c         C   sZ  t  | | ƒ \ } } i  } g  } x| D]} | \ }	 }
 | |	 } | |
 } | | \ } } } | | j d <| | j d <| j ƒ  } | t | } | d k rª d } n  | | j d <t | } | d k rè t j | ƒ rè d } qè n  | | k st d t | ƒ ƒ ‚ n  | | | | f | | <| j	 | | | | f ƒ q( Wt
 j |  | | | ƒ d S(   s  
        @param model: the first model of the structure
        @type model: L{Model}

        @param pdb_file: a PDB file
        @type pdb_file: string

        @param dssp: the dssp executable (ie. the argument to os.system)
        @type dssp: string
        t   SS_DSSPt   EXP_DSSP_ASAg      ð?t   EXP_DSSP_RASAR   s   Structure/DSSP mismatch at N(   R(   t   xtrat   get_resnamet   MAX_ACCt   to_one_letter_codet	   _dssp_cyst   matchR   t   strR1   R   t   __init__(   t   selft   modelt   pdb_fileR   t	   dssp_dictt	   dssp_keyst   dssp_mapt	   dssp_listt   keyt   chain_idR=   t   chaint   resR;   R   R<   t   resnamet   rel_acc(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyRH   š   s0    

	
(   t   __name__t
   __module__t   __doc__RH   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyR$   ‹   s   t   __main__t   Xi   i    t   A(   R[   i   (   R[   i   (   R    R   t   Bio.PDBt   PDBExceptionsR   t   AbstractPropertyMapR   t   reRX   t   compileRE   RC   R   R(   R"   R$   RV   t   syst	   PDBParsert   pt   get_structuret   argvt   sRJ   t   dR)   R'   t   lent   has_keyRA   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/DSSP.pyt   <module>   sZ   




















		&=	
		