# Path: ksatools/ksatools.py
# def pad(xvalues, yvalues, fill=True):
#     '''Adds missing integer values to x and corresponding zeros to y.'''
#     yout = []
#     xout = []
#     xv = np.arange(1, int(1.5 * max(xvalues)))
#     yv = np.zeros(shape=int(1.5 * max(xvalues) - 1), dtype=int)
# 
#     if fill is True:
#         for i, x in enumerate(xvalues):
#             yv[np.where(xv == x)[0][0]] = yvalues[i]
#         xout = list(xv)
#         yout = list(yv)
#     else:
#         for i, x in enumerate(xvalues):
#             if (x - 1 not in xvalues) and (x - 1) not in xout:
#                 xout.append(x - 1)
#                 yout.append(0)
#             if yvalues[xvalues.index(x)] > 0:
#                 xout.append(xvalues[xvalues.index(x)])
#                 yout.append(yvalues[xvalues.index(x)])
#             if (x + 1 not in xvalues) and (x + 1) not in xout:
#                 xout.append(x + 1)
#                 yout.append(0)
#     return(xout, yout)


import sys
import os
import argparse
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
    import numdifftools as nd
from scipy import stats
from scipy.optimize import leastsq
from ksatools.ksatools import pad
                        action="store_true", default=False, help="interactive plot")
    PARSER.add_argument("-p", "--positiveconstrained", dest="constrained",
                        action="store_false", default=True, help="constrained fit")
    PARSER.add_argument("-o", "--outstem", dest="outstem",
                        default=None, help="output file stem")
    PARSER.add_argument("-v", "--verbose", dest="verbose", action="store_true",
                        default=False, help="verbose")

    OPTS = PARSER.parse_args()
    try:
        INFILE = OPTS.infile
    except IndexError:
        PARSER.error("Missing table filename input argument \n%s\n" % USAGE)
    if not (INFILE and os.path.isfile(INFILE)):
        PARSER.error("Missing input filename\n%s\n" % USAGE)
    LOWCUTOFF = int(OPTS.lowcutoff)
    MAXFEV = 2000
    DATA = np.loadtxt(INFILE)  # loaddata
    ORIGY = DATA[:, 1]
    ORIGX = DATA[:, 0]
    NUMBEROFTERMS = int(OPTS.num)
    SECONDPEAK = int(OPTS.bypass)
    OUTFILE = OPTS.outstem
    if OUTFILE is None:
        OUTFILE = INFILE
    print("INFILE", INFILE)
    print("OUTFILE", OUTFILE)
    MAX_COV, MIN_COV = [int(cov) for cov in OPTS.cutoff.split(",")]
#  pad data with zeroes representing bins with no counts.
    print("Padding... originally %d, max %d " % (len(ORIGX), max(ORIGX)))

# Path: ksatools/ksatools.py
# def pad(xvalues, yvalues, fill=True):
#     '''Adds missing integer values to x and corresponding zeros to y.'''
#     yout = []
#     xout = []
#     xv = np.arange(1, int(1.5 * max(xvalues)))
#     yv = np.zeros(shape=int(1.5 * max(xvalues) - 1), dtype=int)
# 
#     if fill is True:
#         for i, x in enumerate(xvalues):
#             yv[np.where(xv == x)[0][0]] = yvalues[i]
#         xout = list(xv)
#         yout = list(yv)
#     else:
#         for i, x in enumerate(xvalues):
#             if (x - 1 not in xvalues) and (x - 1) not in xout:
#                 xout.append(x - 1)
#                 yout.append(0)
#             if yvalues[xvalues.index(x)] > 0:
#                 xout.append(xvalues[xvalues.index(x)])
#                 yout.append(yvalues[xvalues.index(x)])
#             if (x + 1 not in xvalues) and (x + 1) not in xout:
#                 xout.append(x + 1)
#                 yout.append(0)
#     return(xout, yout)


# Path: scripts/kmerspectrumanalyzer.py
import sys
import os
import argparse
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
    import numdifftools as nd
from scipy import stats
from scipy.optimize import leastsq
from ksatools.ksatools import pad

                        action="store_true", default=False, help="interactive plot")
    PARSER.add_argument("-p", "--positiveconstrained", dest="constrained",
                        action="store_false", default=True, help="constrained fit")
    PARSER.add_argument("-o", "--outstem", dest="outstem",
                        default=None, help="output file stem")
    PARSER.add_argument("-v", "--verbose", dest="verbose", action="store_true",
                        default=False, help="verbose")

    OPTS = PARSER.parse_args()
    try:
        INFILE = OPTS.infile
    except IndexError:
        PARSER.error("Missing table filename input argument \n%s\n" % USAGE)
    if not (INFILE and os.path.isfile(INFILE)):
        PARSER.error("Missing input filename\n%s\n" % USAGE)
    LOWCUTOFF = int(OPTS.lowcutoff)
    MAXFEV = 2000
    DATA = np.loadtxt(INFILE)  # loaddata
    ORIGY = DATA[:, 1]
    ORIGX = DATA[:, 0]
    NUMBEROFTERMS = int(OPTS.num)
    SECONDPEAK = int(OPTS.bypass)
    OUTFILE = OPTS.outstem
    if OUTFILE is None:
        OUTFILE = INFILE
    print("INFILE", INFILE)
    print("OUTFILE", OUTFILE)
    MAX_COV, MIN_COV = [int(cov) for cov in OPTS.cutoff.split(",")]
#  pad data with zeroes representing bins with no counts.
    print("Padding... originally %d, max %d " % (len(ORIGX), max(ORIGX)))

    (paddedx1, paddedy1) = pad(ORIGX.tolist(), ORIGY.tolist())