# Path: snakemakelib/report/utils.py
# class Template(string.Formatter):
#     _suffix = {'-3':('n', 10**(-9)), '-2':('u', 10**(-6)), '-1':('m', 10**(-3)), '0':('', 1), '1':('k', 10**3), '2':('M', 10**6), '3':('G', 10**9), '4':('T', 10**12), '5':('P', 10**15)}
#     def format_field(self, value, spec):
#         sfx = ""
#         if spec.endswith('h'):
#             if not value == 0:
#                 spec = spec[:-1] + 'f'
#                 n = (math.floor(math.log(value,10) / 3))
#                 value = value / self._suffix[str(n)][1]
#                 sfx = self._suffix[str(n)][0]
#             else:
#                 spec = 'd'
#         return super(Template, self).format_field(value, spec) + sfx


import os
import sys
import re
import csv
import texttable as tt
import collections
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from snakemakelib.report.utils import Template
from pylab import *

    def rst(self, raw=False):
        ttab = make_rst_table(self.summary.split("\n"))
        return _indent_texttable_for_rst(ttab)

    def summary(self, fmt = None, ctype = None, sep="\t", raw=False):
        columns = self.colnames
        fmt = {k:v[0] for (k,v) in list(self._format.items()) if k in columns} if fmt is None else {k:v for (k,v) in zip(columns, fmt)}
        ctype = {k:v[1] for (k,v) in list(self._format.items()) if k in columns} if ctype is None else {k:v for (k,v) in zip(columns, ctype)}
        if not fmt:
            raise ValueError("No format defined for {cls}; please use derived subclass".format(cls=__class__))
        if raw:
            return "\n".join([sep.join([x for x in columns])] + [sep.join([r[c] for c in columns]) for r in self])
        return "\n".join([sep.join([x for x in columns])] + [sep.join([self._format_field(r[c], fmt[c], ctype[c]) for c in columns]) for r in self])

    
class PicardMetrics(object):
    """Generic class to store metrics section from Picard Metrics reports.
    See also class PicardHistMetrics for reports that provide metrics
    and histogram information.

    Args:
      *args: if provided, must be a list of lists that upon initialization is converted to an OrderedDict. The first list is treated as a header.
      filename (str): file from which to collect metrics
      identifier (str): unique identifier for object, e.g. sample or unit name

    Returns:
      An instance of class PicardMetrics
    """
    _format = collections.OrderedDict()

# Path: snakemakelib/report/utils.py
# class Template(string.Formatter):
#     _suffix = {'-3':('n', 10**(-9)), '-2':('u', 10**(-6)), '-1':('m', 10**(-3)), '0':('', 1), '1':('k', 10**3), '2':('M', 10**6), '3':('G', 10**9), '4':('T', 10**12), '5':('P', 10**15)}
#     def format_field(self, value, spec):
#         sfx = ""
#         if spec.endswith('h'):
#             if not value == 0:
#                 spec = spec[:-1] + 'f'
#                 n = (math.floor(math.log(value,10) / 3))
#                 value = value / self._suffix[str(n)][1]
#                 sfx = self._suffix[str(n)][0]
#             else:
#                 spec = 'd'
#         return super(Template, self).format_field(value, spec) + sfx


# Path: snakemakelib/report/picard.py
import os
import sys
import re
import csv
import texttable as tt
import collections
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from snakemakelib.report.utils import Template
from pylab import *


    def rst(self, raw=False):
        ttab = make_rst_table(self.summary.split("\n"))
        return _indent_texttable_for_rst(ttab)

    def summary(self, fmt = None, ctype = None, sep="\t", raw=False):
        columns = self.colnames
        fmt = {k:v[0] for (k,v) in list(self._format.items()) if k in columns} if fmt is None else {k:v for (k,v) in zip(columns, fmt)}
        ctype = {k:v[1] for (k,v) in list(self._format.items()) if k in columns} if ctype is None else {k:v for (k,v) in zip(columns, ctype)}
        if not fmt:
            raise ValueError("No format defined for {cls}; please use derived subclass".format(cls=__class__))
        if raw:
            return "\n".join([sep.join([x for x in columns])] + [sep.join([r[c] for c in columns]) for r in self])
        return "\n".join([sep.join([x for x in columns])] + [sep.join([self._format_field(r[c], fmt[c], ctype[c]) for c in columns]) for r in self])

    
class PicardMetrics(object):
    """Generic class to store metrics section from Picard Metrics reports.
    See also class PicardHistMetrics for reports that provide metrics
    and histogram information.

    Args:
      *args: if provided, must be a list of lists that upon initialization is converted to an OrderedDict. The first list is treated as a header.
      filename (str): file from which to collect metrics
      identifier (str): unique identifier for object, e.g. sample or unit name

    Returns:
      An instance of class PicardMetrics
    """
    _format = collections.OrderedDict()

    _tp = Template()