B
    ‰°bn  ã               @   s:   d Z ddlmZ ddlmZ ddlmZ G dd„ dƒZdS )zHMap residues of two structures to each other based on a FASTA alignment.é    )ÚSCOPData)Ú	Selection)Úis_aac               @   s2   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚStructureAlignmentzGClass to align two structures based on an alignment of their sequences.r   é   c             C   s  |  ¡ }t |d¡}t |d¡}d}	d}
i }i }g }xÊt|ƒD ]¾}|dd…|f }|| }|| }|dkr˜x||	 }|	d }	t|ƒrlP qlW |  ||¡ nd}|dkrÒx||
 }|
d }
t|ƒr¦P q¦W |  ||¡ nd}|râ|||< |rî|||< | ||f¡ q>W || _|| _|| _	dS )zÚInitialize.

        Attributes:
         - fasta_align - Alignment object
         - m1, m2 - two models
         - si, sj - the sequences in the Alignment object that
           correspond to the structures

        ÚRr   Nú-r   )
Zget_alignment_lengthr   Zunfold_entitiesÚranger   Ú_test_equivalenceÚappendÚmap12Úmap21Úduos)ÚselfZfasta_alignZm1Zm2ZsiZsjÚlengthZrl1Zrl2Zp1Zp2r   r   r   ÚiÚcolumnÚaa1Zaa2Úr1Zr2© r   ú9lib/python3.7/site-packages/Bio/PDB/StructureAlignment.pyÚ__init__   sH    
zStructureAlignment.__init__c             C   s"   |  ¡ }tj| }||kst‚dS )z6Test if aa in sequence fits aa in structure (PRIVATE).N)Zget_resnamer   Zprotein_letters_3to1ÚAssertionError)r   r   r   Zresnamer   r   r   r
   P   s    
z$StructureAlignment._test_equivalencec             C   s   | j | jfS )z­Map residues between the structures.

        Return two dictionaries that map a residue in one structure to
        the equivealent residue in the other structure.
        )r   r   )r   r   r   r   Úget_mapsV   s    zStructureAlignment.get_mapsc             c   s*   x$t dt| jƒƒD ]}| j| V  qW dS )z*Create an iterator over all residue pairs.r   N)r	   Úlenr   )r   r   r   r   r   Úget_iterator^   s    zStructureAlignment.get_iteratorN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r   r   r   r   r   r   r      s
   
<r   N)r   ZBio.Datar   ZBio.PDBr   ZBio.PDB.Polypeptider   r   r   r   r   r   Ú<module>   s   