#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""Get amino acid sequences identified during the gene calling."""

import os
import sys
import argparse

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

from anvio.errors import ConfigError, FilesNPathsError


__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):
    gene_caller_ids = utils.get_gene_caller_ids_from_args(args.gene_caller_ids, args.delimiter)

    dbops.export_aa_sequences_from_contigs_db(args.contigs_db, args.output_file, gene_caller_ids=gene_caller_ids)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Get amino acid sequences from a contigs database for all gene calls.")

    parser.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db'))
    parser.add_argument(*anvio.A('output-file'), **anvio.K('output-file'))
    parser.add_argument(*anvio.A('gene-caller-ids'), **anvio.K('gene-caller-ids'))
    parser.add_argument(*anvio.A('delimiter'), **anvio.K('delimiter'))

    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(-1)
