#!/usr/bin/env 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__ = "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"


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('samples-information'), **anvio.K('samples-information'))
    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 = parser.parse_args()
    
    try:
        variable_nt_positions = VariabilityNetwork(args)
        variable_nt_positions.generate()
    except ConfigError, e:
        print e
        sys.exit(-1)
    except FilesNPathsError, e:
        print e
        sys.exit(-2)
