#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""Summarizer for anvi'o SAAVs over protein structures."""

import sys

import anvio
import anvio.terminal as terminal
import anvio.summarizer as summarizer

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):
    summary = summarizer.SAAVsAndProteinStructuresSummary(args)
    summary.process()


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description="Generate a static web site for SAAVs and protein structures.")

    groupA = parser.add_argument_group("CONTIGS DB", "If you provide a contigs database, anvi'o will findout about\
                                        functions and other properties of genes using the contigs database. This is\
                                        supposed to be the contigs database you used to generate variability profile\
                                        for this project like 2 years ago. Yeah. Time goes by :/")
    groupA.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db', {'required': False}))

    groupB = parser.add_argument_group('WHAT SHOULD BE PROCESSED', "By default, anvi'o will learn about the genes and\
                                        samples you have from the input data directory. If you want to overwrite that\
                                        information (i.e. to work with a smaller set of genes or samples), you can\
                                        come up with your own files.")
    groupB.add_argument('--genes', type=str, help="Genes file.", metavar="FILE")
    groupB.add_argument('--samples', type=str, help="Samples file.", metavar="FILE")


    groupC = parser.add_argument_group('INPUT/OUTPUT', "Read from here, write to there.")
    groupC.add_argument(*anvio.A('input-dir'), **anvio.K('input-dir', {'required': True}))
    groupC.add_argument(*anvio.A('output-dir'), **anvio.K('output-dir', {'required': True}))

    groupD = parser.add_argument_group('ADDITIONAL STUFF', "Little conveniences.")
    groupD.add_argument('--soft-link-images', default=False, action="store_true", help="By default, your imaeges\
                        will be copied in the output directory to create a fully self-contained output (so you can\
                        send it to your colleagues and they would have everything they need to browse the output).\
                        Alternatively you can use this flag to avoid copying images in the output directory (it\
                        would make the output less portable, but it would take less time and space to generate it).")
    groupD.add_argument('--perspectives', default=None, help="By default anvi'o will use each perspective found in the\
                        data directory to create an HTML output. Using this parameter you can limit perspectives to\
                        the ones you are interested in by defining them as a commma-separated list. If you make a\
                        mistake anvi'o will tell you what are the available perspectives, so don't worry.")



    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)
