# 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
    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")

    (fig, axScatter) = plt.subplots(figsize=(8.5,5.5))
    axScatter.scatter(lens, pctids, color="blue", s=0.001) 
    axScatter.set_xticks(range(0,80000,2000))
    axScatter.set_yticks(range(0,100,5))
    fig.suptitle(args_remaining[0])
    plt.xlabel("Read Length (bp)")
    plt.ylabel("Alignment Identity (%)")

    divider = make_axes_locatable(axScatter)
    axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
    axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

    plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(), visible=False)


# 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

    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")

    (fig, axScatter) = plt.subplots(figsize=(8.5,5.5))
    axScatter.scatter(lens, pctids, color="blue", s=0.001) 
    axScatter.set_xticks(range(0,80000,2000))
    axScatter.set_yticks(range(0,100,5))
    fig.suptitle(args_remaining[0])
    plt.xlabel("Read Length (bp)")
    plt.ylabel("Alignment Identity (%)")

    divider = make_axes_locatable(axScatter)
    axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
    axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

    plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(), visible=False)


    len_binsize=250