
:>"^8  ã               @   s¶   d  Z  d d l m Z d d l 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 Gd
 d „  d e ƒ Z d d „  Z d d „  Z d d „  Z d S)a‘  Several routines used to extract information from FSSP sections.

filter: filters a passed summary section and alignment section according to a numeric
        attribute in the summary section. Returns new summary and alignment sections

For example, to filter in only  those records which have a zscore greater than
4.0 and lesser than 7.5:

new_sum, new_align = filter(sum, align, 'zscore', 4, 7.5)
é    )ÚFSSPN)ÚMultipleSeqAlignment)ÚAlphabet)ÚSeq)Ú	SeqRecordc               @   s"   e  Z d  Z d Z d d „  Z d S)Ú	FSSPAlignz@Provision to do single Multi Sequence Alignment from FSSP files.c             C   s   i  | j  d <i  | j  d <d  S)NZabs2pdbZpdb2abs)Úannotations)ÚselfZ
new_record© r
   ú7/tmp/pip-build-ww9dw3qa/biopython/Bio/FSSP/FSSPTools.pyÚ_add_numbering_table   s    zFSSPAlign._add_numbering_tableN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r
   r
   r   r      s   r   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚFSSPMultAlignzBProvision to do multiple Multi Sequence Alignment from FSSP files.c             C   s   g  |  _  g  |  _ i  |  _ d S)zInitialize the class.N)Zabs_resZpdb_resÚdata)r	   r
   r
   r   Ú__init__"   s    		zFSSPMultAlign.__init__N)r   r   r   r   r   r
   r
   r
   r   r      s   r   c             C   s  i  } x$ | j  d ƒ j D] } d | | <q Wx_ t d t | ƒ d ƒ D]D } x; | j  | ƒ j D]' } | | | j  | ƒ j | j 7<q` WqG Wt j t j j ƒ } t	 g  d | ƒ} xI t
 | ƒ D]; } | j t t | | | ƒ |  | j |  | j ƒ ƒ qÃ W| S)z:Return multiple alignment instance (MultipleSeqAlignment).é   Ú Zalphabet)ÚabsÚpos_align_dictÚrangeÚlenZaar   ZGappedZIUPACZextended_proteinr   ÚsortedÚappendr   r   Úpdb2Úchain2)Úsum_dictÚ
align_dictZmult_align_dictÚjÚiÚalphaZ
fssp_alignr
   r
   r   Ú
mult_align)   s     )0r#   c             C   sØ   t  j ƒ  } t j | ƒ } xG |  D]? } t |  | | ƒ } | | k r" | | k r" |  | | | <q" Wt | ƒ }	 xZ | j D]O }
 i  | j |
 ƒ _ x4 |	 D], } | j |
 ƒ j | | j |
 ƒ j | <qš Wq{ W| | f S)z¯Filter a passed summary section and alignment section.

    Filter according to a numeric attribute in the summary section.
    Return new summary and alignment sections.
    )	r   ÚFSSPSumDictÚcopyÚdeepcopyÚgetattrr   Úabs_res_dictr   r   )r   r   Zfilter_attributeZ	low_boundZ
high_boundÚnew_sum_dictÚnew_align_dictÚprot_numÚ
attr_valueÚprot_numbersÚpos_numr
   r
   r   ÚfilterG   s    	r/   c       	      C   sÜ   t  j ƒ  } t j | ƒ } xK | D]C } x: |  D]2 } |  | j |  | j | k r/ |  | | | <q/ Wq" Wt | ƒ } xZ | j D]O } i  | j | ƒ _	 x4 | D], } | j | ƒ j	 | | j | ƒ j	 | <qž Wq W| | f S)zÄFilter summary and alignment blocks for given names only.

    Accepts a list of names. Returns a new Summary block and Alignment block which
    contain the info only for those names passed.
    )
r   r$   r%   r&   r   r   r   r(   r   r   )	r   r   Ú	name_listr)   r*   Zcur_pdb_namer+   r-   r.   r
   r
   r   Úname_filter]   s    	r1   )r   ZBior   r%   Z	Bio.Alignr   r   ZBio.Seqr   ZBio.SeqRecordr   r   Údictr   r#   r/   r1   r
   r
   r
   r   Ú<module>   s   
