
X_S;=                 @   s   d  d l  Td  d l Td  d l Td  d l Td  d l  m Z d  d l m Z d  d l Z d  d l Td  d l	 TGd d   d e j
  Z Gd d   d e j
  Z Gd	 d
   d
 e j
  Z d Z d Z d Z d Z e d k r e j   n  d S)    )*)data)StringIONc               @   s   e  Z d  Z d d   Z d S)test_AlphabeticArrayc             C   s6   t  t t f  } d | d <| d d k s2 t  d  S)	N
   ACr      g      $@)r   r   )r   r	   )AlphabeticArrayprotein_alphabetAssertionError)selfmatrix r   L/Users/gec/Work/Projects/corebioproj/weblogo-3.4/test_corebio/test_matrix.pytest_create   s    
z test_AlphabeticArray.test_createN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c               @   sL   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d S)
test_Motifc             C   s  t  d  } t j |  } | j   | d d k s; t  | d d k sQ t  t | j  d k sl t  | j   t  d
  } t j |  } | j   | d d k s t  | d d k s t  t | j  d k s t  t  d  } t j |  } | j   d  S)Nztransfac_matrix.txt   r   g        r   Gg       @      ztransfac_matrix2.txtg      @g      c@   ztransfac_matrix3.txt)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )testdata_streamMotifread_transfaccloser   shapearray)r   fmr   r   r   test_read_transfac   s     


ztest_Motif.test_read_transfacc             C   s   t  d  } t j |  } | j   | j d  } t | j  d k sO t  xZ t d d  D]I } x@ t	 d  D]2 \ } } | | | f | | | f k sr t  qr Wq_ Wd  S)Nztransfac_matrix.txtZTCGAr   r   ZAGCT)
r   r   r   r   reindexstralphabetr   range	enumerate)r   r!   r"   m2kiar   r   r   test_reindex/   s    
ztest_Motif.test_reindexc       	      C   s   t  d  } t j |  } t  d  } t j |  } | j   t |  \ } } x_ t d |  D]N } xE t d |  D]4 } | | | f | | | d | f k sx t  qx Wqb W| j   | j   d  S)Nztransfac_matrix.txtr   r	   )r   r   r   reverser   r'   r   r   )	r   r!   r"   f2r)   KNr*   nr   r   r   test_reverse<   s    
6
ztest_Motif.test_reversec             C   s  t  d  } t j |  } t  d  } t j |  } | j   t |  \ } } x t d |  D] } | | d f | | d f k s t  | | d f | | d f k s t  | | d f | | d f k s t  | | d f | | d f k sb t  qb W| j   | j   d  S)Nztransfac_matrix.txtr   r   Tr   r   )r   r   r   
complementr   r'   r   r   )r   r!   r"   r/   r)   r0   r1   r*   r   r   r   test_complementL   s    
&&&*
ztest_Motif.test_complementc             C   s   t  d  } t j |  } t  d  } t j |  } | j   | j   | j   | j | j k j   sr t  | j	   | j	   d  S)Nztransfac_matrix.txt)
r   r   r   r5   r.   reverse_complementr    allr   r   )r   r!   r"   r/   r)   r   r   r   test_reverse_complement\   s    



z"test_Motif.test_reverse_complementN)r   r   r   r#   r-   r3   r6   r9   r   r   r   r   r      s
   r   c               @   s   e  Z 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 S)test_SubMatrixc             C   s   d } t  d d d d g d d d d	 g d
 d d d g d d d d g g  } t | |  } | d d k ss t  | d d k s t  | d d k s t  d | d <| d d k s t  d  S)NABCDr	      r   r               	   r      r         r      r   r   Br   )r   r   )r   r   )rF   r   )rF   r   )rF   r   rG   )asarray	SubMatrixr   )r   abarsr   r   r   r   p   s    H
