#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""Adds a DEAFULT collection with EVERYTHING in it into a pan or profile database."""

import sys
import argparse

import anvio
import anvio.utils as utils
import anvio.terminal as terminal

from anvio.errors import ConfigError, FilesNPathsError
from anvio.tables.collections import TablesForCollections


__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"


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


def main(args):
    utils.is_pan_or_profile_db(args.pan_or_profile_db)

    all_items = utils.get_all_item_names_from_the_database(args.pan_or_profile_db)

    collections_table = TablesForCollections(args.pan_or_profile_db)
    collections_table.append('DEFAULT', {'EVERYTHING': all_items})

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="A script to add a 'DEFAULT' collection in an anvi'o pan or profile database with a bin\
                                                  named 'EVERYTHING' that describes all items available in the profile databse.")

    parser.add_argument(*anvio.A('pan-or-profile-db'), **anvio.K('pan-or-profile-db'))

    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)
