# Path: nucio.py
# def lineRecordIterator(fh, nt, nt_types, filter_func=trueFunc, delim=None, cleaner_func=None):
# def lineItemIterator(fh, filter_func=trueFunc):
# def getNucmerAlignmentIterator(fh):
# def fileIterator(filename, itemIterator, open_func=open):
# def recordToString( record, delim="\t" ):
# def nucRecordToString(nuc_record):
# def typeify(mylist, mytypes):
# def prepareDeltaRecord(buf):
# def getDeltaAlignmentIterator(fh):
# def deltaRecordHeaderToString(dr):
# def deltaAlignmentHeaderToString(alignment):
# def deltaRecordToOriginalFormat(dr):
#     def __init__(self, s, *args ):
#     def __enter__(self):
#     def __exit__(self, ttype ,value, traceback):
# def openerFromExtension(filename, default=None):
# class FileOrStream:


import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from operator import attrgetter
from matplotlib.backends.backend_pdf import PdfPages
from mpl_toolkits.axes_grid1 import make_axes_locatable
from nucio import lineRecordIterator,M4Record, M4RecordTypes
from args import parseArgs, getHelpStr, CLArgument

description = ("Usage: graphpid.py [options] title alignments.m4\n\n"
               "Graph Alignments from blasr's m4 output")

argument_list = [["tophist_maxy", "tophist_maxy", int, -1,
                  "Maximum y value for top histogram"]]

arguments = map(CLArgument._make, argument_list)


if not len(sys.argv) > 1:
    sys.exit(getHelpStr(description, arguments) + "\n")

(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)

if not len(args_remaining) == 2:
    sys.exit(getHelpStr(description, arguments) + "\n")

igetter = attrgetter("pctsimilarity", "qseqlength")

mpl.rc('font', family='normal',weight="normal",
              size=10)
mpl.rc('xtick', labelsize=5)
mpl.rc('ytick', labelsize=5)

with open(args_remaining[1]) as fh:
    records = lineRecordIterator(fh, M4Record, M4RecordTypes)
    items = map(igetter, records)
    (pctids, lens) = zip(*items)


# Path: nucio.py
# def lineRecordIterator(fh, nt, nt_types, filter_func=trueFunc, delim=None, cleaner_func=None):
# def lineItemIterator(fh, filter_func=trueFunc):
# def getNucmerAlignmentIterator(fh):
# def fileIterator(filename, itemIterator, open_func=open):
# def recordToString( record, delim="\t" ):
# def nucRecordToString(nuc_record):
# def typeify(mylist, mytypes):
# def prepareDeltaRecord(buf):
# def getDeltaAlignmentIterator(fh):
# def deltaRecordHeaderToString(dr):
# def deltaAlignmentHeaderToString(alignment):
# def deltaRecordToOriginalFormat(dr):
#     def __init__(self, s, *args ):
#     def __enter__(self):
#     def __exit__(self, ttype ,value, traceback):
# def openerFromExtension(filename, default=None):
# class FileOrStream:


# Path: graphpid.py
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from operator import attrgetter
from matplotlib.backends.backend_pdf import PdfPages
from mpl_toolkits.axes_grid1 import make_axes_locatable
from nucio import lineRecordIterator,M4Record, M4RecordTypes
from args import parseArgs, getHelpStr, CLArgument


description = ("Usage: graphpid.py [options] title alignments.m4\n\n"
               "Graph Alignments from blasr's m4 output")

argument_list = [["tophist_maxy", "tophist_maxy", int, -1,
                  "Maximum y value for top histogram"]]

arguments = map(CLArgument._make, argument_list)


if not len(sys.argv) > 1:
    sys.exit(getHelpStr(description, arguments) + "\n")

(p_arg_map, args_remaining) = parseArgs(sys.argv[1:], arguments)

if not len(args_remaining) == 2:
    sys.exit(getHelpStr(description, arguments) + "\n")

igetter = attrgetter("pctsimilarity", "qseqlength")

mpl.rc('font', family='normal',weight="normal",
              size=10)
mpl.rc('xtick', labelsize=5)
mpl.rc('ytick', labelsize=5)

with open(args_remaining[1]) as fh:
    records = lineRecordIterator(fh, M4Record, M4RecordTypes)
    items = map(igetter, records)
    (pctids, lens) = zip(*items)


    pp = PdfPages("out.pdf")