
+[c           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z d   Z d   Z e d	 k r e   n  d S(
   s  
.. module:: run_BUSCO
   :synopsis: BUSCO - Benchmarking Universal Single-Copy Orthologs.
.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

This is the BUSCO main script.

To get help, ``python run_BUSCO.py -h``. See also the user guide.

And visit our website `<http://busco.ezlab.org/>`_

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

iN(   t   BuscoConfig(   t   RawTextHelpFormatter(   t   isdir(   t   is_non_empty_filec          C   s0  t  j d d t j d d d t d t  }  |  j d  } | j d d	 d
 d d t d d d d | j d d d
 d d t d d d d | j d d d
 d d t d d d d | j d d d
 d d t d d d t d d t j	 d | j d  d! d
 d" d t d d# d d$ | j d% d& d
 d' d t d d( d d) | j d* d+ d, d- d t d
 d. d d/ | j d0 d1 d, d- d t d
 d2 d d3 | j d4 d5 d t d
 d6 d d7 d d8 | j d9 d t d
 d: d d; | j d< d= d d> d t d
 d? d d@ t j	 d? | j dA d
 dB d dC d t d t
 d dD t t j	 dB  | j dE d, d- d t d
 dF d dG | j dH dI d
 dJ d t d dK d, d- | j dL dM d
 dN d t d dO d, d- | j dP d
 dQ d t d dR d, d- | j dS dT d, dU d dV dU dW t j | j dX dY d, d d dZ t |  j    S([   s   
    This function parses the arguments provided by the user
    :return: a dictionary having a key for each arguments
    :rtype: dict
    t   descriptions   Welcome to BUSCO %s: the Benchmarking Universal Single-Copy Ortholog assessment tool.
For more detailed usage information, please review the README file provided with this distribution and the BUSCO user guide.t   usagesZ   python BUSCO.py -i [SEQUENCE_FILE] -l [LINEAGE] -o [OUTPUT_NAME] -m [MODE] [OTHER OPTIONS]t   formatter_classt   add_helps   optional argumentss   -is   --int   destt   int   requiredt   metavars
   FASTA FILEt   helps   Input sequence file in FASTA format. Can be an assembled genome or transcriptome (DNA), or protein sequences from an annotated gene set.s   -cs   --cput   cput   Ns7   Specify the number (N=integer) of threads/cores to use.s   -os   --outt   outt   OUTPUTs   Give your analysis run a recognisable short name. Output folders and files will be labelled with this name. WARNING: do not provide a paths   -es   --evaluet   evaluet   typesR   E-value cutoff for BLAST searches. Allowed formats, 0.001 or 1e-03 (Default: %.0e)s   -ms   --modet   modet   MODEs   Specify which BUSCO analysis mode to run.
There are three valid modes:
- geno or genome, for genome assemblies (DNA)
- tran or transcriptome, for transcriptome assemblies (DNA)
- prot or proteins, for annotated gene sets (protein)s   -ls   --lineage_patht   lineage_patht   LINEAGEsk   Specify location of the BUSCO lineage data to be used.
Visit http://busco.ezlab.org for available lineages.s   -fs   --forcet   actiont
   store_truet   forcesg   Force rewriting of existing files. Must be used when output files with the provided name already exist.s   -rs	   --restartt   restarts>   Restart an uncompleted run. Not available for the protein modes   -sps	   --speciest   speciest   SPECIESsl   Name of existing Augustus species gene finding parameters. See Augustus documentation for available options.s   --augustus_parameterst   augustus_parameterss   Additional parameters for the fine-tuning of Augustus run. For the species, do not use this option.
Use single quotes as follow: '--param1=1 --param2=2', see Augustus documentation for available options.s   -ts
   --tmp_patht   PATHt   tmp_paths,   Where to store temporary files (Default: %s)s   --limitt   limitt   REGION_LIMITsU   How many candidate regions (contig or transcript) to consider per BUSCO (default: %s)s   --longt   longs   Optimization mode Augustus self-training (Default: Off) adds considerably to the run time, but can improve results for some non-model organismss   -qs   --quiett   quiets+   Disable the info logs, displays only errorss   -zs   --tarzipt   tarzips>   Tarzip the output folders likely to contain thousands of filess   --blast_single_coret   blast_single_cores   Force tblastn to run on a single core and ignore the --cpu argument for this step only. Useful if inconsistencies when using multiple threads are noticeds   -vs	   --versiont   versions   Show this version and exits   BUSCO %ss   -hs   --helps   Show this help message and exit(   t   argparset   ArgumentParserR    t   VERSIONR   t   Falset   add_argument_groupt   add_argumentt   floatt   DEFAULT_ARGS_VALUESt   intt   strt   varst
   parse_args(   t   parsert   optional(    (    sD   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/busco.pyt   _parse_args#   st    	
""!	c         C   sF  t  j    } t j j d  rT t j t j j d  t j  rT t j j d  } n" d t j j t j j t	   } t
 | d i |  d 6| d 6} t j j | j d d  d |  } t |  s t j |  n  t j j | d	 |  } d
 d l m } | | j _ d
 d l m } d
 d l m }	 d
 d l m }
 |	 j j   |	 j } t |  rw| j d | d  | Sy y | j d t
 j t  j d  f  | j d |  | |  } | j   | j   s| j d t  t  j    |   n! | j d t  t  j    |   | j d | j!  Wn& |
 k
 rU} | j" |  t#  n XWn t# k
 r| j" d  | j" d t
 j$  t#  n t% k
 r| j" d  | j" d  | j" d t
 j$  t#  nm t& k
 rAt' j(   \ } } } | j) d t* j+ | | |   | j" d  | j" d t
 j$  t#  n X| S(   s   
    This function runs a BUSCO analysis according to the provided parameters.
    See the help for more details:
    ``python run_BUSCO.py -h``
    :raises SystemExit: if any errors occur
    t   BUSCO_CONFIG_FILEs   %s//config.ini.defaultt   argsR	   R   t   buscot   out_paths   run_%ss   short_summary_%s.txti(   t
   pipebricks(   t   GenomeAnalysis(   t   BuscoAnalysis(   t   ToolExceptions   Using existing BUSCO files for s   ...sQ   ****************** Start a BUSCO %s analysis, current time: %s ******************s   %m/%d/%Y %H:%M:%Ss   Configuration loaded from %ss3   BUSCO analysis done. Total running time: %s secondssC   BUSCO analysis done with WARNING(s). Total running time: %s secondss   Results written in %s
s   BUSCO analysis failed !sa   Check the logs, read the user guide, if you still need technical support, then please contact %s
s%   A signal was sent to kill the processs!   Unhandled exception occurred: %s
(,   t   timet   ost   environt   gett   accesst   R_OKt   patht   dirnamet   realpatht   __file__R    t   joinR   t   makedirst   quast_libs.buscoR:   t
   PipeLoggert   run_dirpatht   quast_libs.busco.GenomeAnalysisR;   t   quast_libs.busco.BuscoAnalysisR<   t#   quast_libs.busco.pipebricks.ToolsetR=   t   _loggert
   reload_logR   t   infoR)   t   strftimet   run_analysist   has_warningR0   t   mainoutt   errort
   SystemExitt   CONTACTt   KeyboardInterruptt   BaseExceptiont   syst   exc_infot   criticalt	   tracebackt   format_exception(   t   in_fpatht	   out_fnamet
   start_timet   config_filet   configt   assembly_dirpatht   summary_pathR:   R;   R<   R=   t   loggert   analysist   et   exc_typet	   exc_valuet   exc_traceback(    (    sD   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/busco.pyt   main   st    3" %	
$			
t   __main__(   t   __doc__R>   R_   R\   R?   R'   t   loggingt   quast_libs.busco.BuscoConfigR    R   t   os.pathR   t   quast_libs.qutilsR   R5   Rn   t   __name__(    (    (    sD   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/busco/busco.pyt   <module>   s   	j	V