ó
£žbc           @€  s€  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 y d  d l m Z Wn! e k
 r— d  d l m Z n Xd  d l m Z d  d l m Z m Z m Z d  d l m Z e e j ƒ Z e	 e j d	 ƒ Z e ƒ  Z i  Z i  Z d
 „  Z e d „ Z  e d „ Z! e d „ Z" d „  Z# d „  Z$ d „  Z% e d „ Z& d „  Z' d „  Z( d d „ Z) d S(   iÿÿÿÿ(   t   with_statementN(   t   repeat(   t   isdirt   joint   basename(   t   OrderedDict(   t   qconfig(   t   compile_toolt
   val_to_strt   get_path_to_program(   t
   get_loggert   minimap2c         C€  s   t  t |  ƒ S(   N(   R   t   contig_aligner_dirpath(   t   fname(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt	   bin_fpath#   s    c         C€  sC   t  d t d d d d ƒ} | r? |  r? t j d d d ƒn  | S(	   NR   t   min_versions   2.19t   recommend_versions   2.24sè  Critical! Tried to use minimap2, but it was unavailable despite QUAST's sincere expectations! E.g., the binary file is present but corrupted.
Possible workarounds:
1. Remove the minimap2 binary and restart QUAST (it will automatically try to recompile it): rm -f <quast_installation_dir>/quast_libs/minimap2/minimap2
2. Go to <quast_installation_dir>/quast_libs/minimap2/ and recompile minimap2 manually
3. Install a proper version of minimap2 and add it to your PATH environment variablet   exit_with_codei   (   R	   R   t   loggert   error(   t
   just_checkt   minimap_fpath(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyR   '   s
    
c         C€  sE   t  d t ƒ r | s= t d t d g d t d |  d | ƒrA t St S(   NR   t   Minimap2R   t   just_noticeR   t
   only_clean(   R   t   TrueR   R   t   False(   R   R   (    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   compile_minimap2   s    'c         C€  s'   t  |  d | ƒr t S|  j d ƒ t S(   NR   s]   Compilation of contig aligner software was unsuccessful! QUAST functionality will be limited.(   R   R   R   R   (   R   R   (    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   compile_aligner9   s    c         C€  s   t  |  t  | k S(   N(   t   ref_labels_by_chromosomes(   t   chr1t   chr2(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   is_same_reference@   s    c         C€  s   |  t  k r t  |  Sd S(   Nt    (   R   (   t   chrom(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   get_ref_by_chromosomeD   s    c         C€  s   t  j d ƒ } | j |  ƒ S(   Ns%   :\d+|\*[acgtn]+|\-[acgtn]+|\+[acgtn]+(   t   ret   compilet   findall(   t   cigart
   cs_pattern(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   parse_cs_tagH   s    c         C€  s  t  d ƒ } xm |  D]e } g  t | d g g  | d D] } t | ƒ ^ q4 | ƒ D]! \ } } t t | ƒ | ƒ ^ qQ } q Wt | | rŽ d n d ƒ } xc |  D][ } | j d j d „  t | | d g g  | d D] } t | ƒ ^ qÑ ƒ Dƒ ƒ d ƒ qž Wd  S(	   Ni    t
   metricNamet   valuest   at   ws     c         s€  s%   |  ] \ } } d  | | f Vq d S(   s   %-*sN(    (   t   .0t   colwidtht   cell(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pys	   <genexpr>S   s    s   
(   R   t   zipR   t   maxt   lent   opent   writeR   (   t   all_rowst   fpatht   append_to_existing_filet	   colwidthst   rowt   vR-   t   txt_file(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt
   print_fileM   s    cc         C€  s‹   t  |  t j ƒ } t | ƒ s. t j | ƒ n  t j r‡ d d l m } | j	 r‡ t  | d ƒ } t j
 j | ƒ s„ t j | ƒ q„ q‡ n  | S(   Niÿÿÿÿ(   t   search_references_metat   raw(   R   R   t   aligner_output_dirnameR   t   ost   mkdirt   is_combined_reft
   quast_libsR>   t   is_quast_first_runt   path(   t
   output_dirt   minimap_output_dirR>   (    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   create_minimap_output_dirW   s    		c         C€  s4   x- t  |  ƒ j ƒ  D] } | r | j ƒ  q q Wd  S(   N(   t   varsR+   t   close(   t	   ca_outputt   handler(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   close_handlersd   s    t   rtc         C€  s#  t  j j |  ƒ r, d | k r, |  d 7}  n  |  j d ƒ sJ |  j d ƒ rd | k rc | d 7} n  y t j |  d | ƒ} Wn t k
 rœ t |  d | ƒSXd | k r­ | Sy | j d ƒ Wn( t k
 rè | j ƒ  t |  d | ƒSX| j ƒ  t j |  d | ƒ} | Sn t |  d | ƒSd  S(   Nt   rs   .gzs   .gzipt   tt   modeR-   i   (	   RA   RF   t   existst   endswitht   gzipR4   t   IOErrort   readRK   (   t   fRR   t   h(    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   open_gzipsafej   s(    

(*   t
   __future__R    RU   RA   R$   t	   itertoolsR   t   os.pathR   R   R   t   collectionsR   t   ImportErrort%   quast_libs.site_packages.ordered_dictRD   R   t   quast_libs.qutilsR   R   R	   t   quast_libs.logR
   t   LOGGER_DEFAULT_NAMER   t   LIBS_LOCATIONR   R   t!   intergenomic_misassemblies_by_asmt   contigs_aligned_lengthsR   R   R   R   R   R    R#   R)   R=   RI   RN   RZ   (    (    (    sF   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/ca_utils/misc.pyt   <module>   s8   					
		