# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item
# 
# def lineItemIterator(fh, filter_func=trueFunc):
#     '''Takes a file handle and returns a list of the split line
#     Will also take a filter function to filter out lines before they
#     are split
#     '''
#     filtered = ifilter( filter_func, fh)
#     return imap(str.split, filtered)


import sys
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
from itertools import chain, imap, cycle
from operator import itemgetter
from matplotlib.backends.backend_pdf import PdfPages
from numpy import arange
from args import parseArgs, getHelpStr, CLArgument
from nucio import fileIterator, lineItemIterator
from args import argflag


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) >= 1:
    sys.exit(getHelpStr(description, arguments) + "\n")

title = args_remaining[0]
infiles = args_remaining[1:]

cellnames = map(lambda f : "_".join(f.split(".")[0].split("_")[:2]), infiles)

fit_gen = lambda filename : fileIterator(filename, lineItemIterator)
file_iterators = map(fit_gen, infiles)

def getBasesFromLineArr(arr):
    if not bool(arr):
        return
    if arr[0].startswith("n="):
        return arr[6].split("=")[1]
    if arr[0].startswith("#>%d" % p_arg_map["lengreater"]):
        return arr[1].split("=")[1]

def getCountsFromLineArr(arr):
    if not bool(arr):
        return

# Path: nucio.py
# def fileIterator(filename, itemIterator, open_func=open):
#     '''Handles the life cyle of a file,
#        The itemIterator will be passed the 
#        opened file handle
#     '''
#     with open_func(filename) as fh:
#         for item in itemIterator(fh):
#             yield item
# 
# def lineItemIterator(fh, filter_func=trueFunc):
#     '''Takes a file handle and returns a list of the split line
#     Will also take a filter function to filter out lines before they
#     are split
#     '''
#     filtered = ifilter( filter_func, fh)
#     return imap(str.split, filtered)


# Path: graphCellStats.py
import sys
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
from itertools import chain, imap, cycle
from operator import itemgetter
from matplotlib.backends.backend_pdf import PdfPages
from numpy import arange
from args import parseArgs, getHelpStr, CLArgument
from nucio import fileIterator, lineItemIterator
from args import argflag



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) >= 1:
    sys.exit(getHelpStr(description, arguments) + "\n")

title = args_remaining[0]
infiles = args_remaining[1:]

cellnames = map(lambda f : "_".join(f.split(".")[0].split("_")[:2]), infiles)

fit_gen = lambda filename : fileIterator(filename, lineItemIterator)
file_iterators = map(fit_gen, infiles)

def getBasesFromLineArr(arr):
    if not bool(arr):
        return
    if arr[0].startswith("n="):
        return arr[6].split("=")[1]
    if arr[0].startswith("#>%d" % p_arg_map["lengreater"]):
        return arr[1].split("=")[1]

def getCountsFromLineArr(arr):
    if not bool(arr):
        return

    if arr[0].startswith("n="):