
:>"^œ  ã               @   s`   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z Gd d „  d e	 ƒ Z
 d S)	zHMap residues of two structures to each other based on a FASTA alignment.é    )Úprint_function)ÚSCOPData)Ú	Selection)Úis_aac               @   sL   e  Z d  Z d Z d 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{  | j  ƒ  } t j | d ƒ } t j | d ƒ } d }	 d }
 i  } i  } g  } xt | ƒ D]ý } | d d … | f } | | } | | } | d k rÒ x% | |	 } |	 d }	 t | ƒ rš Pqš W|  j | | ƒ n d } | d k rx% | |
 } |
 d }
 t | ƒ rç Pqç W|  j | | ƒ n d } | r5| | | <| rE| | | <| j | | 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_alignÚm1Úm2ÚsiZsjÚlengthZrl1Zrl2Úp1Úp2r   r   r   ÚiÚcolumnÚaa1Zaa2Úr1Zr2© r   ú?/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/StructureAlignment.pyÚ__init__   sH    








		zStructureAlignment.__init__c             C   s/   | j  ƒ  } 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   Úresnamer   r   r   r   Q   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_mapsW   s    zStructureAlignment.get_mapsc             c   s3   x, t  d t |  j ƒ ƒ D] } |  j | Vq Wd 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)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r"   r   r   r   r   r      s
   <r   N)r&   Ú
__future__r   ZBio.Datar   ZBio.PDBr   ZBio.PDB.Polypeptider   Úobjectr   r   r   r   r   Ú<module>   s
   