# 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, itemgetter
from itertools import imap
from matplotlib.backends.backend_pdf import PdfPages
from nucio import lineRecordIterator, M4Record, M4RecordTypes, lineItemIterator
from args import arglist, parseArgs, getHelpStr, CLArgument, argflag

if not len(args_remaining) >= 3:
    sys.exit(getHelpStr(description,args) + "\n")

title = args_remaining[0]
igetter = attrgetter("qseqlength")

flens = []
for fname in args_remaining[1:]:
    with open(fname) as fh:
        if parg_map["lenfiles"] < 0:
            records = lineRecordIterator(fh, M4Record, M4RecordTypes)
            flens.append( map(igetter, records) )
        else:
            getter = itemgetter(parg_map["lenfiles"])
            flens.append( map(int, imap(getter, lineItemIterator(fh) )))

pp = PdfPages("hist.pdf")
fig = plt.figure()
fig.suptitle(args_remaining[0])
len_binsize = 250

plt.xlabel("Read Length")
plt.ylabel("Frequency")

if parg_map["ymax"] > 0:
    plt.ylim(1,parg_map["ymax"])

labels = parg_map["labels"]
colors = ["red","blue","green","black"]

# 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: lengthhist.py
import sys
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from operator import attrgetter, itemgetter
from itertools import imap
from matplotlib.backends.backend_pdf import PdfPages
from nucio import lineRecordIterator, M4Record, M4RecordTypes, lineItemIterator
from args import arglist, parseArgs, getHelpStr, CLArgument, argflag


if not len(args_remaining) >= 3:
    sys.exit(getHelpStr(description,args) + "\n")

title = args_remaining[0]
igetter = attrgetter("qseqlength")

flens = []
for fname in args_remaining[1:]:
    with open(fname) as fh:
        if parg_map["lenfiles"] < 0:
            records = lineRecordIterator(fh, M4Record, M4RecordTypes)
            flens.append( map(igetter, records) )
        else:
            getter = itemgetter(parg_map["lenfiles"])
            flens.append( map(int, imap(getter, lineItemIterator(fh) )))

pp = PdfPages("hist.pdf")
fig = plt.figure()
fig.suptitle(args_remaining[0])
len_binsize = 250

plt.xlabel("Read Length")
plt.ylabel("Frequency")

if parg_map["ymax"] > 0:
    plt.ylim(1,parg_map["ymax"])

labels = parg_map["labels"]
colors = ["red","blue","green","black"]

plt.hist(flens, bins=np.arange(0,50000,len_binsize), histtype='step', color=colors[:len(labels)],label=labels)