
[_Sc           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 m Z m Z d d l m Z d d l Td d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l Z d	 d l Td	 d l Td	 d
 l m Z d d l Z d d l m  Z  d d l! m" Z" m# Z# m$ Z$ m% Z% d d l& Td d l' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- d d l. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 d d l5 m6 Z6 d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* g Z7 d+ Z8 e j9 Z9 d, j:   d	 Z; d- j:   d	 Z< d. e9 e; f Z= d/   Z> d e? f d0     YZ@ g  e- D] ZA e" eA ^ qlZB eC eD d1 d2  eD d3 d4  eD d5 d6  eD d7 d8  g  ZE i d d9 6eG d: 6eH d; 6eE d 6eI d< 6eJ d= 6eK d> 6ZL i eI e- 6eH e, 6eH e+ 6ZM i d? e
 d@  dA 6d? dB 6d? e
 dC  dD 6d? dE 6dz dI 6d| dK 6d dL 6ZN i dM dN 6d} dO 6d~ dQ 6ZO i e- dR 6e, dS 6e+ dT 6ZP i dU dV 6dW dX 6dY dZ 6d[ d\ 6d] d^ 6d_ d` 6da db 6ZQ d e? f dc     YZR d eR f dd     YZS de   ZT df   ZU dg   ZV dh   ZW di   ZX dj   ZY dk   ZZ dl   Z[ i e[ dm 6eT dn 6eX do 6eY dp 6eV dq 6eW dr 6eZ ds 6Z\ e[ Z] d dt  Z^ du   Z_ dv   Z` e  ja d eb d dw  Zc d e? f dx     YZd d S(   s)  
