
bc           @   s  d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 e
 e j  Z e Z y d  d l Z WnH e k
 r y d  d l Z Wq e k
 r e j d  e Z q Xn Xd Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, d    Z- d!   Z. d"   Z/ d#   Z0 d S($   iN(   t   join(   t   qutilst   qconfig(   t   ref_labels_by_chromosomes(   t
   get_loggers:   Can't build html report - please install python-simplejsons   report.jsons   contigs_lengths.jsons   ref_length.jsons   tick_x.jsons   aligned_contigs_lengths.jsons   assemblies_lengths.jsons   _in_contigs.jsons   gc.jsons
   krona.jsons   icarus.jsons   .jsont    c         C   s_   t  r
 d  St j j |   r, t j |   n  t |  d  } t j | | d d | j	   |  S(   Nt   wt
   separatorst   ,t   :(   R   R	   (
   t   simplejson_errort   Nonet   ost   patht   existst   removet   opent   jsont   dumpt   close(   t   fpatht   whatt	   json_file(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save+   s    
c         C   s*   t  |  d  } | j |  | j   |  S(   NR   (   R   t   writeR   (   R   R   R   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_as_text8   s    
c         C   s   d d l  m } t j j   } t t |  t  i | j d  d 6g  d 6| r] t j	 |  n d d 6g  d 6d  d	 6g  d
 6g  d 6| d 6 S(   Ni(   t	   reportings   %d %B %Y, %A, %H:%M:%St   datet   assembliesNamesR   t   referenceNamet   ordert   reportt   subreferencest
   subreportst	   minContig(   t
   quast_libsR   t   datetimet   nowR   R    t   total_report_fnamet   strftimeR   t   name_from_fpathR   (   t   output_dirpatht
   min_contigt	   ref_fpathR   t   t(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_empty_report?   s    c         C   sa  d d l  m } g  | j D] } t j |  ^ q } | j | j j  } g  } g  } t j	 r t
 r t t t g  t
 j   D] }	 |	 ^ q{    } g  | D]! }
 | j | j j d |
 ^ q } n  t j j   } t t |  t  i | j d  d 6| d 6| rt j |  n d d 6g  t |  D] \ } } | ^ q(d	 6| d
 6| d 6| d 6| d 6 S(   Ni(   R   t   ref_names   %d %B %Y, %A, %H:%M:%SR   R   R   R   R   R   R    R!   R"   (   R#   R   t   assembly_fpathsR   t   label_from_fpatht   tablet   Fieldst   grouped_orderR   t   is_combined_refR   t   sortedt   listt   sett   valuesR$   R%   R   R    R&   R'   R(   t	   enumerate(   R)   R*   R+   R   t   thist	   asm_namesR   R!   t	   ref_namest   refR.   R,   t   it   _(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_total_reportO   s$    %11&c         C   se   g  | D] } t  | d t ^ q } t t |  t  i g  | D] } t j |  ^ q> d 6| d 6 S(   Nt   reverset	   filenamest   lists_of_lengths(   R5   t   TrueR   R    t   contigs_lengths_fnR   R0   (   R)   t   contigs_fpathsRC   R6   t   label(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_contigs_lengths   s    %#c         C   s   t  t |  t  i | d 6 S(   Nt   reflen(   R   R    t   ref_length_fn(   R)   t   reference_lengths(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_reference_lengths   s    c         C   s   t  t |  t  i | d 6 S(   Nt   tickX(   R   R    t	   tick_x_fn(   R)   t   tick_x(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_tick_x   s    c         C   sQ   | t  } t t |  |  i | d 6| d 6g  | D] } t j |  ^ q1 d 6 S(   Nt   coord_xt   coord_yRB   (   t	   suffix_fnR   R    R   R0   (   R)   RQ   RR   t
   name_coordRF   t   coord_fnRG   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt
   save_coord   s
    
c         C   s   t  t |  | t  |  S(   N(   R   R    RS   (   R)   t   filenamet   record(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_record   s    c         C   s@   d | t  } t t |  |  i | d 6| d 6| d 6| d 6 S(   Nt   coordRQ   RR   RB   t   refnames(   RS   R   R    (   R)   RQ   RR   RT   t   labelst
   refs_namesRU   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_meta_summary   s    c         C   s@   d | t  } t t |  |  i | d 6| d 6| d 6| d 6 S(   NRZ   RQ   RR   RB   R[   (   RS   R   R    (   R)   RQ   RR   RT   R\   R]   RU   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_meta_misassemblies   s    c         C   s@   t  t |  t  i g  | D] } t j |  ^ q d 6| d 6 S(   NRB   t   assemblies_lengths(   R   R    t   assemblies_lengths_fnR   R0   (   R)   RF   R`   RG   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_assembly_lengths   s    #c         C   sm   t  t |  | t  i g  | D] } t j |  ^ q d 6t d   | j   D  | d 6| d | d 6 S(   NRB   c         s   s*   |  ]  \ } } t  j |  | f Vq d  S(   N(   R   R0   (   t   .0t   contigs_fpatht   feature_amounts(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pys	   <genexpr>   s   t   _in_contigst   ref_t   _number(   R   R    t   in_contigs_suffix_fnR   R0   t   dictt   items(   R)   RF   t   feature_namet   features_in_contigst   ref_features_numRG   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_features_in_contigs   s
    #	c         C   sU   t  t |  t  i g  | D] } t j |  ^ q d 6| d 6| d 6| d 6d  d 6 S(   NRB   t   reference_indext   list_of_GC_distributionst    list_of_GC_contigs_distributionst   lists_of_gc_info(   R   R    t   gc_fnR   R0   R   (   R)   RF   Rq   Rr   Rp   RG   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_GC_info   s    #c         C   s$   t  t |  t  i | d 6| d 6 S(   Nt
   assembliest   paths(   R   R    t   krona_fn(   R)   t   krona_fpathsR\   (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_krona_paths   s    c         C   s,   t  t |  t  i | d d 6| d d 6 S(   Nt   linkst   links_names(   R   R    t	   icarus_fn(   R)   t   icarus_links(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_icarus_links   s    c         C   sA   | r  t  t |  | t  |  St t |  | t  i | | 6 S(   N(   R   R    RS   R   (   R)   t   keywordt   icarus_datat   as_text(    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   save_icarus_data   s    (1   R$   R   t   os.pathR    R#   R   R   t   quast_libs.ca_utils.miscR   t   quast_libs.logR   t   LOGGER_DEFAULT_NAMEt   logt   FalseR
   R   t   ImportErrort
   simplejsont   warningRD   R&   RE   RJ   RN   t   aligned_contigs_fnRa   Ri   Rt   Rx   R}   RS   t	   json_textR   R   R-   R@   RH   RL   RP   RV   RY   R^   R_   Rb   Ro   Ru   Rz   R   R   (    (    (    sN   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/html_saver/json_saver.pyt   <module>   sX   				6																		