B
    b                 @   s   d Z ddlZddlmZ dd Zdd Zdd	 Zd
d ZG dd dZe	dkrddl
Z
ddlmZ e Ze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   s2   t d| g | dd }|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.
    psea/.r   z.sea)
subprocessZcallsplit)fnameZlastbase r   +lib/python3.7/site-packages/Bio/PDB/PSEA.pyrun_psea   s    r   c          	   C   sp   t | }d}d}t|N}xF|D ]>}|dd dkr:d}q |s@q |d dkrNP ||dd  }q W W dQ R X |S )	zParse PSEA output file.r       z>p-sea   
r   N)r   open)Zpnamer	   startssfplr   r   r   r   )   s    

r   c             C   sH   g }x>| D ]6}|dkrd}n|dkr*d}n|dkr6d}| | 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   |   d }|  }g }x|D ]}t|r|| qW t|}|t|ks`td|t|f x$td|D ]}|| || jd< qlW d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residuesZ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   s$   t |}t|}t|| || _dS )zInitialize the class.N)r   r    r)   r%   )selfZmodelfilenamer%   r   r   r   __init__`   s    
zPSEA.__init__c             C   s   | j S )z"Return secondary structure string.)r%   )r+   r   r   r   get_seqg   s    zPSEA.get_seqN)__name__
__module____qualname____doc__r-   r.   r   r   r   r   r*   Z   s   r*   __main__)	PDBParserXr   )r2   r   ZBio.PDB.Polypeptider   r   r   r    r)   r*   r/   sysZBio.PDBr4   pZget_structureargvsr   r   r   r   <module>   s   