ó
îÆÔIc        
   @   sÛ  d  d l  m Z y
 e Z Wn! e k
 r= d  d l m Z n Xd  d l Z d  d l Z d  d l  m Z d  d l	 m
 Z
 d  d l  m Z d Z e j d k rƒy e j d Z Wn e k
 rÅ d	 Z n Xd
 d d d d d d g Z d d d g Z xe D]… Z e j j e j j e e ƒ ƒ r÷ xN e D]F Z e j j e j j e e e ƒ ƒ r%e j j e e e ƒ Z Pq%q%We r|Pq|q÷ q÷ Wn d  d l Z e j d ƒ Z d e k rÅd e j ƒ  k rÅd Z n  e se j d ƒ Z d e k rd e j ƒ  k rd Z qn  e se d ƒ ‚ n  d GHd GHd GHd Z e j j e ƒ sGt ‚ e
 e d e ƒZ  y/ e j! e  ƒ Z" e# s‡t d  e$ e" ƒ ƒ ‚ Wnr e% k
 rüZ& d! GHd" e' e& ƒ k sýd# e' e& ƒ k sýe' e& ƒ d$ k sýe' e& ƒ d% k sýt e' e& ƒ ƒ ‚ n XHd& GHd' Z e j j e ƒ s!t ‚ e( e) e j* e+ e ƒ d( ƒ ƒ ƒ d) k sQt ‚ e
 e d e ƒZ  y/ e j! e  ƒ Z" e# s‘t d  e$ e" ƒ ƒ ‚ Wn_ e% k
 rÄZ& d! GHd* e' e& ƒ k sôt ‚ n0 e, k
 róZ& d! GHe' e& ƒ d+ k sôt ‚ n XHd, GHd- Z e j j e ƒ st ‚ e
 e d e ƒZ  y/ e j! e  ƒ Z" e# sXt d  e$ e" ƒ ƒ ‚ Wnr e% k
 rÍZ& d! GHd. e' e& ƒ k sÎd# e' e& ƒ k sÎe' e& ƒ d$ k sÎe' e& ƒ d% k sÎt e' e& ƒ ƒ ‚ n XHd/ GHd0 GHd1 Z- e+ e- d2 ƒ Z. e j/ e j* e+ d3 ƒ d4 ƒ e. d( ƒ e. j0 ƒ  d5 Z1 e+ e1 d2 ƒ Z. e) e j* e+ d6 d7 ƒ d8 ƒ ƒ d9  Z2 e j/ e2 e. d( ƒ e. j0 ƒ  [. [2 xÍdR dS dT dU dV e- d; d f e- d= d f e1 dA d f g D]’\ Z Z3 Z4 e j5 e j* e+ e ƒ d( ƒ dB „  ƒ Z6 e j j e3 ƒ re j7 e3 ƒ n  dC e$ e ƒ e( e6 ƒ f GHdD e$ e3 ƒ GHe4 d k	 rTdE e$ e4 ƒ GHn  e
 e d e ƒZ  e  j8 e3 ƒ e4 d k	 re  j9 e4 ƒ n  e j d k rùe j: dF  dW k  rùdH e k sádH e3 k sáe4 d k	 rùdH e4 k rùdI e( e6 ƒ GHq´qùn  e j! e  ƒ Z" dI e( e" j; ƒ  ƒ GHe j5 e j* e+ e3 ƒ dJ ƒ ƒ Z< e e6 j= ƒ  ƒ e e< j= ƒ  ƒ k sht ‚ xp e" D]h Z> e' e> j? ƒ e' e< e> j@ j? ƒ k s t ‚ e' e> j? ƒ jA dK d ƒ e' e6 e> j@ j? ƒ k sot ‚ qoWe j7 e3 ƒ e4 d k	 rýe4 ZB n e j jC e ƒ dL dM ZB e j j eB ƒ s9t dN eB ƒ ‚ e j7 eB ƒ q´We j j dO ƒ rle j7 dO ƒ n  e j j dP ƒ rŽe j7 dP ƒ n  e j j e- ƒ r°e j7 e- ƒ n  e j j e1 ƒ rÒe j7 e1 ƒ n  dQ GHd S(X   iÿÿÿÿ(   t   MissingExternalDependencyError(   t   SetN(   t   Clustalw(   t   MultipleAlignCL(   t   SeqIOt   win32t   PROGRAMFILESs   C:\Program Filest	   ClustalW2t    t   ClustalR   t   Clustalw183s   Clustalw1.83s   CTCBioApps\clustalw\v1.83s   clustalw2.exes   clustalw.exes   clustalw1.83.exes   clustalw2 --versions	   not foundt   CLUSTALt	   clustalw2s   clustalw --versiont   clustalws>   Install clustalw or clustalw2 if you want to use Bio.Clustalw.s   Checking error conditionss   =========================s
   Empty files   does_not_exist.fastat   commands   Should have failed, returned %ss   Failed (good)s   Cannot open sequence files   not produceds   [Errno 0] Errors   (0, 'Error')s   Single sequences
   Fasta/f001t   fastai   s   has only one sequence presents   No records found in handles   Invalid sequences   Medline/pubmed_result1.txts   invalid formats   Checking normal situationss   ==========================s   Clustalw/temp horses.fastat   ws   Phylip/hennigian.phyt   phylips   temp_cw_prot.fastas   NBRF/Cw_prot.pirt   rUt   piri(   s
   Fasta/f002s   temp_test.alns   GFF/multi.fnas   temp with space.alns   Registry/seqs.fastas   temp_test.dnds   temp with space.dnds   temp_cw_prot.alnc         C   s   |  j  j d d ƒ S(   Nt   :t   _(   t   idt   replace(   t   rec(    (    s   test_Clustalw_tool.pyt   <lambda>«   s    s(   Calling clustalw on %s (with %i records)s   using output file %ss$   requesting output guide tree file %si   i   t    s   Got an alignment, %i sequencest   clustalt   -i    s   .dnds   Did not find tree file %ss   Fasta/f001.alns   Medline/pubmed_result1.alnt   Done(   s
   Fasta/f002s   temp_test.alnN(   s   GFF/multi.fnas   temp with space.alnN(   s   Registry/seqs.fastas   temp_test.alnN(   s   Registry/seqs.fastas   temp_test.alns   temp_test.dnd(   s   Registry/seqs.fastas   temp_test.alns   temp with space.dnd(   i   i   (D   t   BioR    t   sett	   NameErrort   setsR   t   syst   osR   t   Bio.ClustalwR   R   t   Nonet   clustalw_exet   platformt   environt
   prog_filest   KeyErrort   likely_dirst   likely_exest   foldert   patht   isdirt   joint   filenamet   isfilet   commandst	   getoutputt   outputt   uppert
   input_filet   AssertionErrort   clinet   do_alignmentt   alignt   Falset   reprt   IOErrort   errt   strt   lent   listt   parset   opent
   ValueErrort   temp_filename_with_spacest   handlet   writet   closet   temp_large_fasta_filet   recordst   output_filet   newtree_filet   to_dictt   input_recordst   removet
   set_outputt   set_new_guide_treet   version_infot   get_all_seqst   output_recordst   keyst   recordt   seqR   R   t	   tree_filet   splitext(    (    (    s   test_Clustalw_tool.pyt   <module>   s&  

	!$ 	 (0  (%
%
"	!*+#	