# 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 *
# Copyright (c) 2014 Per Unneberg
matplotlib.use('Agg')

# http://stackoverflow.com/questions/2170900/get-first-list-index-containing-sub-string-in-python
def index_containing_substring(the_list, substring):
    for i, s in enumerate(the_list):
        if substring in s:
              return i
    return -1

def _raw(x):
    return (x, None)

def _convert_input(x):
    if re.match("^[0-9]+$", x):
        return int(x)
    elif re.match("^[0-9,.]+$", x):
        return float(x.replace(",", "."))
    else:
        return str(x)

def _read_picard_metrics(f):
    with open(f) as fh:

# 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 *

# Copyright (c) 2014 Per Unneberg
matplotlib.use('Agg')

# http://stackoverflow.com/questions/2170900/get-first-list-index-containing-sub-string-in-python
def index_containing_substring(the_list, substring):
    for i, s in enumerate(the_list):
        if substring in s:
              return i
    return -1

def _raw(x):
    return (x, None)

def _convert_input(x):
    if re.match("^[0-9]+$", x):
        return int(x)
    elif re.match("^[0-9,.]+$", x):
        return float(x.replace(",", "."))
    else:
        return str(x)

def _read_picard_metrics(f):
    with open(f) as fh:

        data = fh.readlines()