o
    Rŀg                     @   sT   d Z ddlZddlZddlmZ dddZdd Zd	d
 Zdd ZG dd dZ	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_aaFc                 C   st   |  dd }| dd }d| g}tj|ddd}|r!t|j |j s2tj	|d r2|d S t
d	|j )
al  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 not write output to the terminal while run unless
     verbose is set to True.
    /.r   pseaT)capture_outputtextz.seazError running p-sea: )split
subprocessrunprintstdoutstderrstripospathexistsRuntimeError)fnameverboselastbasecmdp r   @/var/www/html/myenv/lib/python3.10/site-packages/Bio/PDB/PSEA.pyrun_psea   s   
r   c                 C   s   t | }d}d}t|4}|D ] }|dd dkrd}q|sq|d dkr' n||dd  }qW d   |S W d   |S 1 sCw   Y  |S )	zParse PSEA output file.r       z>p-sea   
r   N)r   open)pnamer   startssfpliner   r   r   r   4   s*   





r   c                 C   sD   g }| D ]}|dkrd}n|dkrd}n|dkrd}| | q|S )z3Translate PSEA secondary structure string into HEC.aHbEcC)append)pseqseqr$   nr   r   r   psea2HECF   s   r1   c                 C   s   |   d }|  }g }|D ]}t|r|| qt|}|t|ks.td|t|f t|D ]}|| || jd< q2dS )z;Apply secondary structure information to residues in model.r   zLength mismatch %i %iSS_PSEAN)get_listr   r-   len
ValueErrorrangextra)mss_seqr+   allresiduesresLir   r   r   annotateT   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   r1   r?   r9   )selfmodelfilenamer9   r   r   r   __init__k   s   

zPSEA.__init__c                 C   s   | j S )z"Return secondary structure string.)r9   )rA   r   r   r   get_seqr   s   zPSEA.get_seqN)__name__
__module____qualname____doc__rD   rE   r   r   r   r   r@   e   s    r@   )F)
rI   r   r
   Bio.PDB.Polypeptider   r   r   r1   r?   r@   r   r   r   r   <module>   s   
