#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""Creates a network file for a given variability profile output"""

import sys
import argparse

import anvio

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


__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"


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="A program to generate a network description from an anvi'o\
                                                  variability profile.")

    parser.add_argument('-i', '--input-file', metavar = 'VARIABILITY_PROFILE', required = True,
                        help = "The anvi'o variability profile. Please see `anvi-gen-variability-profile` to\
                                generate one.")
    parser.add_argument(*anvio.A('max-num-unique-positions'), **anvio.K('max-num-unique-positions'))
    parser.add_argument(*anvio.A('output-file'), **anvio.K('output-file', {'default': 'network.gexf'}))

    args = anvio.get_args(parser)

    try:
        variable_nt_positions = VariabilityNetwork(args)
        variable_nt_positions.generate()
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-2)
