# Path: ksatools/ksatools.py
# def loadfile(filename):
#     '''Loads file, returns two-column ndarray or None on
#     failure.  Uses filename to guess format.'''
#     try:
#         # parse velvet contig stats format
#         if filename.find("stats.txt") >= 0:
#             matrix = np.loadtxt(filename, usecols=(5, 1), skiprows=1)
#         elif filename.find(".npo") == len(filename) - 4:
#             matrix = np.loadtxt(filename, usecols=(0, 1), skiprows=6)
#             L = getlength(filename)
#             matrix[:, 0] = matrix[:, 0] * L
#         else:  # default bare-bones spectrum format
#             try:
#                 matrix = np.loadtxt(filename, comments="#")
#             except ValueError:
#                 matrix = np.loadtxt(filename, skiprows=1,
#                                     delimiter=",", usecols=(0, 1))
#         # return None if the file is empty
#         matrix[np.isinf(matrix)] = 0
#         matrix = np.atleast_2d(matrix)
#         if matrix.shape[1] == 0:
#             return []
#         else:
#             return matrix
#     except IOError:
#         sys.stderr.write("ERROR: Can't find file %s\n" % filename)
#         return []
# 
# def stratify(spectrum, bands=None):
#     '''Breaks spectrum up into defined abundance-buckets,
#     reporting cumulative data fraction and number of
#     kmers=basepairs with kmer-depths greater than or equal
#     to each bucket boundary.  Returns list of bands, list
#     of (cumulative) fractions, and list of (cumulative)
#     basepairs for each band.
#     '''
#     if bands is None:
#         bands = [1, 10, 100, 1000, 10000, 100000]
#     n = spectrum[:, 0]
#     y = spectrum[:, 1]
#     p = n * y
#     T = sum(p)
#     frac = []
#     size = []
#     for b in bands:
#         frac.append(np.sum(p[n >= b]) / T)
#         size.append(np.sum(y[n >= b]))
#     return bands, frac, size
# 
# def cleanlabel(label):
#     '''Sanitizes graph labels of unintersting file extensions'''
#     suffixes = [".histhist", ".fastq", "_info_contigstats.txt",
#                 ".stats.txt", ".txt", ".csv", ".037.kmerhistogram",
#                 "_001", ".21"]
#     for suffix in suffixes:
#         if label.find(suffix) > 0:
#             label = label[0:(label.find(suffix))]
#     if label[-3:] == ".21":
#         label = label[:-3]
#     return label


import sys
import os
import argparse
import numpy as np
import matplotlib as mpl
    import matplotlib.pyplot as plt
from ksatools.ksatools import loadfile, stratify, cleanlabel
#!/usr/bin/env python
'''Tool to generate bar graphs of data-depth fractions and
basepair-by-depth distributions from kmer spectra
'''

from __future__ import print_function



def plotstratifiedfracs(inlabels, inspectra):
    '''Given list of labels and list of spectra, splits spectra
    up and produces bar plot of the stratified spectra's usage
    fractions
    '''
    colors = ["#CCFFCC", "#99FF99", "#55FF55", "#33CC33", "#009933", "#003300"]
    bands = []
    fracs = []
    sizes = []
    plt.grid(linestyle="-", axis="x", zorder=-10)

# Path: ksatools/ksatools.py
# def loadfile(filename):
#     '''Loads file, returns two-column ndarray or None on
#     failure.  Uses filename to guess format.'''
#     try:
#         # parse velvet contig stats format
#         if filename.find("stats.txt") >= 0:
#             matrix = np.loadtxt(filename, usecols=(5, 1), skiprows=1)
#         elif filename.find(".npo") == len(filename) - 4:
#             matrix = np.loadtxt(filename, usecols=(0, 1), skiprows=6)
#             L = getlength(filename)
#             matrix[:, 0] = matrix[:, 0] * L
#         else:  # default bare-bones spectrum format
#             try:
#                 matrix = np.loadtxt(filename, comments="#")
#             except ValueError:
#                 matrix = np.loadtxt(filename, skiprows=1,
#                                     delimiter=",", usecols=(0, 1))
#         # return None if the file is empty
#         matrix[np.isinf(matrix)] = 0
#         matrix = np.atleast_2d(matrix)
#         if matrix.shape[1] == 0:
#             return []
#         else:
#             return matrix
#     except IOError:
#         sys.stderr.write("ERROR: Can't find file %s\n" % filename)
#         return []
# 
# def stratify(spectrum, bands=None):
#     '''Breaks spectrum up into defined abundance-buckets,
#     reporting cumulative data fraction and number of
#     kmers=basepairs with kmer-depths greater than or equal
#     to each bucket boundary.  Returns list of bands, list
#     of (cumulative) fractions, and list of (cumulative)
#     basepairs for each band.
#     '''
#     if bands is None:
#         bands = [1, 10, 100, 1000, 10000, 100000]
#     n = spectrum[:, 0]
#     y = spectrum[:, 1]
#     p = n * y
#     T = sum(p)
#     frac = []
#     size = []
#     for b in bands:
#         frac.append(np.sum(p[n >= b]) / T)
#         size.append(np.sum(y[n >= b]))
#     return bands, frac, size
# 
# def cleanlabel(label):
#     '''Sanitizes graph labels of unintersting file extensions'''
#     suffixes = [".histhist", ".fastq", "_info_contigstats.txt",
#                 ".stats.txt", ".txt", ".csv", ".037.kmerhistogram",
#                 "_001", ".21"]
#     for suffix in suffixes:
#         if label.find(suffix) > 0:
#             label = label[0:(label.find(suffix))]
#     if label[-3:] == ".21":
#         label = label[:-3]
#     return label


# Path: scripts/stratify.py
import sys
import os
import argparse
import numpy as np
import matplotlib as mpl
    import matplotlib.pyplot as plt
from ksatools.ksatools import loadfile, stratify, cleanlabel

#!/usr/bin/env python
'''Tool to generate bar graphs of data-depth fractions and
basepair-by-depth distributions from kmer spectra
'''

from __future__ import print_function



def plotstratifiedfracs(inlabels, inspectra):
    '''Given list of labels and list of spectra, splits spectra
    up and produces bar plot of the stratified spectra's usage
    fractions
    '''
    colors = ["#CCFFCC", "#99FF99", "#55FF55", "#33CC33", "#009933", "#003300"]
    bands = []
    fracs = []
    sizes = []
    plt.grid(linestyle="-", axis="x", zorder=-10)

    cleanlabels = [cleanlabel(l) for l in inlabels]