#!/usr/bin/env python
# -*- coding: utf-8
"""Script to merge multiple profiles."""

import sys
import argparse

import anvio
import anvio.merger as merger

from anvio.errors import ConfigError, FilesNPathsError


__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='Merge multiple anvio profiles')

    parser.add_argument('input', metavar = 'RUNINFO_FILE', nargs='+',
                        help = 'anvio RUNINFO files to create a merged output')

    parser.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db'))
    parser.add_argument(*anvio.A('output-dir'), **anvio.K('output-dir'))
    parser.add_argument(*anvio.A('sample-name'), **anvio.K('sample-name'))
    parser.add_argument(*anvio.A('skip-hierarchical-clustering'), **anvio.K('skip-hierarchical-clustering'))
    parser.add_argument(*anvio.A('enforce-hierarchical-clustering'), **anvio.K('enforce-hierarchical-clustering'))
    parser.add_argument(*anvio.A('skip-concoct-binning'), **anvio.K('skip-concoct-binning'))
    parser.add_argument(*anvio.A('overwrite-output-destinations'), **anvio.K('overwrite-output-destinations'))
    parser.add_argument(*anvio.A('debug'), **anvio.K('debug'))

    args = parser.parse_args()

    try:
        merger.MultipleRuns(args).merge()
    except ConfigError, e:
        print e
        sys.exit(-1)
    except FilesNPathsError, e:
        print e
        sys.exit(-1)
