#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""A script to export a FASTA file of contigs (or splits) from a contigs database."""

import sys
import argparse

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

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


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

def main(args):
    utils.export_sequences_from_contigs_db(args.contigs_db, args.output_file, splits_mode=args.splits_mode)
    run.info('Export mode', 'splits' if args.splits_mode else 'contigs')
    run.info('Output FASTA', args.output_file)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Export contigs (or splits) from an anvi'o contigs database")

    parser.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db'))
    parser.add_argument('--splits-mode', default=False, action="store_true", help="Export split\
                        sequences instead.")
    parser.add_argument(*anvio.A('output-file'), **anvio.K('output-file', {'required': True}))

    args = parser.parse_args()

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