# Path: bipy/toolbox/tophat.py
# class Bowtie(AbstractStage):
# 
#     stage = "bowtie"
# 
#     def __init__(self, config):
#         self.config = config
#         self.stage_config = config["stage"][self.stage]
#         # defaults = {"q": True, "n": 2, "k": 1,
#         #            "X": 2000, "best": True,
#         #            "sam": True,
#         #            "phred64-quals": True}
#         #self.options = dict(defaults.items() +
#         #                    self.stage_config.get("options", {}).items())
#         self.options = self.stage_config.get("options", {})
#         self.bowtie = sh.Command(self.stage_config.get("program", "bowtie"))
#         self.out_prefix = os.path.join(get_in(self.config,
#                                               ("dir", "results"), "results"),
#                                               self.stage)
#         self.ref_file = self.config["ref"]
#         if not any_bowtie_reference_exists(self.ref_file):
#             bowtie_reference_not_found_error()
# 
#     def _bowtie_se(self, in_file, out_file):
#         self.bowtie(self.options, self.ref_file, in_file, out_file)
# 
#     def _bowtie_pe(self, in_file, out_file):
#         self.bowtie(self.options, self.ref_file,
#                     "-1", in_file[0], "-2", in_file[1], out_file)
# 
#     def _get_out_file(self, in_file):
#         base, _ = os.path.splitext(os.path.basename(in_file))
#         out_prefix = os.path.join(get_in(self.config,
#                                          ("dir", "results"), "results"),
#                                          self.stage)
#         out_dir = os.path.join(out_prefix, base)
#         out_file = os.path.join(out_dir, base + ".sam")
#         return out_file
# 
#     def out_file(self, in_file):
#         if is_pair(in_file):
#             return self._get_out_file(in_file[0])
#         else:
#             return self._get_out_file(in_file)
# 
#     def __call__(self, in_file):
#         self._start_message(in_file)
#         out_file = self.out_file(in_file)
# 
#         if file_exists(out_file):
#             return out_file
# 
#         with file_transaction(out_file) as tmp_out_file:
#             if is_pair(in_file):
#                 self._bowtie_pe(in_file, tmp_out_file)
#             else:
#                 self._bowtie_se(in_file, tmp_out_file)
#         self._end_message(in_file)
# 
#         return out_file


from bipy.toolbox.tophat import Bowtie
from bcbio.utils import file_exists
import yaml
import unittest
import filecmp
import os

CONFIG_FILE = "test/bowtie/test_bowtie.yaml"


class TestBowtie(unittest.TestCase):

    def setUp(self):
        with open(CONFIG_FILE) as in_handle:
            self.config = yaml.load(in_handle)
        self.stage_config = self.config["stage"]["bowtie"]

    def test_single(self):
        correct_file = self.config["input_single_correct"]
        single = self.config["input_single"]

# Path: bipy/toolbox/tophat.py
# class Bowtie(AbstractStage):
# 
#     stage = "bowtie"
# 
#     def __init__(self, config):
#         self.config = config
#         self.stage_config = config["stage"][self.stage]
#         # defaults = {"q": True, "n": 2, "k": 1,
#         #            "X": 2000, "best": True,
#         #            "sam": True,
#         #            "phred64-quals": True}
#         #self.options = dict(defaults.items() +
#         #                    self.stage_config.get("options", {}).items())
#         self.options = self.stage_config.get("options", {})
#         self.bowtie = sh.Command(self.stage_config.get("program", "bowtie"))
#         self.out_prefix = os.path.join(get_in(self.config,
#                                               ("dir", "results"), "results"),
#                                               self.stage)
#         self.ref_file = self.config["ref"]
#         if not any_bowtie_reference_exists(self.ref_file):
#             bowtie_reference_not_found_error()
# 
#     def _bowtie_se(self, in_file, out_file):
#         self.bowtie(self.options, self.ref_file, in_file, out_file)
# 
#     def _bowtie_pe(self, in_file, out_file):
#         self.bowtie(self.options, self.ref_file,
#                     "-1", in_file[0], "-2", in_file[1], out_file)
# 
#     def _get_out_file(self, in_file):
#         base, _ = os.path.splitext(os.path.basename(in_file))
#         out_prefix = os.path.join(get_in(self.config,
#                                          ("dir", "results"), "results"),
#                                          self.stage)
#         out_dir = os.path.join(out_prefix, base)
#         out_file = os.path.join(out_dir, base + ".sam")
#         return out_file
# 
#     def out_file(self, in_file):
#         if is_pair(in_file):
#             return self._get_out_file(in_file[0])
#         else:
#             return self._get_out_file(in_file)
# 
#     def __call__(self, in_file):
#         self._start_message(in_file)
#         out_file = self.out_file(in_file)
# 
#         if file_exists(out_file):
#             return out_file
# 
#         with file_transaction(out_file) as tmp_out_file:
#             if is_pair(in_file):
#                 self._bowtie_pe(in_file, tmp_out_file)
#             else:
#                 self._bowtie_se(in_file, tmp_out_file)
#         self._end_message(in_file)
# 
#         return out_file


# Path: test/bowtie/test_bowtie.py
from bipy.toolbox.tophat import Bowtie
from bcbio.utils import file_exists
import yaml
import unittest
import filecmp
import os


CONFIG_FILE = "test/bowtie/test_bowtie.yaml"


class TestBowtie(unittest.TestCase):

    def setUp(self):
        with open(CONFIG_FILE) as in_handle:
            self.config = yaml.load(in_handle)
        self.stage_config = self.config["stage"]["bowtie"]

    def test_single(self):
        correct_file = self.config["input_single_correct"]
        single = self.config["input_single"]

        bowtie = Bowtie(self.config)