#!/opt/anaconda1anaconda2anaconda3/bin/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__ = "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"
__requires__ = ['bam-file',]
__provides__ = ['linkmers-txt',]


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 = anvio.get_args(parser)

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