U
    fz                     @   s&  d dl mZ d dlZejd d dlZd dlZd dlZ	d dl
mZ d ad ad ddddgZdd	gZd
d Zdg g fddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Z d*d+ Z!d,d- Z"d.d/ Z#d0d1 Z$d2d3 Z%e&d4kr"e%  dS )5    )print_functionNz../../Truex   FTc                 O   s>   t t }td| dd | ||}|jr2t d7 a ntd7 adS )a#  
    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.
    zTest # %d:  )endr   N)global_fail_counterglobal_success_counterprintZmistake)funcargskwZtest_numobj r   Q/tmp/pip-target-lpfmz8o1/lib/python/logomaker/tests/functional_tests_logomaker.pytest_for_mistake   s    

r   c                 K   s   |dk	rxt d| j|f  |D ] }|||< tf | dd| q|D ] }|||< tf | dd| qDt dttf  n"t d| j  tf | dd| td dS )	a  
    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.

    NzTesting %s() parameter %s ...T)r   Zshould_failFz$Tests passed: %d. Tests failed: %d.
z Testing %s() without parameters.all)r   __name__r   r
   r	   pltclose)r   var_name	fail_listsuccess_listkwargsr   r   r   r   test_parameter_values6   s    %r   c               
   C   sN  t jddd} t jddd}tjtjjddddtd	d
}d}tt j	dt
|g| |gd tt j	ddddgddddg| d tt j	ddd | gdddg| d tt j	dddd gdddg| d tt j	d ddd gddg| d tt j	d!dd"d gdd#dg| d tt j	d$dd"d gddg| d tt j	d%dd"d&d gddd#d'd(g| d tt j	d)dd"d&d gddd#d'd(g| d tt j	d*dd"d&d gddg|d tt j	d+dd"d gddd,d-g| d tt j	d.dd"gd ddg| d tt j	d/dgdd'dg| d tt j	d0dd"d1d1gd1gddgdd2gd3gd4d5d5gg| d tjddgd6\}}tt j	d7dd'dg|d g| d d S )8Ncrp_energy_matrixFprint_descriptionss_probability_matrixr      )
      )sizeACGT)columnsr   dfr   r   r   r   color_schemeZbad_color_nameclassicZgraysZchargesalmonr   r   r   r   r&   	font_nameTDejaVu SanszArial Rounded MT BoldzTimes New RomanZstack_orderincorrect argument        Zsmall_on_topZ
big_on_topZfixedcenter_valuesZbaseline_widthg      ?Z
flip_belowZshade_belowffffff?r         ?Z
fade_belowZfade_probabilitiesZvsep333333?r!   Zshow_spineszorderfigsizer   yr      r    r!   g      @   r6   ax)	logomakerget_example_matrixpdZ	DataFramenprandomrandintlistr   Logobool_fail_listr   subplots)good_crp_dfgood_prob_dfZ	random_dfZbad_df1_Ztemp_axr   r   r   	test_Logoz   s     
   
 
 
 
   
  rK   c                  C   s6   t jddd} tt | jddddgdd	d
gd d S )Nr   Fr   r(   Zbad_color_schemer   Tr)   grayr*   r'   )r>   r?   r   rE   Zstyle_glyphsrH   r   r   r   test_Logo_style_glyphs   s
    rN   c               	   C   sb   t jddd} tt | jdddddd	d
gddddgd tt | jdddd	gdddgd d S )Nr   Fr   Zv_alpha0r   皙?r   r3   xxxTr   r/   +?r1   r'   Zv_alpha1)r>   r?   r   rE   Zfade_glyphs_in_probability_logo)rI   r   r   r   )test_Logo_fade_glyphs_in_probability_logo   s     
 rR   c               
   C   s   t jddd} tt | jdddddddggd	d
