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

import sys

import anvio
import anvio.dbops as dbops
import anvio.terminal as terminal

from anvio.errors import ConfigError, FilesNPathsError


__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2015, The anvio Project"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "a.murat.eren@gmail.com"


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


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser(description='Generate a new anvio contigs database.')

    parser.add_argument(*anvio.A('contigs-fasta'), **anvio.K('contigs-fasta'))
    parser.add_argument(*anvio.A('split-length'), **anvio.K('split-length'))
    parser.add_argument(*anvio.A('kmer-size'), **anvio.K('kmer-size'))
    parser.add_argument(*anvio.A('skip-gene-calling'), **anvio.K('skip-gene-calling'))
    parser.add_argument(*anvio.A('external-gene-calls'), **anvio.K('external-gene-calls'))
    parser.add_argument(*anvio.A('ignore-internal-stop-codons'), **anvio.K('ignore-internal-stop-codons'))
    parser.add_argument(*anvio.A('skip-mindful-splitting'), **anvio.K('skip-mindful-splitting'))
    parser.add_argument(*anvio.A('output-db-path'), **anvio.K('output-db-path', {'default': 'CONTIGS.db'}))
    parser.add_argument(*anvio.A('debug'), **anvio.K('debug'))

    args = parser.parse_args()

    try:
        a = dbops.ContigsDatabase(args.output_db_path, run, progress, quiet=False, skip_init = True)
        a.create(args)
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-2)
