#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8

"""A client to access short reads in BAM files.

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

import sys

import anvio

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


__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='Get short reads back from a BAM file.')

    parser.add_argument('input_bams', metavar = 'BAM FILE[S]', nargs='+',
                        help = 'BAM file(s) to access to recover short reads')

    parser.add_argument(*anvio.A('profile-db'), **anvio.K('profile-db'))
    parser.add_argument(*anvio.A('contigs-db'), **anvio.K('contigs-db'))
    parser.add_argument(*anvio.A('collection-name'), **anvio.K('collection-name'))
    parser.add_argument(*anvio.A('bin-id'), **anvio.K('bin-id'))
    parser.add_argument(*anvio.A('bin-ids-file'), **anvio.K('bin-ids-file'))
    parser.add_argument(*anvio.A('output-file'), **anvio.K('output-file'))
    parser.add_argument(*anvio.A('debug'), **anvio.K('debug'))

    args = parser.parse_args()

    try:
        r = GetReadsFromBAM(args)
        r.init()
        r.store_short_reads_for_splits()
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-2)
  
