
jxec           @  sl  d  d l  m Z d  d l Z e j j d  d  d l Z d  d l Z d  d l Z	 d  d l
 j Z d a d a d d  d d d g Z e e g Z d   Z d g  g  d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( e) d k rhe(   n  d S(   i(   t   print_functionNs   ../../i    t   Truet   xi   c         O  sQ   t  t } t d | d d |  | |   } | j rC t  d 7a  n
 t d 7a d S(   s#  
    Run a function with the specified parameters and register whether
    success or failure was a mistake

    parameters
    ----------

    func: (function or class constructor)
        An executable function to which *args and **kwargs are passed.

    return
    ------

    None.
    s   Test # %d: t   endt    i   N(   t   global_fail_countert   global_success_countert   printt   mistake(   t   funct   argst   kwt   test_numt   obj(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_for_mistake   s    
	c         K  s   | d k	 r t d |  j | f  x. | D]& } | | | <t d |  d t |  q* Wx. | D]& } | | | <t d |  d t |  q[ Wt d t t f  n' t d |  j  t d |  d t |  t j	 d  d S(   s  
    Tests predictable success & failure of different values for a
    specified parameter when passed to a specified function

    parameters
    ----------

    func: (function)
        Executable to test. Can be function or class constructor.

    var_name: (str)
        Name of variable to test. If not specified, function is
        tested for success in the absence of any passed parameters.

    fail_list: (list)
        List of values for specified variable that should fail

    success_list: (list)
        List of values for specified variable that should succeed

    **kwargs:
        Other keyword variables to pass onto func.

    return
    ------

    None.

    s   Testing %s() parameter %s ...R	   t   should_fails$   Tests passed: %d. Tests failed: %d.
s    Testing %s() without parameters.t   allN(
   t   NoneR   t   __name__R   R   t   FalseR   R   t   pltt   close(   R	   t   var_namet	   fail_listt   success_listt   kwargsR   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_parameter_values6   s    %

c          C  s  t  j d d t }  t  j d d t } t j t j j d d d d7 d	 t d
  } d } t	 d t  j
 d d d t | g d |  | g  t	 d t  j
 d d d d d d g d d d d d g d |   t	 d t  j
 d d d t d  |  g d d d d g d |   t	 d t  j
 d d d d d d  g d d d d  g d |   t	 d t  j
 d d! d d d d  g d t t g d |   t	 d t  j
 d d" d d d# d  g d d d$ d g d |   t	 d t  j
 d d% d d d# d  g d t t g d |   t	 d t  j
 d d& d d d# d' d  g d d d d$ d( d) g d |   t	 d t  j
 d d* d d d# d' d  g d d d d$ d( d) g d |   t	 d t  j
 d d+ d d d# d' d  g d t t g d |  t	 d t  j
 d d, d d d# d  g d d d d- d g d |   t	 d t  j
 d d. d d d# g d d  t t g d |   t	 d t  j
 d d/ d d g d d d( d g d |   t	 d t  j
 d d0 d d d# d1 d1 g d1 g d d g d d2 g d8 g d d9 d5 d5 g g d |   t j d0 d d g  \ } } t	 d t  j
 d d6 d d d( t g d | d  g d |   d  S(:   Nt   crp_energy_matrixt   print_descriptiont   ss_probability_matrixi    i   t   sizei
   i   t   columnst   ACGTR   R	   R   t   dfR   R   t   color_schemet   bad_color_namet   classict   grayst   charget   salmont	   font_names   DejaVu Sanss   Arial Rounded MT Bolds   Times New Romant   stack_orders   incorrect argumentg        t   small_on_topt
   big_on_topt   fixedt   center_valuest   baseline_widthgg      ?t
   flip_belowt   shade_belowgffffff?i   g      ?t
   fade_belowt   fade_probabilitiest   vsepg333333?t   show_spinest   zordert   figsizeit   yi   g      @i   t   ax(   i
   i   (   i   i   i   (   i
   g      @(   t	   logomakert   get_example_matrixR   t   pdt	   DataFramet   npt   randomt   randintt   listR   t   Logot   bool_fail_listR   R   R   t   subplots(   t   good_crp_dft   good_prob_dft	   random_dft   bad_df1t   _t   temp_ax(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt	   test_Logoz   s\    0!$$$$$$	0c          C  sV   t  j d d t }  t d t  j |   j d d d d d t g d	 d
 d d g  d  S(   NR   R   R	   R   R"   R   t   bad_color_schemei   R   R$   t   grayR'   (   R9   R:   R   R   RA   t   style_glyphsR   (   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_style_glyphs   s    c          C  s   t  j d d t }  t d t  j |   j d d d d d d	 d
 d t g d d d d d g  t d t  j |   j d d d d d d g d d d d
 g  d  S(   NR   R   R	   R   t   v_alpha0R   ig?i   g      ?t   xxxR   i    g        g+?g      ?t   v_alpha1(   R9   R:   R   R   RA   t   fade_glyphs_in_probability_logoR   (   RE   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt)   test_Logo_fade_glyphs_in_probability_logo   s
    +c          C  se  t  j d d t }  t d t  j |   j d d d d d t d d d	 g g d
 d d d d g d d d g d d d g d  g  t d t  j |   j d d d d	 d d g d
 d d d g  t d t  j |   j d d d d	 d d g d
 d d d g  t d t  j |   j d d d d	 d d g d
 d d d g  t d t  j |   j d d d t d
 t	  d  S(   NR   R   R	   R   t   colorR   i    RP   iR   t   redi   g?g?g333333?t   alphaR   g?g      ?t   shadet   fadet   flip(
   R9   R:   R   R   RA   t   style_glyphs_belowR   R   RB   t   bool_success_list(   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_style_glyphs_below   s    Lc          C  s   t  j d d t }  t d t  j |   j d d d d d d	 d
 g d d d d g d d  t d t  j |   j d d d d d d	 g d d d d d g d d  d  S(   NR   R   R	   R   t   pR   iR   g?i'  R   i    i   i
   t   ct   At   Ct   Gt   T(   R9   R:   R   R   RA   t   style_single_glyph(   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_style_single_glyph  s
    (c       
   C  s   t  j d d t }  t j j d d d d g d d d	 d
 d
 d
 d
 g } d j |  } t j j d d d d g d d d	 d
 d
 d
 d
 g } d j |  } t d t  j |   j	 d d d d d d | g d | g  d  S(   NR   R   R_   R`   Ra   Rb   R   i   R]   g      ?R   i
   R	   R   t   sequenceR   iR   g?R   (
   R9   R:   R   R=   R>   t   choicet   joinR   RA   t   style_glyphs_in_sequence(   RD   t   test_good_sequencet   test_bad_sequence(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt"   test_Logo_style_glyphs_in_sequence  s    66c          C  sS   t  j d d t }  t d t  j |   j d d d d d g d	 d
 d d g  d  S(   NR   R   R	   R   R]   R   R   g      ?R   i    i   i
   (   R9   R:   R   R   RA   t   highlight_position(   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_highlight_position!  s    c          C  s^  t  j d d t }  t d t  j |   j d d d d d g d	 d
 d d g d d  t d t  j |   j d d d d d g d	 d d d g d d  t d t  j |   j d d d d d g d	 d d
 d g d d d d  t d t  j |   j d d d d d t d g d	 d d d d d g g d d d d  t d t  j |   j d d d d d t d g d	 d  d d d d d g g d d d d  t d t  j |   j d d d d d g d	 d d d  g d d d d  t d t  j |   j d d d d d g d	 d d d  g d d d d  t d t  j |   j d d d d d  g d	 d d d g d d d d  d  S(   NR   R   R	   R   t   pminR   R   i   R   i    i   i
   t   pmaxi   g      @i   i   t   paddingig      RT   t   wrong_colort   pinkRU   t	   edgecolort   floort   ceilingiR5   g      ?(   R9   R:   R   R   RA   t   highlight_position_rangeR   R   (   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt"   test_Logo_highlight_position_range)  s0    ""(73c          C  s   t  j d d t }  t d t  j |   j d d d d d  g d d	 d
 d g  t d t  j |   j d d d d d t d g d d d d d d g g  t d t  j |   j d d d d d	 d d  g d d d d d g  d  S(   NR   R   R	   R   R5   R   R   R   ig      ?i   RT   Rq   Rr   RU   t	   linewidtht   1i    g      ?i   (   R9   R:   R   R   RA   t   draw_baselineR   R   (   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_draw_baselineU  s    +c          C  s  t  j d d t }  t d t  j |   j d d d d d  d d	 g d
 d d d g  t d t  j |   j d d d d d  d d g d
 d d g  t d t  j |   j d d d d  d g d
 d g  t d t  j |   j d d d d  d g d
 d d d d g  d  S(   NR   R   R	   R   t   anchorR   R   g      ?g      ?R   ii   i   t   spacingi    t   fmts   %dt   rotationigffffff?i   (   R9   R:   R   R   RA   t   style_xticksR   (   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_style_xticksf  s    "c          C  se  t  j d d t }  t d t  j |   j d d d d d  d d	 d
 g d d d
 d d d g d d d
 g g  t d t  j |   j d d d t d t  t d t  j |   j d d d d d d d d d g g d d d d d d	 g g  t d t  j |   j d d d d d g d d d d g  t d t  j |   j d d d d d g d d  d d g g  d  S(    NR   R   R	   R   t   spinesR   R   g      ?g      ?t   topR   t   bottomt   leftt   rightt   visibleRT   Rq   i   t   blackt   greeng?Rx   RP   ig        i    i   t   bounds(   R   R   R   R   (   R   R   R   (   R   R   (	   R9   R:   R   R   RA   t   style_spinesR   RB   R[   (   RD   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_Logo_style_spines{  s     4c          C  s5  t  j d d t }  t  j d d t } t d t  j d d d d |  d  g d	 | g d
 d d d  t d t  j d d d g  d	 | g d
 d d d  t d t  j d d d g  d	 | g d
 d d d  t d t  j d d d t d	 t d |  t d t  j d d d t d	 t d |  t d t  j d d
 d d d d  g d	 d g d | d d  t d t  j d d d d d d  g d	 d d d g d | d
 d  t d t  j d d d d d d d d d g g d	 d  d d d d g g d | d
 d d d  t d t  j d d d d  d d g d	 d d d g d | d
 d d d  d  S(   NR   R   t   crp_counts_matrixR	   R   R!   R   R   R   t	   from_typet   countst   to_typet   probabilityt   weightt   informationR-   t   normalize_valuesi   t
   backgroundig      ?t   pseudocounti    i
   (   R9   R:   R   R   t   transform_matrixR   RB   R[   (   t   good_crp_weight_dft   good_crp_counts_df(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_transform_matrix  s:    3c           C  s  t  d t j d d d d  d t g d d d d	 g  t  d t j d d
 d d t g d d  d d d d g g d d  t  d t j d d d d t d g d d  d g d d  t  d t j d d d g  d d g d d  t  d t j d d d g  d d g d d  t  d t j d d d t d t d d  t  d t j d d d d t d g d d d d g d d  t  d t j d d d t d t d d d d  d  S(   NR	   R   t   seqR   i   R   R    s   !@#$R9   t   colsi    R_   R`   Ra   Rb   t   ACGTACGTt   alphabetRP   t   dnat   rnat   ACGUACGUt   proteint   LMWAt   is_iupacR   R   R   R   t   center_weights(   R   R9   t   sequence_to_matrixR   R   RB   R[   (    (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_sequence_to_matrix  s$    +"c          C  s  t  j d d t  }  |  j   } Wd  QXg  | D]* } d | k r1 d | k r1 | j   ^ q1 } t d t  j d d d d	 d
 d d g g d | d d g g  t d t  j d d d d	 d
 d g d d  g d d d g  t d t  j d d d d	 t d g d d d d d g d |  t d t  j d d d d d
 g d d  d d d d g g d |  t d t  j d d d d d t d  g d d d d g d |  t d t  j d d d t	 d t
 d |  t d t  j d d  d d  d
 d g d d	 d d! g d |  d  S("   Ns   crp_sites.faR   t   #t   >R	   R   t	   sequencesR   i    R   t   AACCTt   AACGATAR   t   ACAt   GGAR   iR   RP   R   R   R   R   i   g      ?t   characters_to_ignoreg      ?R_   R`   Ra   R   R   i
   (   R9   t   open_example_datafileR   t	   readlinest   stripR   t   alignment_to_matrixR   R   RB   R[   (   t   ft   raw_seqsR   t   seqs(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_alignment_to_matrix  s,    7(%!$!c          C  sH  t  j d d t " }  t j |  d d d d } Wd  QXt d t  j d d	 d
 d  d d g d | d g d | d  t d t  j d d d
 d  d d g d | d g d	 | d  t d t  j d d d
 d d g d d  d d d d g g d	 | d d | d  t d t  j d d d
 d t d g d d  d g d	 | d d | d  d  S(   Ns   nn_saliency_values.txtR   t   commentR   t   seps   	R	   R   R   R   R   iR   t	   charactert   valuest   valueR   R_   R`   Ra   Rb   R   i    RP   R   (	   R9   R   R   R;   t   read_csvR   t   saliency_to_matrixR   R   (   R   t   saliency_data_df(    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_saliency_to_matrix  s    !$c          C  s  t  j d d d g  \ }  } | j d d g  | j d d g  t d t j d d	 d
 g  d d d d d g d d d | d d d d  t d t j d d d
 d d d  g d d d d g d	 d d | d d d d  t d t j d d d
 d d d  g d d d d g d	 d d | d d d d  t d t j d d d
 d d d  g d d d d g d	 d d | d d d d  t d t j d d d
 d d g d d  | g d	 d d d d d d d  t d t j d d d
 d d g d d d d g d	 d d d d d d d d |  	t d t j d d d
 d d d  d g d d d d g d	 d d d d d d d d |  	t d t j d d d
 d g d d g d	 d d d d d d d d |  	t d t j d d d
 d d g d d d d  g d	 d d d d d d d d |  	t d t j d d! d
 d d g d d" d d d g d d d g d d# d$ g g d	 d d d d d d d d |  	t d t j d d% d
 d d g d d& d d d g d d d g d d# d$ g g d	 d d d d d d d d |  	t d t j d d' d
 d d d  g d d d d g d	 d d d d d d d d |  	t d t j d d( d
 d d  g d d) d g d	 d d d d d d d d |  	t d t j d d* d
 t d t	 d	 d d d d d d d d |  	t d t j d d+ d
 t d t	 d	 d d d d d d d d |  	t d t j d d, d
 d g d d d d d g d	 d d d d d d d d |  	t d t j d d- d
 d. d d g d d/ d d0 g d	 d d d d d d d d |  	t d t j d d d
 d1 d d2 g d4 d d g g d d5 d d g g d	 d d d d d d d d |  	d  S(6   NR6   i   i   i    i   i   R	   R   R]   R   R   i
   g      ?R^   R_   R8   Rt   Ru   g?R`   R   it   widtht   vpadg?R(   s   DejaVu Sanst   font_weightRP   t   boldi   t   normalRT   RU   g?g333333?Rs   R   t	   edgewidtht   dont_stretch_more_thant   ERY   t   mirrorR5   RV   g?g+?g      ?s   incorrect argumentR7   g      @(   i   i   i   (   i
   g      @(
   R   RC   t   set_xlimt   set_ylimR   R9   t   GlyphR   RB   R[   (   t   figR8   (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt
   test_Glyph1  st    !99c           C  s   t  d t j d d d d d g d d d	 g d
 t  t  d t j d d
 d t d t d d  t  d t j d d d d d g d d d g d
 t  t  d t j d d
 d t d t d d  d  S(   NR	   R   t   nameR   s   wrong argumentiR   R   t   ww_counts_matrixR   s   nn_saliency_values.txts   ss_sequences.txt(   R   R9   R:   R   RB   R[   R   (    (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   test_logomaker_get_data_methods  s    c        
   C  sB   t  d t j d d d d t d g d d d	 g  t j d
  d  S(   NR	   R   R   R   i    RP   R   t   crpt   fig1bR   (   R   R9   t   demoR   R   R   (    (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt	   test_demo  s    c           C  s{   t    t   t   t   t   t   t   t   t   t	   t
   t   t   t   t   t   t   d S(   s   
    Run all Logomaker functional tests. There are 547 tests as of 14 May 2019.

    parameters
    ----------
    None.

    return
    ------
    None.
    N(   RJ   RN   RS   R\   Rd   Rk   Rm   Rw   R{   R   R   R   R   R   R   R   R   (    (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt	   run_tests  s"    t   __main__(*   t
   __future__R    t   syst   patht   appendR9   t   numpyR=   t   pandasR;   t   matplotlib.pyplott   pyplotR   R   R   RB   R   R   R[   R   R   R   RJ   RN   RS   R\   Rd   Rk   Rm   Rw   R{   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sO   /tmp/pip-install-l3LICk/logomaker/logomaker/tests/functional_tests_logomaker.pyt   <module>   sF   	#A	T							,				1	#	*		e			&