ztest_SubMatrix.test_createc             C   s   t  d  } t d d d d g d d d d	 g d
 d d d g d d d d g g  } t | |  } d } d } | j | | f  } x] t |  D]O \ } } x@ t |  D]2 \ }	 }
 | | |
 f | | |	 f k s t  q Wq Wd  S)Nr;   r	   r<   r   r   r=   r>   r?   r@   rA   r   rB   r   rC   rD   r   rE   Z	DCCBBBAAABA)AlphabetrH   rI   indexr(   r   )r   rJ   rK   rL   s1s2vr"   r+   r2   jr   r   r   test_get{   s    Hztest_SubMatrix.test_getc             C   sE  t  d  } t d d d d g d d d d	 g d
 d d d g d d d d g g  } t | |  } | j d  } t | j t d d d g d d d g d
 d d g g  k  s t  | j d  } t | j t d d g d d g g  k  s t  | j t  d   } t | j t d d g d d g g  k  sAt  d  S)Nr;   r	   r<   r   r   r=   r>   r?   r@   rA   r   rB   r   rC   rD   r   rE   ABCrM   )rN   rH   rI   r$   r8   r    r   )r   rJ   rK   matZmat2r   r   r   test_get_subMatrix   s    HE3z!test_SubMatrix.test_get_subMatrixc             C   s   t  d  } t d d d d g d d d d	 g d
 d d d g d d d d g g  } t | |  } |  j t | j d  |  j t | j d  |  j t | j d  d  S)Nr;   r	   r<   r   r   r=   r>   r?   r@   rA   r   rB   r   rC   rD   r   rE   Er   56)rX   r   )rY   rZ   )rX   r   )rN   rH   rI   assertRaises
IndexError__getitem__rO   )r   rJ   rK   rL   r   r   r   test_fail_get   s    Hztest_SubMatrix.test_fail_getc             C   ss   t  d  } t d d d d g d d d d	 g d
 d d d g d d d d g g  } t | |  } t |  } d  S)Nr;   r	   r<   r   r   r=   r>   r?   r@   rA   r   rB   r   rC   rD   r   rE   )rN   rH   rI   repr)r   rJ   rK   rL   stringr   r   r   	test_repr   s    Hztest_SubMatrix.test_reprc             C   s5   t  t  } t j |  } | d d k s1 t  d  S)Nr,   r   )r,   r,   )r   test_matrix1rI   readr   )r   r!   rV   r   r   r   	test_read   s    ztest_SubMatrix.test_readc             C   s&   t  t  } |  j t t j |  d  S)N)r   test_matrix4r[   
ValueErrorrI   rc   )r   r!   r   r   r   test_read_asymmetric_fail   s    z(test_SubMatrix.test_read_asymmetric_failc             C   sr   t  t  } |  j t t j |  t  t  } t j | d t d  } t  t  } |  j t t j | t  d  S)Nr&   ARNDCQEGHILKMFPSTWYV)	r   test_matrix3r[   rf   rI   rc   rN   rb   unambiguous_protein_alphabet)r   r!   rV   r/   r   r   r   test_read_alphabets   s    		z"test_SubMatrix.test_read_alphabetsc             C   s&   t  t  } |  j t t j |  d  S)N)r   test_matrix2r[   rf   rI   rc   )r   r!   r   r   r   test_read_corrupt   s    	z test_SubMatrix.test_read_corruptc             C   s|   t  j d  } t j |  } |  j | d d  | j   t  j d  } t j |  } |  j | d	 d
  | j   d  S)Npam250r   g       @pam120r   r=   r?   )r   r   )r   r=   i)r   data_streamrI   rc   assertEqualr   )r   r!   rV   r   r   r   test_read_pam   s    
ztest_SubMatrix.test_read_pamc             C   s|   t  j d  } t j |  } |  j | d d	  | j   t  j d  } t j |  } |  j | d
 d  | j   d  S)Nblosum80r   r   r   blosum62r   r=   )r   r   )r   r=   )r   rp   rI   rc   rq   r   )r   r!   rV   r   r   r   test_read_blosum   s    
ztest_SubMatrix.test_read_blosumc             C   s   t  d  } t j |  } |  j | d d  | j   t  d  } t j |  } |  j | d d  |  j | j j d  | j   t  d
  } t j |  } |  j | d d  | j   d  S)Nzblosum35.blast.newr   r=   r   zblosum35.blastr   r   r<      z
pam250.mat)r   r=   ru   )r   r   )rx   rx   )r   r=   )r   rI   rc   rq   r   r    r   )r   r!   rV   r   r   r   test_read_blast   s    

