ó
‚™xTc           @   sÂ   d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l m	 Z	 d d l
 m Z m Z d d l Z d d l Z e j j d ƒ Z d	 d
 „ Z e d k r¾ e e j d ƒ n  d S(   s•   
Extracts R-free flags from reflection files.
Writes reflection count, free fraction pairs to file (for plotting).
Also shows free fraction in bins.
iÿÿÿÿ(   t   division(   t   reflection_file_utils(   t   reflection_file_readerN(   t   show_string(   t   Sorryt   Usages  r_free_flags_accumulation {
  file_name=None
    .type=path
  label=None
    .type=str
  test_flag_value=None
    .type=int
  disable_suitability_test=False
    .type=bool
}
r_free_flags_accumulation {
  output=None
    .type=path
  plot_header=None
    .type=str
    .multiple=True
}
s   iotbx.r_free_flags_accumulationc            s  ‡  f d †  } t  |  ƒ d k s9 d |  k s9 d |  k rC | ƒ  n  g  } t j d d ƒ } g  } xÆ |  D]¾ } t j j | ƒ r½ t j d | ƒ } | j ƒ  d  k	 r½ | j
 | ƒ d  } q½ n  | d  k	 rh y | j d | ƒ } Wn4 t k
 rõ ‚  q&t k
 rt d	 | ƒ ‚ q&X| j
 | ƒ qh qh Wt j d
 | ƒ j ƒ  }	 |	 j }
 t j d | ƒ } | j d |
 j d |
 j d |
 j d |
 j d d ƒ \ } } | j ƒ  j |
 _ | j ƒ  j ƒ  |
 _ | |
 _ |
 j d  k r÷t j j |
 j ƒ d |
 _ n  t j d |	 ƒ } | j ƒ  Hd GH| j  d | j! ƒ  |
 j k ƒ } | j" ƒ  H| j# d d ƒ j ƒ  } d t$ |
 j ƒ GHd GHd GHt% j& j' ƒ  t( |
 j d ƒ } x |
 j) D] } | | IJq¢Wx3 t* | j+ | j, ƒ D] \ } } | | I| IJqÌW| j- ƒ  Ht% j& j' ƒ  d  S(   Nc              s   t  d ˆ  ƒ ‚ d  S(   Ns    %s reflection_file [label=value](   R   (    (   t   command_name(    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/r_free_flags_accumulation.pyt   raise_usage$   s    i    s   --helps   -ht
   home_scopet   r_free_flags_accumulationt	   file_namet   args   Unknown file or keyword: %st   sourcest   reflection_filest   labelt   test_flag_valuet   disable_suitability_testt   parameter_scopes   .r_free_flags_accumulationt   python_objects   #phil __OFF__t   datat   by_valuet
   resolutions   Writing file: %ss4     1. column: reflection counts, sorted by resolutionsE     2. column: number of free reflections / total number of reflectionst   w(.   t   lent   master_paramst!   command_line_argument_interpretert   ost   patht   isfileR   t   any_reflection_filet	   file_typet   Nonet   appendt   processt   KeyboardInterruptt	   ExceptionR   t   fetcht   extractR	   R   t   reflection_file_servert   get_r_free_flagsR
   R   R   R   t   infot   sourcet   label_stringt   outputt   basenamet   formatt   showt   arrayR   t   show_r_free_flags_infot   sortR   t   syst   stdoutt   flusht   opent   plot_headert   zipt   reflection_countst   free_fractionst   close(   t   argsR   R   t   phil_objectst   argument_interpreterR   R   t	   refl_filet   command_line_paramst   params_scopet   paramst   srvt   r_free_flagsR   t   working_paramst   accut   outt   linet   ct   f(    (   R   sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/r_free_flags_accumulation.pyt   run#   sx    *
				   									
	
	"
t   __main__i   (   t   __doc__t
   __future__R    t   iotbxR   R   t   libtbx.philt   libtbxt   libtbx.str_utilsR   t   libtbx.utilsR   R   R2   R   t   philt   parseR   RJ   t   __name__t   argv(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/r_free_flags_accumulation.pyt   <module>   s   		=