
:>"^                 @   s   d  Z  d d l Z d d l m Z d d   Z d d   Z d d	   Z d
 d   Z Gd d   d e  Z	 e
 d k r d d l Z d d l m Z e   Z e j d e j d  Z e	 e d e j d  d S)aH  Wrappers for PSEA, a program for secondary structure assignment.

See this citation for P-SEA, PMID: 9183534

Labesse G, Colloc'h N, Pothier J, Mornon J-P:  P-SEA: a new efficient
assignment of secondary structure from C_alpha.
Comput Appl Biosci 1997 , 13:291-295

ftp://ftp.lmcp.jussieu.fr/pub/sincris/software/protein/p-sea/
    N)is_aac             C   s?   t  j d |   |  j d  d } | j d  d } | d S)aE  Run PSEA and return output filename.

    Note that this assumes the P-SEA binary is called "psea" and that it is
    on the path.

    Note that P-SEA will write an output file in the current directory using
    the input filename with extension ".sea".

    Note that P-SEA will write output to the terminal while run.
    zpsea /   .r   z.sea)ossystemsplit)fnamelastbase r   1/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/PSEA.pyrun_psea   s    r   c             C   s   t  |   } d } d } t | d  k } xa | j   D]S } | d d  d k r\ d } q7 | se q7 | d d k rv P| | d d	  } q7 WWd QRX| S)
zParse PSEA output file.r    r   z>p-sear   
Nr   )r   open	readlines)Zpnamer
   startssfplr   r   r   psea)   s    r   c             C   sd   g  } xW |  D]O } | d k r( d } n' | d k r= d } n | d k rO d } | j  |  q W| S)z3Translate PSEA secondary structure string into HEC.aHbEcC)append)Zpseqseqr   nr   r   r   psea2HEC;   s    		r$   c             C   s   |  j    d } | j    } g  } x' | D] } t |  r) | j |  q) Wt |  } | t |  k s t d | t |  f   x, t d |  D] } | | | | j d <q Wd S)z;Apply secondary structure information to residues in model.r   zLength mismatch %i %iZSS_PSEAN)Zget_listr   r!   len
ValueErrorrangeZxtra)mss_seqr   allZresiduesresLir   r   r   annotateI   s    r.   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)PSEAziDefine PSEA class.

    PSEA object is a wrapper to PSEA program for secondary structure assignment.
    c             C   s2   t  |  } t |  } t | |  | |  _ d S)zInitialize the class.N)r   r$   r.   r)   )selfmodelfilenamer)   r   r   r   __init__`   s    zPSEA.__init__c             C   s   |  j  S)z"Return secondary structure string.)r)   )r0   r   r   r   get_seqg   s    zPSEA.get_seqN)__name__
__module____qualname____doc__r3   r4   r   r   r   r   r/   Z   s   r/   __main__)	PDBParserXr   )r8   r   ZBio.PDB.Polypeptider   r   r   r$   r.   objectr/   r5   sysZBio.PDBr:   pZget_structureargvsr   r   r   r   <module>   s   	