#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""Return counts of AAs in bins, contigs, or gene caller ids"""

import sys

import anvio
import anvio.terminal as terminal

from anvio.errors import ConfigError, FilesNPathsError
from anvio.dbops import AA_counts


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


run = terminal.Run()
progress = terminal.Progress()


def main(args):
    aa_counts = AA_counts(args)
    aa_counts.report()


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description='Collects AA counts information from a contigs database\
                                                  for a given bin, set of contigs, or set of genes.')

    group0 = parser.add_argument_group('MANDATORY STUFF', 'You have to set the following two parameters, then\
                                                           you will select one set of parameters from the\
                                                           following optional sections. If you select nothing\
                                                           from those sets, AA counts for everything in the\
                                                           contigs database will be reported.')
    group0.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db', {'required': True}))
    group0.add_argument(*anvio.A('output-file'), **anvio.K('output-file'))

    groupA = parser.add_argument_group('OPTIONAL PARAMS FOR BINS')
    groupA.add_argument(*anvio.A('profile-db'), **anvio.K('profile-db', {'required': False}))
    groupA.add_argument(*anvio.A('collection-name'), **anvio.K('collection-name'))
    groupA.add_argument(*anvio.A('bin-ids-file'), **anvio.K('bin-ids-file'))

    groupB = parser.add_argument_group('OPTIONAL PARAMS FOR CONTIGS')
    groupB.add_argument(*anvio.A('contigs-of-interest'), **anvio.K('contigs-of-interest', {'help': "A file with\
                                                         contig names. There should be only one column in the file,\
                                                         and each line should correspond to a unique split name."}))

    groupC = parser.add_argument_group('OPTIONAL PARAMS FOR GENE CALLS')
    groupC.add_argument(*anvio.A('gene-caller-ids'), **anvio.K('gene-caller-ids'))

    args = anvio.get_args(parser)

    try:
        main(args)
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-2)