d
d
gdddgdddgd gd tt | jddddgdd
dgd tt | jddddgdd
dgd tt | jddddgdd
dgd tt | jdttd d S )Nr   Fr   colorr   rP   Tr   redr   皙?皙?r4   r'   alphar   rO   r1   Zshadefadeflip)r>   r?   r   rE   Zstyle_glyphs_belowrF   bool_success_listrM   r   r   r   test_Logo_style_glyphs_below   s*         r[   c                  C   sb   t jddd} tt | jdddddgd	d
dgdd tt | jddddgddddgd
d d S )Nr   Fr   pr   r   rO   i'  r   r   r!   A)r   r   r   r   cr^   CGT)r   r   r   r   r\   )r>   r?   r   rE   Zstyle_single_glyphrM   r   r   r   test_Logo_style_single_glyph  s    
   
 rb   c                  C   s   t jddd} tjjddddgdd	d	d	d	gd
}d|}tjjddddgdd	d	d	d	gd
}d|}tt | jdddd|g|gd d S )Nr   Fr   r]   r_   r`   ra            ?)r#   r\   r   r!   sequencer   r   rO   r'   )	r>   r?   rA   rB   choicejoinr   rE   Zstyle_glyphs_in_sequence)rH   Ztest_good_sequenceZtest_bad_sequencer   r   r   "test_Logo_style_glyphs_in_sequence  s    "
"

 rh   c                  C   s4   t jddd} tt | jdddgddd	gd
 d S )Nr   Fr   r\   r         ?r   r   r!   r'   )r>   r?   r   rE   Zhighlight_positionrM   r   r   r   test_Logo_highlight_position!  s
     rj   c               
   C   sT  t jddd} tt | jdddgddd	gd
d tt | jdddgddd	gdd tt | jdddgddd	gdd	d tt | jdddddgdddddggdd	d tt | jdddddgd dddddggdd	d tt | jddd	gddd gdd	d tt | jdddgddd gdd	d tt | jddd gdddgdd	d d S ) Nr   Fr   pminr      r   r   r!      )r   r   r   r   pmaxrn   g      @   r;   )r   r   r   r   rk   paddingr   g      )r   r   r   r   rk   rn   rS   Twrong_colorpinkrT   	edgecolorfloorceilingir5   r1   )r>   r?   r   rE   Zhighlight_position_rangerM   r   r   r   "test_Logo_highlight_position_range)  s^           
   
     rv   c               	   C   s   t jddd} tt | jddd gdddgd	 tt | jd
ddddgdddddggd	 tt | jddddd gddddgd	 d S )Nr   Fr   r5   r   r   r1   r   r'   rS   Trq   rr   rT   	linewidth1r   ri   r9   )r>   r?   r   rE   Zdraw_baselinerM   r   r   r   test_Logo_draw_baselineU  s     
 
 
ry   c                  C   s   t jddd} tt | jddd ddgdd	d
gd tt | jddd ddgd	d
gd tt | jdd dgdgd tt | jdd dgddddgd d S )Nr   Fr   anchorr   r1   r3   r   r   r9   r'   spacingr   fmtz%dZrotationir2      )r>   r?   r   rE   Zstyle_xticksrM   r   r   r   test_Logo_style_xticksf  s"    
 
   
r~   c               	   C   s   t jddd} tt | jddd dddgd	dd
ddgdddggd tt | jdttd tt | jdddddddggdddddggd tt | jdddgdddgd tt | jdddgd ddggd d S )Nr   Fr   Zspinesr   r1   r3   top)r   bottomleftrightr   r   r   )r   r   r   )r   r   r'   visiblerS   rq   r    blackgreeng?rw   rP   r   r/   r   r   Zbounds)r>   r?   r   rE   Zstyle_spinesrF   rZ   rM   r   r   r   test_Logo_style_spines{  s4    
	    
r   c               	   C   s,  t jddd} t jddd}tt jdd| d g|gddd	 tt jdg |gdd
d	 tt jdg |gddd	 tt jdtt|d tt jdtt|d tt jdddd gdg|dd tt jdddd gdd
dg|dd tt jdddddddggd ddddgg|ddd tt jdd ddgdddg|ddd d S )Nr   Fr   Zcrp_counts_matrixr&   r   countsprobability)r   r   r   r   	from_typeto_typeweightinformationr0   r+   Znormalize_valuesr   r   )r   r   r   r   r&   r   r   )r   r   r   r   r&   r   
backgroundr   rd   )r   r   r   r   r&   r   r   pseudocountr   r!   )r>   r?   r   Ztransform_matrixrF   rZ   )Zgood_crp_weight_dfZgood_crp_counts_dfr   r   r   test_transform_matrix  sp                      r   c                	   C   s   t tjdd ddgdddgd t tjdd	dgd d
dddggdd t tjdd	ddgd dgdd t tjdg dgdd t tjdg dgdd t tjdttdd t tjdd	ddgdddgdd t tjdttddd d S )Nseqr    Tr$   z!@#$r>   r'   colsr   r]   r_   r`   ra   ZACGTACGTr   r   r   r   r   alphabetrP   dnaZrnaZACGUACGUZproteinZLMWAZis_iupacr   r   r   r   center_weights)r   r   r   r   r   r   )r   r>   Zsequence_to_matrixrF   rZ   r   r   r   r   test_sequence_to_matrix  sP                  r   c               	   C   s  t jddd} |  }W 5 Q R X dd |D }tt jdddd	d
gg|ddggd tt jddddgd gddgd tt jddddgddddg|d tt jdddgd ddddgg|d tt jddddd gdddg|d tt jdtt|d tt jd d ddgddd!g|d d S )"Nzcrp_sites.faFr   c                 S   s$   g | ]}d |krd|kr|  qS )#>)strip).0r   r   r   r   
<listcomp>  s       z,test_alignment_to_matrix.<locals>.<listcomp>	sequencesr   r   ZAACCTZAACGATAZACAZGGAr'   r   r   )r   r   r   r   r   r   TrP   r   r   r   r   r   rd   Zcharacters_to_ignorer1   r]   r_   r`   r   r   r!   )r>   open_example_datafile	readlinesr   Zalignment_to_matrixrF   rZ   )fZraw_seqsZseqsr   r   r   test_alignment_to_matrix  sJ     
   
 
   r   c               	   C   s   t jddd} tj| ddd}W 5 Q R X tt jdd dd	g|d
 g|d d tt jdd dd	g|d g|d
 d tt jdd	dgd ddddgg|d
 |d d tt jddddgd dg|d
 |d d d S )Nnn_saliency_values.txtFr   r   	)commentsepr   r   r   	charactervalue)r   r   r   r   valuesr   r   r   r]   r_   r`   ra   )r   r   r   r   r   r   r   r   TrP   r   )r>   r   r@   Zread_csvr   Zsaliency_to_matrix)r   Zsaliency_data_dfr   r   r   test_saliency_to_matrix  s0          r   c                  C   s  t jddgd\} }|ddg |ddg ttjdg dddd	gd
|ddd ttjdddd gd
ddgd|ddd ttjdddd gddd	gd|dd
d ttjdddd gddd	gd|dd
d ttjdddgd |gdddd
d ttjdddgdddgdddd
|d	 ttjdddd dgddd	gdddd
|d	 ttjddgdgdddd
|d	 ttjdddgd d!d"gdddd
|d	 ttjd#ddgd$dddgdddgdd%d&ggdddd
|d	 ttjd'ddgd(dddgdddgdd%d&ggdddd
|d	 ttjd)ddd gddd	gdddd
|d	 ttjd*dd gd+d
gdddd
|d	 ttjd,ttdddd
|d	 ttjd-ttdddd
|d	 ttjd.dgdd	dd!gdddd
|d	 ttjd/d0ddgd1d	d2gdddd
|d	 ttjd3d4dd5gd6ddggd7d!d!ggdddd
|d	 d S )8N   r    r<   r   r9   r   r\   r!   r1   r]   )r   r   r   r   r^   r=   rt   ru   r^   rU   r_   r   )r   r   r   r   r\   r=   rt   ru   rt   )r   r   r   r   r\   r=   ru   r^   ru   r   )r   r   r   r   r\   r=   rt   r^   r=   )r   r   r   r   r\   ru   rt   r^   width)	r   r   r   r   r\   ru   rt   r^   r=   Zvpadg?r,   r-   Zfont_weightrP   boldr;   normalrS   rT   rV   r4   rs   r   Z	edgewidthZdont_stretch_more_thanErY   Zmirrorr5   rW   rO   rQ   r3   r6   r.   r7   r8   r:   )	r   rG   Zset_xlimZset_ylimr   r>   ZGlyphrF   rZ   )Zfigr=   r   r   r   
test_Glyph1  s@    
                        
                                              
         
    r   c                   C   sd   t tjdddgddgdd t tjdttdd	 t tjdddgd
dgdd t tjdttd
d	 d S )Nnamezwrong argumentr   r   Zww_counts_matrixF)r   r   r   r   r   r   )r   r   r   r   r   r   zss_sequences.txt)r   r>   r?   rF   rZ   r   r   r   r   r   test_logomaker_get_data_methods  s(           r   c                   C   s*   t tjddddgddgd td d S )	Nr   r   TrP   ZcrpZfig1br'   r   )r   r>   Zdemor   r   r   r   r   r   	test_demo  s
     r   c                   C   sj   t   t  t  t  t  t  t  t  t  t	  t
  t  t  t  t  t  t  dS )z
    Run all Logomaker functional tests. There are 547 tests as of 14 May 2019.

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

    return
    ------
    None.
    N)rK   rN   rR   r[   rb   rh   rj   rv   ry   r~   r   r   r   r   r   r   r   r   r   r   r   	run_tests  s"    r   __main__)'
__future__r   syspathappendr>   numpyrA   Zpandasr@   Zmatplotlib.pyplotZpyplotr   r
   r	   rF   rZ   r   r   rK   rN   rR   r[   rb   rh   rj   rv   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sH   #
DT,1#*e&
