#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2011, A. Murat Eren
#
# 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 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.


import os

import IlluminaUtils.utils.helperfunctions as h


if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser(description='Visualize Qual Dicts')
    parser.add_argument('qual_dict', metavar = 'QUAL_DICT',
                                        help = 'cPickle dictionary that contains quality score info')
    parser.add_argument('-p', '--prefix', metavar = 'FILE PREFIX', default = None,
                                        help = 'Prefix for the output file(s)')
    parser.add_argument('--title', metavar = 'TITLE', default = None,
                                        help = 'Title to appear at the top of the figure')
    parser.add_argument('--split-tiles', action = 'store_true', default = False,
                                        help = 'When set, quality curves will be shown separately for each tile')

    args = parser.parse_args()
    
    qual_dict = h.load_cPickle_obj(args.qual_dict)
    prefix = args.prefix if args.prefix else args.qual_dict
    title = args.title if args.title else os.path.basename(args.qual_dict)
    split_tiles = args.split_tiles

    for reason in qual_dict:
        h.visualize_qual_stats_dict(qual_dict[reason], '%s_%s' % (prefix, reason), '%s [%s]' % (title, reason), split_tiles)

