ó
šxTc           @   sH   d  d l  m Z d  d l m Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   rsam(   t   bioinformaticsc         C   sN  t  t | j | j ƒ ƒ } x,| D]} | j d | j ƒ t j d | j d |  d | j	 d | d | ƒ \ } } | d k  r‘ | j d ƒ q" n  | j j
 d }	 | j j
 | }
 t |
 ƒ t | ƒ k sß t d	 |
 | f ƒ ‚ | j d
 ƒ | j d ƒ t j d |	 |
 g d d d g ƒ } | j t | ƒ ƒ | j | | f SWt d ‚ d  S(   Ns   Trying %s...t	   alignmentt   residuest   consecutivityt   one_letter_fort
   min_lengthi    s   No match, discardeds   len( %s ) != len( %s )s   Matching sequence found!s   Mapping to master:t
   alignmentst   namest   MASTERt   CURRENTs   No matching alignment found(   t   dictt   zipt   three_letter_codest   one_letter_codest   infot   nameR    t   map_to_alignmentt   objectR   R   t   lent   AssertionErrorR   t   clustal_alignmentt   strt   RuntimeError(   R   R   R   t   mm_typet   loggerR   t   alot   indext   rmapt   mastert   seqt   pairwise(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   alignment_search   s0    			.	c         C   sR   x4 |  D], } t  j d | j ƒ  j | j ƒ  f ƒ q Wt  j d t |  ƒ ƒ d  S(   Ns   Chain %s, residue %ss   Altogether %s residues(   R   t   debugt   parentt   idt   residR   R   (   R   t   r(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   log_residues+   s    *c         C   sa   d d  l  } | j j d |  d | ƒ } | j ƒ  } t j d | j | j g d | | g ƒ } | S(   Niÿÿÿÿt   seq_at   seq_bR   R   (   t   mmtbx.alignmentR   t   alignt   extract_alignmentR   R   t   at   b(   R'   R(   t   name_at   name_bt   mmtbxt	   align_objt   tmpt   ali(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   create_alignment3   s    	c         C   sv   g  } | j  d ƒ xC | D]; } t d |  d | d ƒ } | j | | | j ƒ  f ƒ q W| j d d „  d t ƒ | S(   Ns   Scoring alignment sequences...t   firstt   secondi    t   keyc         S   s   |  d S(   Ni   (    (   R,   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   <lambda>I   s    t   reverse(   R   R4   t   appendt   identity_countt   sortt   True(   t   trialt
   collectionR   t   scoredt   mR3   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   rank_sequences_by_match@   s     N(   t   phaserR    t   iotbxR   R    R&   R4   RB   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/application_utils.pyt   <module>   s
   	&		