ó
¤ï	Ic           @   sR   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t
   RanaConfig(   t
   complementt   PrintFormatc           B   sò   e  Z d  Z e j Z e j Z e j Z e e Z e e Z e j	 Z	 e e Z
 d „  Z d d „ Z d d d „ Z g  d g  d d „ Z d „  Z d „  Z d	 „  Z d
 „  Z g  d d „ Z g  d d „ Z g  d d „ Z g  d d „ Z d „  Z RS(   sB   PrintFormat allow the printing of results of restriction analysis.c         C   s   d S(   s)   PrintFormat() -> new PrintFormat InstanceN(    (   t   self(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   __init__E   s    t   listc         C   sF   | d k r |  j  |  _ n' | d k r6 |  j |  _ n |  j |  _ d S(   sk  PF.print_as([what='list']) -> print the results as specified.

        Valid format are :
            'list'      -> alphabetical order
            'number'    -> number of sites in the sequence
            'map'       -> a map representation of the sequence with the sites.

        If you want more flexibility over-ride the virtual method make_format.
        t   mapt   numberN(   t	   _make_mapt   make_formatt   _make_numbert
   _make_list(   R   t   what(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   print_asI   s    
t    c         C   s€   | s |  j  } n  g  g  } } xC | j ƒ  D]5 \ } } | rT | j | | f ƒ q, | j | ƒ q, W|  j | | | | ƒ GHd S(   sÒ  PF.print_that(dct, [title[, s1]]) -> Print dct nicely formatted.

        dct is a dictionary as returned by a RestrictionBatch.search()
        
        title is the title of the map.
        It must be a formated string, i.e. you must include the line break.
        
        s1 is the title separating the list of enzymes that have sites from
        those without sites.
        s1 must be a formatted string as well.

        The format of print_that is a list.N(   t   resultst	   iteritemst   appendR	   (   R   t   dctt   titlet   s1t   lst   nct   kt   v(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt
   print_that]   s    c         C   s   |  j  | | | | ƒ S(   sÇ   PF.make_format(cut, nc, title, s) -> string

        Virtual method.
        Here to be pointed to one of the _make_* methods.
        You can as well create a new method and point make_format to it.(   R   (   R   t   cutR   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR	   u   s    c         C   s    |  j  | | ƒ |  j | | ƒ S(   s|  PF._make_number(ls,title, nc,s1) -> string.

        return a string of form :
        
        title.

        enzyme1     :   position1, position2.
        enzyme2     :   position1, position2, position3.

        ls is a list of cutting enzymes.
        title is the title.
        nc is a list of non cutting enzymes.
        s1 is the sentence before the non cutting enzymes.(   t   _make_list_onlyt   _make_nocut_only(   R   R   R   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR      s    c         C   s    |  j  | | ƒ |  j | | ƒ S(   s¡  PF._make_number(ls,title, nc,s1) -> string.

        return a string of form :
        
        title.

            enzyme1, position
            |
        AAAAAAAAAAAAAAAAAAAAA...
        |||||||||||||||||||||
        TTTTTTTTTTTTTTTTTTTTT...

        ls is a list of cutting enzymes.
        title is the title.
        nc is a list of non cutting enzymes.
        s1 is the sentence before the non cutting enzymes.(   t   _make_map_onlyR   (   R   R   R   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR      s    c         C   s    |  j  | | ƒ |  j | | ƒ S(   s§  PF._make_number(ls,title, nc,s1) -> string.

        title.
        
        enzyme which cut 1 time :
        
        enzyme1     :   position1.

        enzyme which cut 2 times :
        
        enzyme2     :   position1, position2.
        ...

        ls is a list of cutting enzymes.
        title is the title.
        nc is a list of non cutting enzymes.
        s1 is the sentence before the non cutting enzymes.(   t   _make_number_onlyR   (   R   R   R   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR
   ¢   s    c         C   s   | |  j  | | ƒ S(   se  PF._make_nocut(ls,title, nc,s1) -> string.

        return a formatted string of the non cutting enzymes.

        ls is a list of cutting enzymes -> will not be used.
        Here for compatibility with make_format.
        
        title is the title.
        nc is a list of non cutting enzymes.
        s1 is the sentence before the non cutting enzymes.(   R   (   R   R   R   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   _make_nocut¶   s    c   	      C   s³   | s
 | S| j  ƒ  d } | p# d } d j } xh | D]` } | | t j t | ƒ |  j ƒ f ƒ } t | ƒ |  j k r6 | | | d f ƒ } d } q6 q6 W| | | d f ƒ } | S(   sß   PF._make_nocut_only(nc, s1) -> string.

        return a formatted string of the non cutting enzymes.
        
        nc is a list of non cutting enzymes.
        s1 is the sentence before the non cutting enzymes.
        R   s,   
   Enzymes which do not cut the sequence.

s   
(   t   sortt   joint   strt   ljustt	   NameWidtht   lent   linesize(	   R   R   R   R   R   t   stt
   stringsitet   Joint   key(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR   Ã   s    
	'c         C   s   | s
 | S|  j  | | ƒ S(   sJ  PF._make_list_only(ls, title) -> string.

        return a string of form :
        
        title.

        enzyme1     :   position1, position2.
        enzyme2     :   position1, position2, position3.
        ...
        
        ls is a list of results.
        title is a string.
        Non cutting enzymes are not included.(   t   _PrintFormat__next_section(   R   R   R   R   R   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR   Ù   s    c         C   sÎ   | s
 | S| j  d „  ƒ t | ƒ } d } g  } x{ | D]s \ } }	 t |	 ƒ }
 |
 | k r™ | d | 7} |  j | | ƒ } | |	 f g |
 } } q9 n  | j | |	 f ƒ q9 W| d | 7} |  j | | ƒ S(   s§  PF._make_number_only(ls, title) -> string.

        return a string of form :
        
        title.
        
        enzyme which cut 1 time :
        
        enzyme1     :   position1.

        enzyme which cut 2 times :
        
        enzyme2     :   position1, position2.
        ...
        
                
        ls is a list of results.
        title is a string.
        Non cutting enzymes are not included.c         S   s!   t  t |  d ƒ t | d ƒ ƒ S(   Ni   (   t   cmpR%   (   t   xt   y(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   <lambda>  s    i   s    

enzymes which cut %i times :

(   R    t   iterR%   R+   R   (   R   R   R   R   R   t   iteratort   cur_lent   new_sectt   namet   sitest   l(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR   ë   s     c   !      C   s9  | s
 | Sg  | D] \ } } t  | ƒ ^ q } | j ƒ  | pB d } i  }	 x^ | D]V \ }
 } xG | D]? } | |	 k r‘ |	 | j t  |
 ƒ ƒ qe t  |
 ƒ g |	 | <qe WqR W|	 j ƒ  } | j ƒ  i  } d d t |  j ƒ } } } x t d | d ƒ D]k } | d } g  } xH | D]@ } | | k r7| j | ƒ q| | | <| | j | ƒ } PqW| | | <qø W| | | <|  j j ƒ  } t	 | ƒ } d } d \ } } d d } d j
 } x,t d | d ƒ D]} | d } | } x‚| | D]v} d } | | k rx' |	 | D] } d j
 | | f ƒ } qW| d d !} | | t  | ƒ | d f ƒ } | | | d f ƒ } | | | f ƒ } | | | f ƒ } Pn  x' |	 | D] } d j
 | | f ƒ } qšW| d } | | d | d !t  | ƒ | d f ƒ } | | d | d !| | | f ƒ } | | d | d !| | | d f ƒ } | | | f ƒ } | | | f ƒ } qåWd j
 | | | !| d | | | !| t  j t  | d ƒ d	 ƒ d d
 t  j t  | ƒ d	 ƒ d f ƒ f ƒ }  | | |  f ƒ } qÄWd d } x†| | D]z} d } | | k r£x' |	 | D] } | | d | f ƒ } qW| d | d !} | | t  | ƒ | d f ƒ } | | | d f ƒ } | | | f ƒ } | | | f ƒ } Pn  x' |	 | D] } | | d | f ƒ } q®W| d } | | d | d !t  | ƒ | d f ƒ } | | d | d !| | | f ƒ } | | d | d !| | | d f ƒ } | | | f ƒ } | | | f ƒ } qõWd }  | | | | !d f ƒ }  | |  | | | d f ƒ }  | |  | | | !d f ƒ }  | |  | t  j t  | d ƒ d	 ƒ d | | d
 t  j t  | ƒ d	 ƒ d f ƒ f ƒ }  | | |  f ƒ } | S(   s|  PF._make_map_only(ls, title) -> string.

        return a string of form :
        
        title.

            enzyme1, position
            |
        AAAAAAAAAAAAAAAAAAAAA...
        |||||||||||||||||||||
        TTTTTTTTTTTTTTTTTTTTT...
        
                
        ls is a list of results.
        title is a string.
        Non cutting enzymes are not included.
        R   i    i<   t   |t    i;   s   
i   i   i   s   

(   i    i    (   R"   R    R   t   keysR%   t   sequencet   xranget   indext   tostringR   R!   R#   t   rjust(!   R   R   R   R   R   R-   R.   t
   resultKeysR   t	   enzymemapt   enzymeR   t   ct   mappingt   cutloct   countert   lengthR6   R*   R:   t   revsequencet   at   baset	   emptylineR)   t   linet   st   nt   lineot   line2t   linetotR   t   mapunit(    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR     s°    %





	
  
)$'
#'
 
)$'%!c         C   s,  | j  ƒ  d |  j |  j d } |  j |  j } t j d | ƒ } d d j } } xÐ | D]È \ } }	 d }
 | d j g  |	 D] } t | ƒ ^ q~ ƒ d f ƒ } t	 | ƒ | k rñ g  t j
 | | ƒ D] } | j ƒ  ^ qÇ } | j | ƒ }
 n | }
 | | t | ƒ j |  j ƒ d |
 d f ƒ } q\ W| S(   sm  FP.__next_section(ls, into) -> string.

        ls is a list of tuple (string, [int, int]).
        into is a string to which the formatted ls will be added.

        Format ls as a string of lines :
        The form is :

        enzyme1     :   position1.
        enzyme2     :   position2, position3.

        then add the formatted ls to tot
        return tot.s   
R8   s   ([\w,\s()]){1,%i}[,\.]R   s   , t   .s    :  (   R    R$   t   IndentR&   t   MaxSizet   ret   compileR!   R"   R%   t   finditert   groupR#   (   R   R   t   intot   indentationR&   t   patt   severalR)   R4   R5   R(   t   siteR6   R-   (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   __next_section}  s    
4++(   t   __name__t
   __module__t   __doc__t   RanaConft   ConsoleWidthR$   RT   t   Cmodulot	   PrefWidthRS   R&   R   R   R   R	   R   R   R
   R   R   R   R   R   R+   (    (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyR   :   s*   			

	
	
				%m(	   RU   t	   itertoolst   Bio.RestrictionR    Rb   t   Bio.Restriction.DNAUtilsR   t   objectR   (    (    (    sŽ   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/Restriction/PrintFormat.pyt   <module>   s   ,