ztest_SubMatrix.test_read_blastN)r   r   r   r   rT   rW   r^   ra   rd   rg   rk   rm   rr   rw   r{   r   r   r   r   r:   n   s   	r:   a  # A Test Matrix
# More comments

# And blank line should be ignored

A    4  -2  -2  -2   0  -1  -1  -1  -2  -2  -2  -2  -1  -2  -1   0  -1  -3  -2  -1  -2  -1  -1
R   -2   6  -1  -1  -4   1   0  -3   0  -3  -3   2  -2  -3  -2  -1  -1  -2  -2  -3   3  -1  -1
N   -2  -1   7   1  -3   0   0  -1   0  -5  -4   0  -3  -4  -2   0  -1  -3  -2  -4   3  -1  -1
D   -2  -1   1   7  -4   0   1  -1  -1  -6  -5   0  -4  -5  -1   0  -1  -4  -3  -5   0  -2  -2
C    0  -4  -3  -4  12  -3  -4  -3  -3  -1  -2  -4  -1  -2  -3  -2  -1  -2  -2   0  -3   5  -2
Q   -1   1   0   0  -3   6   1  -2   0  -3  -3   1  -2  -3  -1   0  -1  -2  -2  -3   0   1  -1
E   -1   0   0   1  -4   1   5  -2  -1  -4  -4   1  -3  -4  -1  -1  -1  -3  -3  -4   0  -1  -1
G   -1  -3  -1  -1  -3  -2  -2   7  -2  -6  -5  -2  -4  -5  -2  -1  -2  -4  -4  -5  -2  -2  -2
H   -2   0   0  -1  -3   0  -1  -2   9  -3  -3  -1  -2  -1  -2  -1  -1   0   0  -3   0  -1  -1
I   -2  -3  -5  -6  -1  -3  -4  -6  -3   5   2  -4   1   0  -4  -4  -2  -1  -1   3  -4  -2  -2
L   -2  -3  -4  -5  -2  -3  -4  -5  -3   2   5  -3   2   1  -3  -3  -2  -1  -1   1  -4  -2  -2
K   -2   2   0   0  -4   1   1  -2  -1  -4  -3   5  -2  -4  -1  -1  -1  -3  -3  -3   1  -1  -1
M   -1  -2  -3  -4  -1  -2  -3  -4  -2   1   2  -2   7   1  -3  -2  -1   0   0   1  -3  -2  -1
F   -2  -3  -4  -5  -2  -3  -4  -5  -1   0   1  -4   1   7  -3  -3  -2   3   3   0  -3  -2  -1
P   -1  -2  -2  -1  -3  -1  -1  -2  -2  -4  -3  -1  -3  -3   8  -1  -2  -3  -3  -3  -2  -2  -2
S    0  -1   0   0  -2   0  -1  -1  -1  -4  -3  -1  -2  -3  -1   4   1  -3  -2  -3   0  -1  -1
T   -1  -1  -1  -1  -1  -1  -1  -2  -1  -2  -2  -1  -1  -2  -2   1   5  -2  -2  -1  -1  -1  -1
W   -3  -2  -3  -4  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -3  -2  12   3  -2  -3  -2  -1
Y   -2  -2  -2  -3  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -2  -2   3   8  -2  -2  -2  -1
V   -1  -3  -4  -5   0  -3  -4  -5  -3   3   1  -3   1   0  -3  -3  -1  -2  -2   5  -4  -2  -2
B   -2   3   3   0  -3   0   0  -2   0  -4  -4   1  -3  -3  -2   0  -1  -3  -2  -4   3  -1  -1
Z   -1  -1  -1  -2   5   1  -1  -2  -1  -2  -2  -1  -2  -2  -2  -1  -1  -2  -2  -2  -1   3  -1
X   -1  -1  -1  -2  -2  -1  -1  -2  -1  -2  -2  -1  -1  -1  -2  -1  -1  -1  -1  -2  -1  -1  -1
a	  # An invalid Test Matrix
# Its got a non-numerical value in it. Is the correct exception raised?

# And blank line should be ignored

A    4  -2  -2  -2   0  -1  -1  -1  -2  -2  -2  -2  -1  -2  -1   0  -1  -3  -2  -1  -2  -1  -1
R   -2   6  -1  -1  -4   1   0  -3   0  -3  -3   2  -2  -3  -2  -1  -1  -2  -2  -3   3  -1  -1
N   -2  -1   7   1  -3   0   0  -1   0  -5  -4   0  -3  -4  -2   0  -1  -3  -2  -4   3  -1  -1
D   -2  -1   1   7  -4   0   1  -1  -1  -6  -5   0  -4  -5  -1   0  -1  -4  -3  -5   0  -2  -2
C    0  -4  -3  -4  12  -3  -4  -3  -3  -1  -2  -4  -1  -2  -3  -2  -1  -2  -2   0  -3   5  -2
Q   -1   1   0   0  -3   6   1  -2   0  -3  -3   1  -2  -3  -1   0  -1  -2  -2  -3   0   1  -1
E   -1   0   0   1  -4   x   5  -2  -1  -4  -4   1  -3  -4  -1  -1  -1  -3  -3  -4   0  -1  -1
G   -1  -3  -1  -1  -3  -2  -2   7  -2  -6  -5  -2  -4  -5  -2  -1  -2  -4  -4  -5  -2  -2  -2
H   -2   0   0  -1  -3   0  -1  -2   9  -3  -3  -1  -2  -1  -2  -1  -1   0   0  -3   0  -1  -1
I   -2  -3  -5  -6  -1  -3  -4  -6  -3   5   2  -4   1   0  -4  -4  -2  -1  -1   3  -4  -2  -2
L   -2  -3  -4  -5  -2  -3  -4  -5  -3   2   5  -3   2   1  -3  -3  -2  -1  -1   1  -4  -2  -2
K   -2   2   0   0  -4   1   1  -2  -1  -4  -3   5  -2  -4  -1  -1  -1  -3  -3  -3   1  -1  -1
M   -1  -2  -3  -4  -1  -2  -3  -4  -2   1   2  -2   7   1  -3  -2  -1   0   0   1  -3  -2  -1
F   -2  -3  -4  -5  -2  -3  -4  -5  -1   0   1  -4   1   7  -3  -3  -2   3   3   0  -3  -2  -1
P   -1  -2  -2  -1  -3  -1  -1  -2  -2  -4  -3  -1  -3  -3   8  -1  -2  -3  -3  -3  -2  -2  -2
S    0  -1   0   0  -2   0  -1  -1  -1  -4  -3  -1  -2  -3  -1   4   1  -3  -2  -3   0  -1  -1
T   -1  -1  -1  -1  -1  -1  -1  -2  -1  -2  -2  -1  -1  -2  -2   1   5  -2  -2  -1  -1  -1  -1
W   -3  -2  -3  -4  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -3  -2  12   3  -2  -3  -2  -1
Y   -2  -2  -2  -3  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -2  -2   3   8  -2  -2  -2  -1
V   -1  -3  -4  -5   0  -3  -4  -5  -3   3   1  -3   1   0  -3  -3  -1  -2  -2   5  -4  -2  -2
B   -2   3   3   0  -3   0   0  -2   0  -4  -4   1  -3  -3  -2   0  -1  -3  -2  -4   3  -1  -1
Z   -1  -1  -1  -2   5   1  -1  -2  -1  -2  -2  -1  -2  -2  -2  -1  -1  -2  -2  -2  -1   3  -1
X   -1  -1  -1  -2  -2  -1  -1  -2  -1  -2  -2  -1  -1  -1  -2  -1  -1  -1  -1  -2  -1  -1  -1
a  #
# This test matrix has a smaller alphabet
A    4  -2  -2  -2   0  -1  -1  -1  -2  -2  -2  -2  -1  -2  -1   0  -1  -3  -2  -1  
R   -2   6  -1  -1  -4   1   0  -3   0  -3  -3   2  -2  -3  -2  -1  -1  -2  -2  -3  
N   -2  -1   7   1  -3   0   0  -1   0  -5  -4   0  -3  -4  -2   0  -1  -3  -2  -4  
D   -2  -1   1   7  -4   0   1  -1  -1  -6  -5   0  -4  -5  -1   0  -1  -4  -3  -5  
C    0  -4  -3  -4  12  -3  -4  -3  -3  -1  -2  -4  -1  -2  -3  -2  -1  -2  -2   0  
Q   -1   1   0   0  -3   6   4  -2   0  -3  -3   1  -2  -3  -1   0  -1  -2  -2  -3  
E   -1   0   0   1  -4   4   5  -2  -1  -4  -4   1  -3  -4  -1  -1  -1  -3  -3  -4  
G   -1  -3  -1  -1  -3  -2  -2   7  -2  -6  -5  -2  -4  -5  -2  -1  -2  -4  -4  -5  
H   -2   0   0  -1  -3   0  -1  -2   9  -3  -3  -1  -2  -1  -2  -1  -1   0   0  -3  
I   -2  -3  -5  -6  -1  -3  -4  -6  -3   5   2  -4   1   0  -4  -4  -2  -1  -1   3  
L   -2  -3  -4  -5  -2  -3  -4  -5  -3   2   5  -3   2   1  -3  -3  -2  -1  -1   1  
K   -2   2   0   0  -4   1   1  -2  -1  -4  -3   5  -2  -4  -1  -1  -1  -3  -3  -3  
M   -1  -2  -3  -4  -1  -2  -3  -4  -2   1   2  -2   7   1  -3  -2  -1   0   0   1  
F   -2  -3  -4  -5  -2  -3  -4  -5  -1   0   1  -4   1   7  -3  -3  -2   3   3   0  
P   -1  -2  -2  -1  -3  -1  -1  -2  -2  -4  -3  -1  -3  -3   8  -1  -2  -3  -3  -3  
S    0  -1   0   0  -2   0  -1  -1  -1  -4  -3  -1  -2  -3  -1   4   1  -3  -2  -3  
T   -1  -1  -1  -1  -1  -1  -1  -2  -1  -2  -2  -1  -1  -2  -2   1   5  -2  -2  -1  
W   -3  -2  -3  -4  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -3  -2  12   3  -2  
Y   -2  -2  -2  -3  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -2  -2   3   8  -2  
V   -1  -3  -4  -5   0  -3  -4  -5  -3   3   1  -3   1   0  -3  -3  -1  -2  -2   5  
a  # This matrix is invalid because it is asymetric! (AR, RA)

A    4   2  -2  -2   0  -1  -1  -1  -2  -2  -2  -2  -1  -2  -1   0  -1  -3  -2  -1  -2  -1  -1
R   -2   6  -1  -1  -4   1   0  -3   0  -3  -3   2  -2  -3  -2  -1  -1  -2  -2  -3   3  -1  -1
N   -2  -1   7   1  -3   0   0  -1   0  -5  -4   0  -3  -4  -2   0  -1  -3  -2  -4   3  -1  -1
D   -2  -1   1   7  -4   0   1  -1  -1  -6  -5   0  -4  -5  -1   0  -1  -4  -3  -5   0  -2  -2
C    0  -4  -3  -4  12  -3  -4  -3  -3  -1  -2  -4  -1  -2  -3  -2  -1  -2  -2   0  -3   5  -2
Q   -1   1   0   0  -3   6   1  -2   0  -3  -3   1  -2  -3  -1   0  -1  -2  -2  -3   0   1  -1
E   -1   0   0   1  -4   1   5  -2  -1  -4  -4   1  -3  -4  -1  -1  -1  -3  -3  -4   0  -1  -1
G   -1  -3  -1  -1  -3  -2  -2   7  -2  -6  -5  -2  -4  -5  -2  -1  -2  -4  -4  -5  -2  -2  -2
H   -2   0   0  -1  -3   0  -1  -2   9  -3  -3  -1  -2  -1  -2  -1  -1   0   0  -3   0  -1  -1
I   -2  -3  -5  -6  -1  -3  -4  -6  -3   5   2  -4   1   0  -4  -4  -2  -1  -1   3  -4  -2  -2
L   -2  -3  -4  -5  -2  -3  -4  -5  -3   2   5  -3   2   1  -3  -3  -2  -1  -1   1  -4  -2  -2
K   -2   2   0   0  -4   1   1  -2  -1  -4  -3   5  -2  -4  -1  -1  -1  -3  -3  -3   1  -1  -1
M   -1  -2  -3  -4  -1  -2  -3  -4  -2   1   2  -2   7   1  -3  -2  -1   0   0   1  -3  -2  -1
F   -2  -3  -4  -5  -2  -3  -4  -5  -1   0   1  -4   1   7  -3  -3  -2   3   3   0  -3  -2  -1
P   -1  -2  -2  -1  -3  -1  -1  -2  -2  -4  -3  -1  -3  -3   8  -1  -2  -3  -3  -3  -2  -2  -2
S    0  -1   0   0  -2   0  -1  -1  -1  -4  -3  -1  -2  -3  -1   4   1  -3  -2  -3   0  -1  -1
T   -1  -1  -1  -1  -1  -1  -1  -2  -1  -2  -2  -1  -1  -2  -2   1   5  -2  -2  -1  -1  -1  -1
W   -3  -2  -3  -4  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -3  -2  12   3  -2  -3  -2  -1
Y   -2  -2  -2  -3  -2  -2  -3  -4   0  -1  -1  -3   0   3  -3  -2  -2   3   8  -2  -2  -2  -1
V   -1  -3  -4  -5   0  -3  -4  -5  -3   3   1  -3   1   0  -3  -3  -1  -2  -2   5  -4  -2  -2
B   -2   3   3   0  -3   0   0  -2   0  -4  -4   1  -3  -3  -2   0  -1  -3  -2  -4   3  -1  -1
Z   -1  -1  -1  -2   5   1  -1  -2  -1  -2  -2  -1  -2  -2  -2  -1  -1  -2  -2  -2  -1   3  -1
X   -1  -1  -1  -2  -2  -1  -1  -2  -1  -2  -2  -1  -1  -1  -2  -1  -1  -1  -1  -2  -1  -1  -1
__main__)corebioZcorebio.matrixcorebio.seqcorebio.utilsr   Zcorebio._py3kr   unittestnumpyZtest_corebioTestCaser   r   r:   rb   rl   ri   re   r   mainr   r   r   r   <module>   s"   





V