#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8

import sys

import anvio

from anvio.contigops import GenbankToAnvioWrapper
from anvio.errors import ConfigError, FilesNPathsError


__author__ = "Developers of anvi'o (see AUTHORS.txt)"
__copyright__ = "Copyleft 2015-2019, the Meren Lab (http://merenlab.org/)"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "a.murat.eren@gmail.com"


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description="This script takes the 'metadata' output of the program `ncbi-genome-download` (see\
                                                  https://github.com/kblin/ncbi-genome-download for details), and processes each\
                                                  GenBank file found in the metadata file to generate a FASTA file, as well as genes\
                                                  and functions files for each entry. Plus, it autmatically generates a FASTA TXT\
                                                  file descriptor for anvi'o snakemake workfloes. So it is a multi-talented program\
                                                  like that.")


    groupA = parser.add_argument_group('INPUT', 'Give us the preciousss...')
    groupA.add_argument('-m', '--metadata', required=True, help='This is the file you get from the\
                            program `ncbi-genome-download` when you use the parameter `--metadata-table`.',
                            metavar='GENBANK_METADATA')

    groupB = parser.add_argument_group('OUTPUT', "Where to find your precioussesss...")
    groupB.add_argument(*anvio.A('output-dir'), **anvio.K('output-dir'))
    groupB.add_argument('--output-fasta-txt', help="This is not a FASTA file, but a TAB-delimited file with all\
                            the file names and paths processed by this program. This output can directly go into\
                            the anvi'o snakemake workflows because magic.", metavar='OUTPUT_FASTA_TXT')

    args = anvio.get_args(parser)

    try:
        genbank_to_anvio = GenbankToAnvioWrapper(args)
        genbank_to_anvio.process()
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-2)
