# Path: bipy/toolbox/piranha.py
# def run(in_file, bin_size=30, covariate=None, out_file=None):
#     def __init__(self, config):
#     def _start_message(self, in_file):
#     def _end_message(self, in_file):
#     def _check_run(self, in_file):
#     def __call__(self, in_file):
# class PiranhaStage(AbstractStage):
# 
# Path: bipy/toolbox/reporting.py
# def safe_latex(to_fix):
#     def generate_pdf(self, sections=None, out_file=None):
#     def template(self):
#     def generate_report(self, *args, **kwargs):
# def make_latex_table_header(length):
# def panda_to_latex(table, caption=""):
#     def _panda_row_to_latex_row(row):
# class LatexPdf(object):
# class LatexReport(object):
# 
# Path: bipy/utils.py
# def in2out(in_file, word, transform=True, out_dir=None):
#     """
#     creates an out_file name from an in_file name by adding word to the
#     in_file name and writing it to the output_directory if specified.
#     if transform is True, the word replaces the extension of in_file.
#     if False it adds it to the stem
#     transform: in2out("test.bam", "sam", transform=True) -> "test.sam"
#     non transform: in2out("test.bam", "sam", transform=False) -> "test_bam.sam"
# 
#     """
#     (base, ext) = os.path.splitext(in_file)
#     if out_dir:
#         base = os.path.join(out_dir, os.path.basename(base))
# 
#     if transform:
#         return "%s.%s" % (base, word)
# 
#     else:
#         return "%s_%s.%s" % (base, ext, word)


import yaml
import unittest
import os
from bipy.toolbox import piranha
from bcbio.utils import safe_makedir, file_exists
from bipy.toolbox import reporting
from bipy.utils import in2out

STAGENAME = "piranha"


class TestPiranha(unittest.TestCase):

    def setUp(self):
        self.config_file = os.path.join("test", STAGENAME, "test_" +
                                        STAGENAME + ".yaml")
        with open(self.config_file) as in_handle:
            self.config = yaml.load(in_handle)

        self.in_file = self.config["input"]
        self.stage_config = self.config["stage"][STAGENAME]
        self.bin_size = self.stage_config.get("bin_size", 30)
        self.covariate = self.stage_config.get("covariate", None)
        self.out_dir = os.path.join("results", "test", STAGENAME)

    def test_run(self):

        exp_out = in2out(self.in_file, "piranha.bed", transform=True,
                         out_dir = self.out_dir)
        print exp_out

# Path: bipy/toolbox/piranha.py
# def run(in_file, bin_size=30, covariate=None, out_file=None):
#     def __init__(self, config):
#     def _start_message(self, in_file):
#     def _end_message(self, in_file):
#     def _check_run(self, in_file):
#     def __call__(self, in_file):
# class PiranhaStage(AbstractStage):
# 
# Path: bipy/toolbox/reporting.py
# def safe_latex(to_fix):
#     def generate_pdf(self, sections=None, out_file=None):
#     def template(self):
#     def generate_report(self, *args, **kwargs):
# def make_latex_table_header(length):
# def panda_to_latex(table, caption=""):
#     def _panda_row_to_latex_row(row):
# class LatexPdf(object):
# class LatexReport(object):
# 
# Path: bipy/utils.py
# def in2out(in_file, word, transform=True, out_dir=None):
#     """
#     creates an out_file name from an in_file name by adding word to the
#     in_file name and writing it to the output_directory if specified.
#     if transform is True, the word replaces the extension of in_file.
#     if False it adds it to the stem
#     transform: in2out("test.bam", "sam", transform=True) -> "test.sam"
#     non transform: in2out("test.bam", "sam", transform=False) -> "test_bam.sam"
# 
#     """
#     (base, ext) = os.path.splitext(in_file)
#     if out_dir:
#         base = os.path.join(out_dir, os.path.basename(base))
# 
#     if transform:
#         return "%s.%s" % (base, word)
# 
#     else:
#         return "%s_%s.%s" % (base, ext, word)


# Path: test/piranha/test_piranha.py
import yaml
import unittest
import os
from bipy.toolbox import piranha
from bcbio.utils import safe_makedir, file_exists
from bipy.toolbox import reporting
from bipy.utils import in2out


STAGENAME = "piranha"


class TestPiranha(unittest.TestCase):

    def setUp(self):
        self.config_file = os.path.join("test", STAGENAME, "test_" +
                                        STAGENAME + ".yaml")
        with open(self.config_file) as in_handle:
            self.config = yaml.load(in_handle)

        self.in_file = self.config["input"]
        self.stage_config = self.config["stage"][STAGENAME]
        self.bin_size = self.stage_config.get("bin_size", 30)
        self.covariate = self.stage_config.get("covariate", None)
        self.out_dir = os.path.join("results", "test", STAGENAME)

    def test_run(self):

        exp_out = in2out(self.in_file, "piranha.bed", transform=True,
                         out_dir = self.out_dir)
        print exp_out

        out_file = piranha.run(self.in_file, bin_size=self.bin_size,