#!/usr/bin/env python
###############################################################################
#                                                                             #
#    bitterGravel                                                             #
#                                                                             #
#    contig length anaysis and image generation                               #
#                                                                             #
#    Copyright (C) Michael Imelfort                                           #
#                                                                             #
###############################################################################
#                                                                             #
#    This program is free software: you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation, either version 3 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program. If not, see <http://www.gnu.org/licenses/>.     #
#                                                                             #
###############################################################################

__author__ = "Michael Imelfort"
__copyright__ = "Copyright 2014"
__credits__ = ["Michael Imelfort"]
__license__ = "GPLv3"
__version__ = "1.0.0"
__maintainer__ = "Michael Imelfort"
__email__ = "mike@mikeimelfort.com"

###############################################################################
###############################################################################
###############################################################################
###############################################################################

# system includes
import argparse
import sys

# local includes
from bittergravel.lenTools import LenStatMaker

###############################################################################
###############################################################################
###############################################################################
###############################################################################

def doWork(args):
    """Wrapper function to allow easy profiling"""
    LSM = LenStatMaker()
    LSM.parseAllFiles(args.files, subSample=args.subSample)
    LSM.plot2DFigure(fileName=args.plotName, groupNames=args.groupNames)

###############################################################################
###############################################################################
###############################################################################
###############################################################################

if __name__ == '__main__':
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('files', nargs='+', help="Files to parse space separated groups, groups separated by commas. Up to 4 groups")
    parser.add_argument('--groupNames', nargs='+', default=[], help="Names of each group used when plotting")
    parser.add_argument('--plotName', default='', help="Name of the file to plot to")
    parser.add_argument('--subSample', default=0, type=int, help="Only process the first XX reads (0 for all)")

    # parse the arguments
    args = parser.parse_args()

    # profiling happens here. If you'd like to track the speed your code runs at
    # then set the following to True and voila!
    if(False):
        import cProfile
        cProfile.run('doWork(args)', 'profile')
        ##########################################
        ##########################################
        # Use this in python console!
        #import pstats
        #p = pstats.Stats('prof')
        #p.sort_stats('cumulative').print_stats(10)
        #p.sort_stats('time').print_stats(10)
        ##########################################
        ##########################################
    else:
        doWork(args)

###############################################################################
###############################################################################
###############################################################################
###############################################################################

