ó
šIc           @   sþ   d  d l  Z  d  d l Z d  d l Z d  d l Td  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d e j f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e d k rú e j d d ƒ Z e j d e ƒ n  d S(   iÿÿÿÿN(   t   *(   t   Fasta(   t	   SeqRecord(   t   Seq(   t   Alphabet(   t   IUPACt
   RecordTestc           B   s   e  Z d  „  Z RS(   c         C   s[   d „  } t  j ƒ  } | t | j ƒ t k ƒ s6 t ‚ | t | j ƒ t k ƒ sW t ‚ d S(   s   Basic test on Record
        c         S   s   |  r
 d Sd S(   Ni   i    (    (   t   b(    (    s   test_Fasta.pyt   pbool   s    N(   R   t   Recordt   typet   titlet
   StringTypet   AssertionErrort   sequence(   t   selfR   t   r(    (    s   test_Fasta.pyt   test_record_basic   s    	!(   t   __name__t
   __module__R   (    (    (    s   test_Fasta.pyR      s   t
   ParserTestc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sf   d d g } g  |  _  x3 | D]+ } |  j  j t t j j d | ƒ ƒ ƒ q Wi d
 d 6d d	 6|  _ d  S(   Nt   f001t   f002R   i`   iO   i    id   iy  i   (   i`   iO   (   id   iy  (   t   handlest   appendt   opent   ost   patht   joint   lengths(   R   t   filest   filename(    (    s   test_Fasta.pyt   setUp    s    	)
c         C   s"   x |  j  D] } | j ƒ  q
 Wd  S(   N(   R   t   close(   R   t   handle(    (    s   test_Fasta.pyt   tearDown)   s    c         C   s°   t  j ƒ  } x t t |  j ƒ ƒ D]† } |  j | } | j | ƒ } t | t  j ƒ s\ t ‚ t | j	 ƒ |  j
 | d k s‚ t ‚ t | j ƒ |  j
 | d k s" t ‚ q" Wd S(   s.   Basic operation of the Record Parser.
        i    i   N(   R   t   RecordParsert   ranget   lenR   t   parset
   isinstanceR	   R   R   R   R   (   R   t   parsert   indexR"   t   rec(    (    s   test_Fasta.pyt   test_record_parser-   s    &c         C   sæ   t  j ƒ  } xÓ t t |  j ƒ ƒ D]¼ } |  j | } | j | ƒ } t | t j ƒ s\ t ‚ t | j	 t
 j
 ƒ sw t ‚ | j	 j t j k s’ t ‚ t | j	 ƒ |  j | d k s¸ t ‚ t | j ƒ |  j | d k s" t ‚ q" Wd S(   s0   Basic operation of the Sequence Parser.
        i   i    N(   R   t   SequenceParserR%   R&   R   R'   R(   R   R   t   seqR   t   alphabetR   t   generic_alphabetR   t   description(   R   R)   R*   R"   R+   (    (    s   test_Fasta.pyt   test_sequence_parser8   s    &c         C   sJ   t  j d t j ƒ } | j |  j d ƒ } | j j t j k sF t ‚ d S(   s6   Setting the alphabet for the Sequence Parser.
        R/   i    N(	   R   R-   R   t   unambiguous_dnaR'   R   R.   R/   R   (   R   R)   R+   (    (    s   test_Fasta.pyt   test_sequence_alphabetE   s    	c         C   st   d „  } t  j d | ƒ } | j |  j d ƒ } | j d k sF t ‚ | j d k s[ t ‚ | j d k sp t ‚ d S(   s7   Test title conversion for the Sequence Parser.
        c         S   s   d S(   Nt   idt   nameR1   (   R5   R6   R1   (    (   R   (    (    s   test_Fasta.pyt   test_title2idsP   s    t	   title2idsi    R5   R6   R1   N(   R   R-   R'   R   R5   R   R6   R1   (   R   R7   R)   R+   (    (    s   test_Fasta.pyt   test_sequence_title_convertM   s    	(   R   R   R    R#   R,   R2   R4   R9   (    (    (    s   test_Fasta.pyR      s   						t   IteratorTestc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s"   t  t j j d d ƒ ƒ |  _ d  S(   NR   R   (   R   R   R   R   t   test_handle(   R   (    (    s   test_Fasta.pyR    Y   s    c         C   s   |  j  j ƒ  d  S(   N(   R;   R!   (   R   (    (    s   test_Fasta.pyR#   \   s    c         C   s½   t  j |  j ƒ } i d d 6d d 6d d 6} xY t d ƒ D]K } | j ƒ  } | j d ƒ } | d j ƒ  } | d | | k s: t ‚ q: W| j ƒ  d	 k s¡ t ‚ | j ƒ  d	 k s¹ t ‚ d	 S(
   s8   Ensure the Fasta iterator works returning text.
        s   >gi|1348912|gb|G26680|G26680i    s   >gi|1348917|gb|G26685|G26685i   s   >gi|1592936|gb|G29385|G29385i   i   s   
N(   R   t   IteratorR;   R%   t   nextt   splitR   t   None(   R   t   it   rec_infot   rec_numR+   t   linest
   title_part(    (    s   test_Fasta.pyt   test_basic_iterator_   s    

c         C   sO   d } t  j |  j ƒ } x t | ƒ D] } | d 7} q% W| d k sK t ‚ d S(   sD   Ensure the Fasta iterator works like a Python 2.2 iterator.
        i    i   i   N(   R   R<   R;   t   iterR   (   R   t   nt   iteratorR+   (    (    s   test_Fasta.pyt   test_new_iteratorp   s
    c         C   sT   t  j ƒ  } t  j |  j | ƒ } x, t | ƒ D] } t | t  j ƒ s. t ‚ q. Wd S(   s0   Test the iterator with a Record Parser.
        N(   R   R$   R<   R;   RF   R(   R	   R   (   R   R)   RH   R+   (    (    s   test_Fasta.pyt   test_record_iteratory   s    c         C   sT   t  j ƒ  } t  j |  j | ƒ } x, t | ƒ D] } t | t j ƒ s. t ‚ q. Wd S(   s2   Test the iterator with a Sequence Parser.
        N(   R   R-   R<   R;   RF   R(   R   R   (   R   R)   RH   R+   (    (    s   test_Fasta.pyt   test_sequence_iterator   s    c         C   sp   t  t j j d d ƒ ƒ } t j | t j ƒ  ƒ } d } x t | ƒ D] } | d 7} qF W| d k sl t ‚ d S(   s>   Parse FASTA files with # style comment lines in them.
        R   t   f003i    i   i   N(	   R   R   R   R   R   R<   R$   RF   R   (   R   R"   RH   t   num_recsR+   (    (    s   test_Fasta.pyt   test_parsing_comments‰   s    (	   R   R   R    R#   RE   RI   RJ   RK   RN   (    (    (    s   test_Fasta.pyR:   X   s   							t   __main__t	   verbosityi   t
   testRunner(   R   t   syst   unittestt   typest   BioR   R   R   R   t   Bio.AlphabetR   t   TestCaseR   R   R:   R   t   TextTestRunnert   runnert   main(    (    (    s   test_Fasta.pyt   <module>   s   
9<