ó
 6ˆIc           @   sZ  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 e Z x} e j d j e j ƒ D]b Z yE e j e ƒ Z x/ e j e ƒ D] Z e j d ƒ r´ e Z q´ q´ WWqŒ e j k
 rí qŒ XqŒ We se
 d ƒ ‚ n  d e j f d	 „  ƒ  YZ e d
 k rVd GHe j d d ƒ Z e j d e ƒ n  d S(   iÿÿÿÿN(   t   FDist(   t
   Controller(   t   MissingExternalDependencyErrort   PATHt   fdist2s2   Install FDist if you want to use Bio.PopGen.FDist.t   AppTestc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s+   Tests the fdist suite of applications.
    c         C   s-   t  j d t j | |  j t j | ƒ d  S(   Nt   PopGen(   t   shutilt   copyfilet   ost   sept   dirname(   t   selft   innamet   outname(    (    s   test_PopGen_FDist.pyt	   _copyfile#   s    c         C   sb   t  j ƒ  |  _ t j ƒ  |  _ |  j d d ƒ |  j d d ƒ |  j d d ƒ |  j d d ƒ d  S(   Nt   data_fst_outfilet   fdist1t   infiles   out.dats   out.cpl(   R   t   FDistControllert   ctrlt   tempfilet   mkdtempR   R   (   R   (    (    s   test_PopGen_FDist.pyt   setUp(   s    c         C   sd   t  j j |  j ƒ r` x5 t  j |  j ƒ D]! } t  j |  j t  j | ƒ q( Wt  j |  j ƒ n  d  S(   N(   R	   t   patht   isdirR   t   listdirt   removeR
   t   rmdir(   R   t   file(    (    s   test_PopGen_FDist.pyt   tearDown0   s    c         C   sJ   |  j  j d |  j ƒ \ } } | d d k  s4 t ‚ | d k sF t ‚ d S(   s    Test datacal execution.
        t   data_dirg)\Âõ(Ü?g{®Gáz„?i   N(   R   t   run_datacalR   t   AssertionError(   R   t   fstt	   samp_size(    (    s   test_PopGen_FDist.pyt   test_datacal8   s    c         C   s\   |  j  j d d d d d d d d d	 d
 d d d |  j ƒ } t | d ƒ d k  sX t ‚ d S(   s   Test fdist execution.
        t   npopsi   t   nsamplesi
   R"   gš™™™™™¹?t   sample_sizei   t   muti    t   num_simsid   R   g{®Gáz”?N(   R   t	   run_fdistR   t   absR!   (   R   R"   (    (    s   test_PopGen_FDist.pyt
   test_fdist?   s    c         C   s\   |  j  j d d d d d d d d d	 d
 d d d |  j ƒ } t | d ƒ d k  sX t ‚ d S(   s0   Test fdist execution approximating Fst.
        R%   i   R&   i
   R"   gš™™™™™¹?R'   i   R(   i    R)   id   R   g
×£p=
·?gš™™™™™©?N(   R   t   run_fdist_force_fstR   R+   R!   (   R   R"   (    (    s   test_PopGen_FDist.pyt   test_fdist_force_fstI   s
    c         C   s4   |  j  j d |  j ƒ } t | ƒ d k s0 t ‚ d S(   s   Test cplot execution.
        R   i   N(   R   t	   run_cplotR   t   lenR!   (   R   t   cpl_interval(    (    s   test_PopGen_FDist.pyt
   test_cplotT   s    c         C   s4   |  j  j d |  j ƒ } t | ƒ d k s0 t ‚ d S(   s   Test pv execution.
        R   i   N(   R   t   run_pvR   R0   R!   (   R   t   pv_data(    (    s   test_PopGen_FDist.pyt   test_pvZ   s    (   t   __name__t
   __module__t   __doc__R   R   R   R$   R,   R.   R2   R5   (    (    (    s   test_PopGen_FDist.pyR       s   					
		t   __main__s<   Running fdist tests, which might take some time, please waitt	   verbosityi   t
   testRunner(   t   commandsR	   R   R   t   unittestt
   Bio.PopGenR    t   Bio.PopGen.FDistR   t   BioR   t   Falset   foundt   environt   splitt   pathsepR   R   t   listR   t
   startswitht   Truet   errort   TestCaseR   R6   t   TextTestRunnert   runnert   main(    (    (    s   test_PopGen_FDist.pyt   <module>   s0    A