#!/usr/bin/env python
# -*- coding: utf-8

"""The client for LinkMers class.

   See https://github.com/meren/anvio/issues/144 for details."""

import sys

import anvio

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


__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__':
    import argparse

    parser = argparse.ArgumentParser(description='Access reads in contigs and positions in a BAM file')

    parser.add_argument('-i', '--input-files', metavar = 'INPUT_BAM(S)', nargs='+', default = None, required = True,
                        help = 'Sorted and indexed BAM files to analyze. It is essential that all BAM files must be\
                                the result of mappings against the same contigs.')

    parser.add_argument(*anvio.A('contigs-and-positions'), **anvio.K('contigs-and-positions'))
    parser.add_argument(*anvio.A('only-complete-links'), **anvio.K('only-complete-links'))
    parser.add_argument(*anvio.A('output-file'), **anvio.K('output-file', {'required': True}))
    parser.add_argument(*anvio.A('list-contigs'), **anvio.K('list-contigs'))

    args = parser.parse_args()

    try:
        r = LinkMers(args)
        r.process()
        r.report(args.output_file)
    except ConfigError, e:
        print e
        sys.exit(-1)
    except FilesNPathsError, e:
        print e
        sys.exit(-2)
  
