
+[c           @   s   d  Z  d d l Z d d l m Z d d l m Z d d l m Z yT d d l m	 Z	 d d l m
 Z
 d d l m Z d d	 l m Z d d
 l m Z WnA e k
 r d d l m	 Z	 d d l m
 Z
 d d l m Z n Xd e f d     YZ d S(   s'  
.. module:: BuscoConfig
   :synopsis: Load and combine all parameters provided to BUSCO through config file, dataset and command line
.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

Copyright (c) 2016-2017, Evgeny Zdobnov (ez@ezlab.org)
Licensed under the MIT license. See LICENSE.md file.

iN(   t
   PipeConfig(   t
   PipeLogger(   t   busco(   t   NoOptionError(   t   NoSectionError(   t   ParsingError(   t   DuplicateSectionError(   t   DuplicateOptionErrort   BuscoConfigc        '   B   s  e  Z d  Z d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d d d d d  d! d" d# g' Z d$ d% g Z d& Z d' Z e j Z	 d( Z
 i d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6e j   d3 6d4 d5 6d6 d7 6d6 d8 6d6 d9 6d6 d: 6d; d< 6e d= 6e d> 6e d? 6e d@ 6e dA 6e dB 6e dC 6Z dD dE dF dG g Z e j e   Z e dH  Z e dI    Z e dJ    Z RS(K   sL  
    This class extends pipebricks.PipeConfig to read the config.ini.default file. Furthermore, it uses extra args that can be
    provided through command line and information available in the dataset.cfg file to produce a single instance
    containing all correct parameters to be injected to a busco.BuscoAnalysis instance.
    s   çs   ¬s   ¢s   ´s   ês   îs   ôs   ŵs   ẑs   ûs   âs   ŝs   ĝs   ĥs   ĵs   ŷs   ĉs   és   ïs   ẅs   ës   ẗ,s   üs   ís   ös   ḧs   ÿs   ẍs   ès   às   äs   ¨s   €s   £s   át   /s   'g@i N  s   mailto:support@orthodb.orgi   t   cpugMbP?t   evaluet   flyt   speciess   ./tmp/t   tmp_pathi   t   limitt   out_patht	   eukaryotat   domains   N/At
   clade_namet   dataset_creation_datet   dataset_nb_buscost   dataset_nb_speciest    t   augustus_parameterst   longt   restartt   quiett   debugt   forcet   tarzipt   blast_single_coret   int   outt   lineage_patht   modec         C   s  y t  t |   j |  Wn t k
 rq y t j |  |  Wq t k
 rm } t j j d |  t  q Xn t	 k
 r } t j j d |  t  nY t
 k
 r } t j j d |  t  n- t k
 r } t j j d |  t  n Xywxz | D]r } | | d& k	 rLt | |  t k	 rL|  j d | t | |   q | | t k r |  j d | d  q q W| rxV t j D]H } y |  j d |  Wqt k
 rt j j d |  t  qXqWn  xQ |  j d  D]@ } | d j d  r|  j d | d t j | d   qqWd& } yat d	 |  j d d
   }	 x|	 D]}
 |
 j d  d d k r|  j d d |
 j   j d  d  qU|
 j d  d d k ry |  j d d  WqPt k
 r|  j d d |
 j   j d  d  qPXqU|
 j d  d d k ry |  j d d  Wn7 t k
 rm|  j d d |
 j   j d  d  n X|
 j   j d  d } qU|
 j d  d d k r|  j d d |
 j   j d  d  qU|
 j d  d d k r|  j d d |
 j   j d  d  qU|
 j d  d d k rU|  j d d |
 j   j d  d  qUqUW| r| d k r| d k rt j j d |  t  n  WnB t k
 r| rt j j d t j d t j d f  qn Xxe t t j j    D]N } y |  j d |  Wqt k
 r8|  j d | t t j |   qXqWxQ |  j d  D]@ } | d j d  rM|  j d | d t j | d   qMqMW| r>x |  j   D] } x |  j |  D]y } | d j d  s| d d k s| d d k r| d j  d  r3|  j | | d t! j" j# | d   q3qqWqWn  | rxN |  j d  D]: } | d d
 k sz| d d k rTt j$ | d  qTqTWn  | rd |  j d d  k rt j j d  t  qn  | r1|  j% d d   d k s|  j% d d   d! k r1t j j d" |  j% d d    t  q1n  | rl|  j& d d#  t j d# k rlt j j d$  qln  Wn; t' k
 rt j j d% |  t  n t k
 rn Xx' |  j d  D] } t j j( |  qWd& S('   s  
        :param conf_file: a path to a config.ini.default file
        :type conf_file: str
        :param args: key and values matching BUSCO parameters to override config.ini.default values
        :type args: dict
        :param checks: whether to proceed to the mandatory parameters + file dependencies checks,
         used in a main BUSCO analysis. Default True
        :type checks: bool
        s   Error in the config file: %ss3   Duplicated entry in the config.ini.default file: %sR   t   Truesn   The parameter '--%s' was not provided. Please add it in the config file or provide it through the command linei    t   _pathi   s   %sdataset.cfgR"   t   =t   nameR   R   R   t   creation_dateR   t   number_of_BUSCOsR   t   number_of_speciesR   t
   prokaryotaR   sK   Corrupted dataset.cfg file: domain is %s, should be eukaryota or prokaryotas   The dataset you provided does not contain the file dataset.cfg, likely because it is an old version. Default species (%s, %s) will be used as augustus speciest   pathR    t   ~R	   R!   s   Please do not provide a full path in --out parameter, no slash. Use out_path in the config.ini.default file to specify the full path.R   i   sz   Limit must be an integer between 1 and 20 (you have used: %s). Note that this parameter is not needed by the protein mode.R   s%   You are using a custom e-value cutoffse   No section [busco] found in %s. Please make sure both the file and this section exist, see userguide.N()   t   superR   t   __init__t	   TypeErrorR    R   t   _loggert   errort
   SystemExitR   R   t   Nonet   typet   boolt   sett   strR$   t   MANDATORY_USER_PROVIDED_PARAMSt   getR   t   itemst   endswitht	   nice_patht   opent   splitt   stript   IOErrort   warningt   DEFAULT_ARGS_VALUESt   listt   keyst   sectionst
   startswitht   osR,   t
   expandusert   check_path_existt   getintt   getfloatR   R   (   t   selft	   conf_filet   argst   checkst   et   keyt   paramt   itemR   t   target_species_filet   l(    (    sJ   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/BuscoConfig.pyR/   >   s    
		
& +)-*))-	
(+38 0	c         C   s3   t  j j |   s/ t j j d |   t  n  d S(   s   
        This function checks whether the provided path exists
        :param path: the path to be tested
        :type path: str
        :raises SystemExit: if the path cannot be reached
        s   Impossible to read %sN(   RH   R,   t   existsR   R1   R2   R3   (   R,   (    (    sJ   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/BuscoConfig.pyRJ      s    c         C   s>   y% |  d d k r  |  d 7}  n  |  SWn t  k
 r9 d SXd S(   s   
        :param path: a path to check
        :type path: str
        :return: the same but cleaned path
        :rtype str:
        iR	   N(   R0   R4   (   R,   (    (    sJ   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/BuscoConfig.pyR=      s    (   t   __name__t
   __module__t   __doc__t   FORBIDDEN_HEADER_CHARSt#   FORBIDDEN_HEADER_CHARS_BEFORE_SPLITt   HMMER_VERSIONt	   MAX_FLANKR   t   __version__t   VERSIONt   CONTACTRH   t   getcwdt   FalseRC   R9   R   t
   get_loggerR1   R$   R/   t   staticmethodRJ   R=   (    (    (    sJ   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/BuscoConfig.pyR      s(   03	&#(   RZ   RH   t&   quast_libs.busco.pipebricks.PipeConfigR    t&   quast_libs.busco.pipebricks.PipeLoggerR   t
   quast_libsR   t   configparserR   R   R   R   R   t   ImportErrort   ConfigParserR   (    (    (    sJ   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/BuscoConfig.pyt   <module>   s   