WebLogo (http://code.google.com/p/weblogo/) is a tool for creating sequence 
logos from biological sequence alignments.  It can be run on the command line,
as a standalone webserver, as a CGI webapp, or as a python library.

The main WebLogo webserver is located at http://weblogo.threeplusone.com

Please consult the manual for installation instructions and more information:
(Also located in the weblogolib/htdocs subdirectory.)

    http://weblogo.threeplusone.com/manual.html

For help on the command line interface run
    ./weblogo --help

To build a simple logo run
    ./weblogo  < cap.fa > logo0.eps
    
To run as a standalone webserver at localhost:8080 
    ./weblogo --serve

To create a logo in python code:
    >>> from weblogolib import *
    >>> fin = open('cap.fa')
    >>> seqs = read_seq_data(fin) 
    >>> data = LogoData.from_seqs(seqs)
    >>> options = LogoOptions()
    >>> options.title = "A Logo Title"
    >>> format = LogoFormat(data, options)
    >>> eps = eps_formatter( data, format)
   


-- Distribution and Modification --
This package is distributed under the new BSD Open Source License. 
Please see the LICENSE.txt file for details on copyright and licensing.
The WebLogo source code can be downloaded from 
http://code.google.com/p/weblogo/

WebLogo requires Python 2.5, 2.6 or 2.7, and the python
array package 'numpy' (http://www.scipy.org/Download)

Generating logos in PDF or bitmap graphics formats require that the ghostscript
program 'gs' be installed. Scalable Vector Graphics (SVG) format also requires 
the program 'pdf2svg'.

i    (   t   absolute_importt   divisiont   print_functionN(   t   datetime(   t   logt   sqrtt   exp(   t   Template(   t   *(	   t   arrayt   asarrayt   float64t   onest   zerost   int32t   allt   anyt   shapei   (   t	   Dirichlet(   t   seq_io(   t   amino_acid_compositiont   amino_acid_letterst   dna_letterst   rna_letters(   t   Alphabett   Seqt   SeqListt   unambiguous_dna_alphabett   unambiguous_rna_alphabett   unambiguous_protein_alphabet(   t   isfloatt   find_commandt   ArgumentErrort   stdreprt   resource_stringt   resource_filename(   t   StringIOt   LogoOptionst   descriptiont   __version__t
   LogoFormatt   LogoDatat   GhostscriptAPIt   std_color_schemest   default_color_schemest   classict	   std_unitst	   std_sizest   std_alphabetst   std_percentCGt   pdf_formattert   jpeg_formattert   png_formattert   png_print_formattert   txt_formattert   eps_formattert
   formatterst   default_formattert   base_distributiont   equiprobable_distributiont   read_seq_datat   colort   colorschemet   logomaths:   Create sequence logos from biological sequence alignments.s5   $Date: 2014-06-02 22:07:02 -0700 (Mon, 02 Jun 2014) $s   $Revision: 206 $s   WebLogo %s (%s)c         C` s    d d  l  } | j j |   d  S(   Ni    (   t   weblogolib._cgit   _cgit   main(   t   htdocs_directoryt
   weblogolib(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   cgi   s    c           B` s5   e  Z d  Z d Z d	 d  Z d   Z d d  Z RS(
   s8   Interface to the command line program Ghostscript ('gs')t   pngt   pdft   jpegc         C` sm   y t  d d | } WnG t k
 r_ y t  d d | } Wq` t k
 r[ t d   q` Xn X| |  _ d  S(   Nt   gst   paths   gswin32c.exesr   Could not find Ghostscript on path. There should be either a gs executable or a gswin32c.exe on your system's path(   R   t   EnvironmentErrort   command(   t   selfRJ   RL   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   __init__   s    c         C` sa   |  j  d g } y( t | d t } | j   \ } } Wn t k
 rV t d   n X| j   S(   Ns	   --versiont   stdouts$   Cannot communicate with ghostscript.(   RL   t   Popent   PIPEt   communicatet   OSErrort   RuntimeErrort   strip(   RM   t   argst   pt   outt   err(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   version   s    i,  c      
   C` s  i d d 6d d 6d d 6} y | | } Wn t  k
 rH t d   n X|  j d | d d	 d
 d d t |  d t |  d d g
 } | d k r | j d t |   | d k  r | j d  | j d  | j d  q n  | j d  d d j |  }	 y= t | d t d t d t }
 |
 j | j	    \ } } Wn t
 k
 r`t |	   n X|
 j d k r|	 d |
 j 7}	 | d  k	 r|	 | 7}	 n  t |	   n  | S(   Nt   png16mRF   t   pdfwriteRG   RH   s   Unsupported format.s   -sDEVICE=%ss   -dPDFSETTINGS=/printers   -sstdout=%stderrs.   -dColorConversionStrategy=/LeaveColorUnchangeds   -sOutputFile=-s   -dDEVICEWIDTHPOINTS=%ss   -dDEVICEHEIGHTPOINTS=%ss   -dSAFERs	   -dNOPAUSEs   -r%si,  s   -dGraphicsAlphaBits=4s   -dTextAlphaBits=4s   -dAlignToPixels=0t   -sM   Unrecoverable error : Ghostscript conversion failed (Invalid postscript?). %st    t   stdinRO   t   stderri    s   
Return code: %i
(   t   KeyErrort
   ValueErrorRL   t   strt   appendt   joinRP   RQ   RR   t   encodeRS   RT   t
   returncodet   None(   RM   t   formatt
   postscriptt   widtht   heightt
   resolutiont
   device_mapt   deviceRV   t	   error_msgRW   RX   RY   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   convert   sF    	 (   s   pngs   pdfs   jpegN(   t   __name__t
   __module__t   __doc__t   formatsRh   RN   RZ   Rq   (    (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR*      s
   		t   Gt   oranget   TUt   redt   Ct   bluet   At   greent   autot
   monochromes   base pairingt   hydrophobicityt	   chemistryt   chargeg      ?i   t   bitst   natsi
   t   digitst   kTgWy @gfffffr@g     @@s   kJ/molgn?s   kcal/molt   probabilityg@t   smallt   mediumi   t   larget   proteint   rnat   dnag      D@s
   H. sapiensg     @I@s   E. colig      C@s   S. cerevisiaeg      B@s
   C. elegansg     E@s   D. melanogasterg      E@s   M. musculusgYQ@s   T. thermophilusc           B` s)   e  Z d  Z d   Z d   Z d   Z RS(   sz
   A container for all logo formatting options. Not all of these
    are directly accessible through the CLI or web interfaces. 
    
    To display LogoOption defaults:
    >>> from weblogolib import *
    >>> LogoOptions()
    
    All physical lengths are measured in points. (72 points per inch, 28.3 points per cm)
      
    String attributes:
        o creator_text      -- Embedded as comment in figures.
        o logo_title             
        o logo_label
        o unit_name         -- See std_units for options. (Default 'bits') 
        o yaxis_label       -- Defaults to unit_name      
        o xaxis_label
        o fineprint         -- Defaults to WebLogo name and version
        
    Boolean attributes:
        o show_yaxis 
        o show_xaxis         
        o show_ends 
        o show_fineprint        
        o show_errorbars    -- Draw errorbars (default: False)
        o show_boxes        -- Draw boxes around stack characters (default: True)
        o debug             -- Draw extra graphics debugging information. 
        o rotate_numbers    -- Draw xaxis numbers with vertical orientation? 
        o scale_width       -- boolean, scale width of characters proportional to ungaps
        o pad_right         -- Make a single line logo the same width as multiline logos (default: False)                           
                                
    Other attributes:
        o stacks_per_line
        
        o yaxis_tic_interval 
        o yaxis_minor_tic_ratio 
        o yaxis_scale
        o xaxis_tic_interval 
        o number_interval

        o shrink_fraction       -- Proportional shrinkage of characters if show_boxes is true.

        o errorbar_fraction 
        o errorbar_width_fraction 
        o errorbar_gray 

        o resolution             -- Dots per inch (default: 96). Used for bitmapped output formats
        
        o default_color 
        o color_scheme 
        
        o stack_width           --
        o stack_aspect_ratio    -- Ratio of stack height to width (default: 5)

        o logo_margin           -- Default: 2 pts
        o stroke_width          -- Default: 0.5 pts
        o tic_length            -- Default: 5 pts
        o stack_margin          -- Default: 0.5 pts
        
        o small_fontsize        -- Small text font size in points
        o fontsize              -- Regular text font size in points
        o title_fontsize        -- Title text font size in points
        o number_fontsize       -- Font size for axis-numbers, in points.
        
        o text_font
        o logo_font
        o title_font
        
        o first_index
        o logo_start
        o logo_end

    c         K` s  d |  _ t |  _ d |  _ d |  _ d |  _ d |  _ t |  _	 d |  _
 d |  _ d |  _ d |  _ t |  _ d |  _ d |  _ t |  _ d |  _ t |  _ d |  _ t |  _ d t |  _ t |  _ d |  _ t |  _ d	 |  _ d
 |  _ d |  _ d |  _ t  j! d  |  _" d |  _# t |  _$ d |  _% d |  _& d |  _' t( d |  _) d |  _* d |  _+ t |  _, d |  _- d |  _. d |  _/ d |  _0 d |  _1 d |  _2 d |  _3 d |  _4 d |  _5 d |  _6 t |  _7 t |  _8 d d l9 m: } | |  |  d S(   s    Create a new LogoOptions instance.
        
        >>> L = LogoOptions(logo_title = "Some Title String")
        >>> L.show_yaxis = False
        >>> repr(L)
        t    i(   R   g      ?i   i   s   WebLogo g      ?g?g      ?g      ?g      X@t   blacki   R   i   i
   i   i   t   ArialMTs   Arial-BoldMTi    (   t   updateN(;   Rh   t   alphabett   release_descriptiont   creator_textt
   logo_titlet
   logo_labelt   stacks_per_linet	   unit_namet   Truet
   show_yaxist   yaxis_labelt   yaxis_tic_intervalt   yaxis_minor_tic_ratiot   yaxis_scalet
   show_xaxist   xaxis_labelt   xaxis_tic_intervalt   Falset   rotate_numberst   number_intervalt	   show_endst   annotatet   show_fineprintR'   t	   fineprintt
   show_boxest   shrink_fractiont   show_errorbarst   errorbar_fractiont   errorbar_width_fractiont   errorbar_grayRm   t   Colort   by_namet   default_colort   color_schemet   debugt   logo_margint   stroke_widtht
   tic_lengthR/   t   stack_widtht   stack_aspect_ratiot   stack_margint	   pad_rightt   small_fontsizet   fontsizet   title_fontsizet   number_fontsizet	   text_fontt	   logo_fontt
   title_fontt   first_indext
   logo_startt   logo_endt   scale_widtht   reverse_stackst   corebio.utilsR   (   RM   t   kwargsR   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyRN     sf    																																														c         C` s   d d l  m } | |   S(   Ni    (   R!   (   t   corebio.utilR!   (   RM   R!   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   __repr__  s    c         C` s/   t  t |   j    } | j   t |  |  S(   N(   t   listt   varst   keyst   sortR!   (   RM   t
   attributes(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR     s    
(   Rr   Rs   Rt   RN   R   (    (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR%   G  s   H	R	c           B` s   e  Z d  Z d d  Z RS(   s3   Specifies the format of the logo. Requires LogoData and LogoOptions 
    objects.
    
    >>> data = LogoData.from_seqs(seqs )
    >>> options = LogoOptions()
    >>> options.title = "A Logo Title"
    >>> format = LogoFormat(data, options) 
    
    Raises an ArgumentError if arguments are invalid.
    c   
      C` sI  t  j |   | dF k	 r/ |  j j | j  n  | j |  _ | j |  _ t |  _	 t |  _
 dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ dF |  _ |  j |  j |  _ d d   d f d d   d f d d   d	 f d
 d   d f d d   d f d d   d f d d   d f d d   d f d d   d f d d   d f d d   d f d  d!   d" f d# d$   d% f d& d'   d( f d) d*   d+ f d, d-   d. f f } xE | D]= } | d/ t |  | d0   st | d1 | d0   qqW|  j dF k rO|  j  |  _ n  |  j! dF k rx|  j |  j  d/ |  _! n  |  j! |  j d/ |  _" |  j |  j  d0 k  rt d2 d3   n  |  j! |  j  |  j k rt d4 d3   n  |  j# rt$ |  _	 n  |  j% st |  _& n  |  j' r!t$ |  _
 n  |  j( dF k r?|  j) |  _( n  |  j( rTt$ |  _* n t |  _* t |  _+ |  j, st- |  j) } | rt. t/ |  j   | |  _, qd5 |  _, n  |  j, d6 k rt d7 d8   n  |  j0 |  j, k r|  j0 d9 _0 n  t1 |  j0  |  j2 |  _ |  j3 dF k rH|  j t4 k r<t4 |  j |  _3 qHt5 |  _3 n  d/ |  j" d/ |  j6 |  _ |  j d/ k r|  j7 rt8 |  j6 |  j"  |  _6 n  |  j d1 |  j9 |  _ |  j: r|  j; d: |  _ n	 d0 |  _ |  j+ r|  j; d; |  _ n |  j; |  _ |  j< r3|  j= r |  j> d< |  _ q<|  j> d; |  _ n	 d= |  _ d= |  _ |  j	 r]|  j? |  _ n	 d0 |  _ d6 |  _ |  j
 r|  j |  j; 7_ n  |  j& r|  j |  j@ 7_ n  |  j |  j |  j |  _ |  j |  j6 |  j |  j |  _ tA d1 |  jB |  j |  j |  j |  j  |  _ tA d1 |  jB |  j  |  _ tC jD   jE d>  |  _ d? } i d@ tF 6d? tG 6dA tH 6} |  j+ r|  j | k r| |  j } n  | |  _ |  jI dF k rg  |  _I xa tJ |  j  D]M } | |  j  }	 |	 |  jK d0 k r|  jI jL dB |	  q|  jI jL dC  qWn  t/ |  jI  |  j k rEt dD dE   n  dF S(G   s4    Create a new LogoFormat instance.
        
        R   c         S` s
   |  d k S(   Ni    (    (   t   x(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   <lambda>   s    s!   Stacks per line must be positive.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   !  s    s&   Stack width must be greater than zero.R   c         S` s
   |  d k S(   Ni    (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   "  s    s-   Stack aspect ratio must be greater than zero.R   c         S` s
   |  d k S(   Ni    (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   #  s    s   Font sizes must be positive.R   c         S` s
   |  d k S(   Ni    (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   $  s    R   c         S` s
   |  d k S(   Ni    (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   %  s    R   c         S` s   |  d k o |  d k S(   Ng        g      ?(    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   &  s    sC   The visible fraction of the error bar must be between zero and one.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   (  s    s*   The yaxis tic interval cannot be negative.t   yaxis_minor_tic_intervalc         S` s   |  o |  d k  S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   )  s    s   Distances cannot be negative.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   *  s    s'   Tic interval must be greater than zero.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   +  s    s!   Invalid interval between numbers.R   c         S` s   |  d k o |  d k S(   Ng        g      ?(    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   ,  s    s   Invalid shrink fraction.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   -  s    s   Invalid stack margin.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   .  s    s   Invalid logo margin.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   /  s    s   Invalid stroke width.R   c         S` s
   |  d k S(   Ng        (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   0  s    s   Invalid tic length.i   i    i   s6   Logo range extends before start of available sequence.t
   logo_ranges4   Logo range extends beyond end of available sequence.g      ?g        s   Invalid yaxis scaleR   g       @g      @g      ?g      @i   R^   R]   RW   t   ds   %dR   s-   Annotations must be same length as sequences.R   N(M   R%   RN   Rh   t   __dict__R   R   t   lengtht   seqlenR   t
   show_titlet   show_xaxis_labelR   t   lines_per_logot
   char_widtht   line_margin_leftt   line_margin_rightt   line_margin_bottomt   line_margin_topt   title_heightt   xaxis_label_heightt   line_heightt
   line_widtht   logo_heightt
   logo_widtht   creation_datet   end_typeR   R   t   stack_heightt   getattrR    R   R   R   t   total_stacksR   R   R   R   R   R   R   t   show_yaxis_labelR   R   R.   R   t   lenR   t   floatR   R   R,   R   R   R   t   minR   R   R   R   R   R   R   R   t   intR   R   t   nowt	   isoformatR   R   R   R   t   rangeR   Rd   (
   RM   t   datat   optionst   arg_conditionst   testt   conversion_factorR   t	   end_typest   it   index(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyRN     s   																		  	 	 	 																!/
		N(   Rr   Rs   Rt   Rh   RN   (    (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR(     s   
c         C` s:   t  |  |  j   } t   } | j d | | j | j  S(   s    Generate a logo in PDF format.RG   (   R7   t   decodeR*   Rq   R   R   (   R   Ri   t   epsRI   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR2     s    	c         C` s@   t  |  |  j   } t   } | j | | | j | j | j  S(   N(   R7   R   R*   Rq   R   R   Rm   (   R   Ri   Ro   R   RI   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   _bitmap_formatter  s    	c         C` s   t  |  | d d S(   s     Generate a logo in JPEG format.Ro   RH   (   R   (   R   Ri   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR3     s    c         C` s9  t  |  |  } y t d  } Wn t k
 r> t d   n Xd d l } | j d d  \ } } | j d d  \ } } z t | d  }	 t j d d	 k r |	 j j	 |  n |	 j	 |  |	 j
 d  | | | g }
 t |
  } | j   \ } } t |  } | j   j   SWd t j |  t j |  Xd S(
   sp    Generate a logo in Scalable Vector Graphics (SVG) format.
    Requires the program 'pdf2svg' be installed.
    t   pdf2svgsk   Scalable Vector Graphics (SVG) format requires the program 'pdf2svg'. Cannot find 'pdf2svg' on search path.i    Nt   suffixs   .pdfs   .svgt   wi   (   R2   R   RK   t   tempfilet   mkstempt   opent   syst   version_infot   buffert   writet   seekRP   RR   t   readRf   t   ost   remove(   R   Ri   RG   RL   R  t   fpdfit	   fname_pdft   fsvgit	   fname_svgt   fpdf2RV   RW   RX   RY   t   fsvg(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   svg_formatter  s*    c         C` s   t  |  | d d S(   s    Generate a logo in PNG format.Ro   RF   (   R   (   R   Ri   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR4     s    c         C` s   d | _  t |  | d d S(   sG    Generate a logo in PNG format with print quality (600 DPI) resolution.iX  Ro   RF   (   Rm   R   (   R   Ri   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR5     s    	c         C` s   t  |   j   S(   s5    Create a text representation of the logo data. 
    (   Rc   Rf   (   t   logodataRi   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR6     s    c      5   C` sz  i  } d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 g5 } x! | D] } t  | |  | | <q Wt | j  j   | d6 <d7   } | | j  | d8 <g  } xP | j j D]B } | | j  } x* | j D] } | j	 d9 | d: |  q6WqWd; j
 |  | d< <g  }	 t | j }
 |	 j	 d=  | j | j } | j | j d> } xlt | |  D][} | | j } | | } | d? k r7| | j d? k r7|	 j	 d@  |	 j	 dA  |	 j	 d=  |	 j	 d@  n  |	 j	 dB | j |  |
 rp|  j | t | j } n dC } t t |  j | |  j   } | j dD dE    | j   | j dD dF    | j s| j   n  t t |  j |   } | dG k r]dC } | j r|  j | } n  x; | D]0 } |	 j	 dH | | d? | | | d> f  q&Wn  |  j dM k	 r|
 r| dG k r|  j | \ } } |  j | } | |
 9} | |
 9} | |
 9} | | j! k r| j! } n  | | } | | } |	 j	 dI | | f  n  |	 j	 dJ  |	 j	 d@  qW|	 j	 dA  d; j
 |	  | dK <t" t# dL t$  j%   } t& |  j' |  } | j(   S(N   s1    Generate a logo in Encapsulated Postscript (EPS)R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   shrinkc         S` s7   d j  d t |  j  t |  j  t |  j  d f  S(   NR^   t   [t   ](   Re   Rc   Ry   R}   R{   (   R=   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   format_color4  s    !R   s     (s   ) s   
t
   color_dictt	   StartLinei   i    R   t   EndLines   (%s) StartStackg      ?t   keyc         S` s   |  d S(   Ni   (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   c  s    c         S` s   |  d S(   Ni    (    (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR   e  s    g        s    %f %f (%s) ShowSymbols    %f %f DrawErrorbart   EndStackt	   logo_datas   template.epsN()   R   Rc   R   t   lowerR   R   t   groupsR=   t   symbolsRd   Re   R.   R   R   R   R   R   R   R   t   entropyR   t   zipt   countsR   R   t   reverseR   R   t   sumR   t   weightt   entropy_intervalRh   R   R"   Rr   t   __file__R   R   t
   substituteRf   (   R  Ri   t   substitutionst   from_formatt   sR  t   colorst   groupt   cfR   t   conv_factort   seq_fromt   seq_tot	   seq_indext
   logo_indext   stack_indexR   Rz   t   fraction_widtht   ct   lowt   hight   centert   downt   upt   templatet   logo(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR7     s    																	!

	 	1!


 

R   RG   RF   t	   png_printRH   t   svgR  c   
      C` s*  |  d k r d S|  j   } | j   d k r2 d S| d k re | d k	 re t t t |    } n  | d k  r t d   n  | j   d k r | t t |   } nT| j   d k s | j   d k r
| t k r | t	 t
 t  } q| t t |   } n| t k r-| t t |  } n| d d k rZ| t t | d    } nt |  r| t t |  d	  } n||  d d
 k r|  d d k r|  d d !} | j d d  j d d  j d d  j d d  j   } t |  t |  d k rt d   n  t t |  t  } yd x] t t |  d  D]E } | | d } | j |  } t | | d d  }	 |	 | | <qGWWn t k
 rt d   n Xt | d k  rt d   n  | t |  } | | 9} n t d |    t |  t |  k r&t d   n  | S(   s   Parse a description of the expected monomer distribution of a sequence.
    
    Valid compositions:
    
    - None or 'none' :      No composition sepecified 
    - 'auto' or 'automatic': Use the typical average distribution
                            for proteins and an equiprobable distribution for
                            everything else.    
    - 'equiprobable' :      All monomers have the same probability.
    - a percentage, e.g. '45%' or a fraction '0.45':
                            The fraction of CG bases for nucleotide alphabets
    - a species name, e.g. 'E. coli', 'H. sapiens' :
                            Use the average CG percentage for the specie's      
                            genome.
    - An explicit distribution,  e.g. {'A':10, 'C':40, 'G':40, 'T':10}
    t   nonei    s   Weight cannot be negative.t   equiprobableR~   t	   automaticit   %g      Y@t   {t   }i   t   ,R^   t   't   "t   :i   s0   Explicit prior does not match length of alphabets!   Cannot parse explicit compositiong      s&   Explicit prior does not match alphabets$   Unknown or malformed composition: %ss7   The sequence alphabet and composition are incompatible.N(   Rh   RU   R  R   R   R   Rb   R;   R   R
   t   aa_compositionR   R1   R:   R   t   replacet   splitR   R   t   ordR   R%  (
   t   compositionR   R&  t   compt   priort   explicitt   rt   letterR   t   value(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   parse_prior  sX       $ <c         C` sY   d |  d d } |  d d } |  d d } d |  d d } t  | | | | f t  S(   Ng      ?g      Y@g       @id   (   R
   R   (   t	   percentCGR|   Rz   Rv   t   T(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR:     s
    c         C` s   t  |  t  |  S(   N(   R   R   (   R   (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR;     s    c   
      C` sA  t  t j j d |   } | d k rs |  j |  } |  j d  } | d k rd t d |   n  t |  }  n$ |  t j k r t |  j    }  n  |  j	 d  | |   } | d k s t |  d k r t d   n  | rx- t |  D] \ } }	 |	 j   | | <q Wn  | r+t |  | _ n t j |  | _ | S(   s    Read sequence data from the input stream and return a seqs object. 
    
    The environment variable WEBLOGO_MAX_FILE_SIZE overides the max_file_size argument.
    Used to limit the load on the WebLogo webserver.
    t   WEBLOGO_MAX_FILE_SIZEi    i   R   s+   File exceeds maximum allowed size: %d bytess,   Please provide a multiple sequence alignmentN(   R   R
  t   environt   getR	  t   IOErrorR$   R  R_   R  Rh   R   Rb   t	   enumeratet   maskR   R   t   which(
   t   fint   input_parserR   t   ignore_lower_caset   max_file_sizeR   t	   more_datat   seqsR   R,  (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR<     s(    c           B` sV   e  Z d  Z d d d d d d d  Z e d d   Z e d d   Z d   Z RS(   s   The data needed to generate a sequence logo.
       
    - alphabet 
    - length
    - counts  -- An array of character counts
    - entropy -- The relative entropy of each column
    - entropy_interval -- entropy confidence interval
     c         C` s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   s   Creates a new LogoData objectN(   R   R   R#  R!  R'  R&  (   RM   R   R   R#  R!  R'  R&  (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyRN   1  s    					c         C` s  | j  \ } } | d k	 r- t | t  } n  | d k sK t |  d k r t |  } t | t  } d } xt d |  D]G }	 t | |	  }
 |
 d k r d | |	 <q| | t | |	  | |	 <q| Wn t | t  } t | d f t  } t |  } x t d |  D]~ }	 t | |	 t  } | | 7} t	 |  } | j
 | t |   | |	 <| j | t |  d  \ | |	 d <| |	 d <q
Wt t j | d d t  } t |  } | d k rt d   n  | | } |  | | | | | |  S(	   s$   Build a LogoData object from counts.g        i    i   gffffff?i   t   axiss
   No counts.N(   R   Rh   R	   R   R%  R   R   R   R!  R   t   mean_relative_entropyt   interval_relative_entropyt   naR   t   maxRb   (   t   clsR   R#  RQ  t
   seq_lengthR|   t   Rt   entR'  R   Rz   t   alphat	   posteriorR&  t
   max_weight(    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   from_counts<  s6     
6 
c         C` s   t  |  d k s( t  | d  d k r7 t d   n  t  | d  } xF t |  D]8 \ } } | t  |  k rT t d | d d   qT qT W| j   } |  j | j | |  S(   s<   Build a LogoData object from a SeqList, a list of sequences.i    s   No sequence data found.s@   Sequence number %d differs in length from the previous sequencesi   t	   sequences(   R   Rb   R]  R    t   profileRr  R   (   Rk  Re  RQ  Rl  R   R,  R#  (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt	   from_seqsh  s    (c         C` s  t    } t d d | t d d | t d d | t d d | t d d | t d d | t d d | t d	 d
 d d | x' |  j D] } t | d
 d d | q Wt d d | x8t |  j  D]'} t | d d
 d d | x+ |  j | D] } t | d
 d d | qWt d |  j | d
 d d | |  j d  k	 rt d |  j | d d
 d d | t d |  j | d d
 d d | n t d d d
 d d | |  j	 d  k	 rt d |  j	 | d
 d d | n  t d d | q Wt d d | | j
   S(   Ns   ## LogoDatat   files5   # First column is position number, counting from zeros*   # Subsequent columns are raw symbol countss+   # Entropy is mean entropy measured in nats.s-   # Low and High are the 95% confidence limits.s:   # Weight is the fraction of non-gap symbols in the column.s   #	t   #t   ends   	s    	s   Entropy	Low	High	Weighti   s   %6.4fi    R   s   # End LogoData(   R$   t   printR   R   R   R#  R!  R'  Rh   R&  t   getvalue(   RM   RX   t   aR   R7  (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   __str__  s8    	!
$N(	   Rr   Rs   Rt   Rh   RN   t   classmethodRr  Ru  R|  (    (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyR)   '  s   	
+gkn]@go@gStd@gФH#?g%@g4333330@(e   Rt   t
   __future__R    R   R   R  t   copyR
  R   t   mathR   R   R   t   stringR   t
   subprocesst   numpyR	   R
   R   R   R   R   R   R   R   Ri  R=   R>   R?   R   t   corebioR   t   corebio.dataR   R   R   R   t   corebio.morematht   corebio.seqR   R   R   R   R   R   R   R   R   R    R!   R"   R#   t   corebio._py3kR$   t   __all__R&   R'   RM  t   release_datet   release_buildR   RE   t   objectR*   t   _kRK  t   ColorSchemet
   ColorGroupR-   Rh   R   t   base_pairingR   R   R   R+   R,   R.   R/   R0   R1   R%   R(   R2   R   R3   R  R4   R5   R6   R7   R8   R9   RV  R:   R;   R	  R   R<   R)   (    (    (    s=   /home/psgendb/BIRCHDEV/pkg/weblogo-3.4/weblogolib/__init__.pyt   <module>Y   s   
@

"
..			T






				%				
N		(