#!/usr/bin/env python
# -*- coding: utf-8
"""Get protein sequences identified during the gene calling."""

import sys
import argparse

import anvio
import anvio.tables as t
import anvio.terminal as terminal
import anvio.filesnpaths as filesnpaths

from anvio.errors import ConfigError, FilesNPathsError
from anvio.tableops import Table


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


def main(args):
    filesnpaths.is_file_exists(args.contigs_db)

    class T(Table):
        def __init__(self, db_path, version, run=run, progress=progress):
            Table.__init__(self, db_path, version, run, progress)

    h = T(args.contigs_db, anvio.__contigs__version__)
    h.export_sequences_table_in_db_into_FASTA_file(t.gene_protein_sequences_table_name, output_file_path = args.output_file)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Get protein 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'))

    args = parser.parse_args() 
    
    try:
        main(args)
    except ConfigError, e:
        print e
        sys.exit(-1)
    except FilesNPathsError, e:
        print e
        sys.exit(-1)
