class TestScreen(unittest.TestCase): def setUp(self): self.example = Example() self.mock_args = MockClass() self.test_folder = "test_folder" self.output = os.path.join(self.test_folder, "output") self.tex_wig = os.path.join(self.test_folder, "tex") self.frag_wig = os.path.join(self.test_folder, "frag") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tex_wig) os.mkdir(self.frag_wig) os.mkdir(self.output) self.fasta = os.path.join(self.test_folder, "aaa.fa") gen_file(self.fasta, self.example.fasta) args = self.mock_args.mock() args.output_folder = self.output args.fasta = self.fasta self.screen = Screen(args) def tearDown(self): if os.path.exists(self.test_folder): shutil.rmtree(self.test_folder) def test_screenshot(self): gen_file(os.path.join(self.tex_wig, "tex_1_f.wig"), self.example.wig_f) gen_file(os.path.join(self.tex_wig, "notex_1_f.wig"), self.example.wig_f) gen_file(os.path.join(self.frag_wig, "frag_f.wig"), self.example.wig_f) gen_file(os.path.join(self.tex_wig, "tex_1_r.wig"), self.example.wig_r) gen_file(os.path.join(self.tex_wig, "notex_1_r.wig"), self.example.wig_r) gen_file(os.path.join(self.frag_wig, "frag_r.wig"), self.example.wig_r) args = self.mock_args.mock() args.fasta = self.fasta args.main_gff = os.path.join(self.test_folder, "main.gff") gen_file(args.main_gff, self.example.main_gff) side_gff = os.path.join(self.test_folder, "side.gff") args.side_gffs = [side_gff] gen_file(side_gff, self.example.side_gff) args.frag_wigs = self.frag_wig args.tex_wigs = self.tex_wig args.height = 1000 args.tlibs = ["tex_1_f.wig:tex:1:a:+", "tex_1_r.wig:tex:1:a:-", "notex_1_f.wig:notex:1:a:+", "notex_1_r.wig:notex:1:a:-"] args.flibs = ["frag_f.wig:frag:1:a:+", "frag_r.wig:frag:1:a:-"] args.present = "expand" args.output_folder = self.output self.screen.screenshot(args) self.assertTrue(os.path.exists(os.path.join(self.output, "screenshots", "aaa", "forward"))) self.assertTrue(os.path.exists(os.path.join(self.output, "screenshots", "aaa", "reverse"))) datas = import_data(os.path.join(self.output, "screenshots", "aaa", "forward.txt")) datas = import_data(os.path.join(self.output, "screenshots", "aaa", "reverse.txt")) self.assertEqual("\n".join(datas), self.example.out_r) def test_import_libs(self): texs = [["tex_1.wig", "tex", "1", "a", "+"], ["notex_1.wig", "notex", "1", "a", "+"]] lib_dict = {"ft": [], "fn": [], "rt": [], "rn": [], "ff": [], "rf": []} self.screen._import_libs(texs, "+", self.tex_wig, lib_dict) self.assertDictEqual(lib_dict, {'fn': ['test_folder/tex/notex_1.wig'], 'rn': [], 'rt': [], 'ft': ['test_folder/tex/tex_1.wig'], 'rf': [], 'ff': []})
def screen(self): """generate screenshot""" print("Running screenshot generation") self.check_file([self._args.main_gff, self._args.fasta_file], ["--main_gff", "--fasta_file"], True) if self._args.side_gffs is not None: for gff in (self._args.side_gffs): gff = gff.strip() if not os.path.isfile(gff): print("Error: The --side_gffs do not exist!") sys.exit() if self._args.output_folder is None: print("Error: Please assign --output_folder!") sys.exit() if (self._args.present != "expand") and ( self._args.present != "collapse") and ( self._args.present != "squish"): print("Error: Please assign \"expand\" or " "\"collapse\" or \"squish\" to --present!") sys.exit() args_sc = self.args_container.container_screen( self._args.main_gff, self._args.side_gffs, self._args.fasta_file, self._args.height, self._args.tex_notex_libs, self._args.frag_libs, self._args.present, self._args.output_folder) screen = Screen(args_sc) screen.screenshot(args_sc)
def screen(self): """generate screenshot""" print("Running screenshot generating...") self.check_file([self._args.main_gff, self._args.fasta], ["--main_gff", "--fasta"], True) if self._args.side_gffs is not None: for gff in (self._args.side_gffs.split(",")): gff = gff.strip() if not os.path.isfile(gff): print("Error: The --side_gffs no exist!!") sys.exit() if self._args.output_folder is None: print("Error: please assign --output_folder!!") sys.exit() if (self._args.present != "expand") and ( self._args.present != "collapse") and ( self._args.present != "squish"): print("Error: please assign \"expand\" or " "\"collapse\" or \"squish\" to --present!!") sys.exit() args_sc = self.args_container.container_screen( self._args.main_gff, self._args.side_gffs, self._args.fasta, self._args.frag_wig_folder, self._args.tex_wig_folder, self._args.height, self._args.tex_libs, self._args.frag_libs, self._args.present, self._args.output_folder) screen = Screen(args_sc) screen.screenshot(args_sc)
def setUp(self): self.example = Example() self.mock_args = MockClass() self.test_folder = "test_folder" self.output = os.path.join(self.test_folder, "output") self.tex_wig = os.path.join(self.test_folder, "tex") self.frag_wig = os.path.join(self.test_folder, "frag") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tex_wig) os.mkdir(self.frag_wig) os.mkdir(self.output) self.fasta = os.path.join(self.test_folder, "aaa.fa") gen_file(self.fasta, self.example.fasta) args = self.mock_args.mock() args.output_folder = self.output args.fasta = self.fasta self.screen = Screen(args, self.output)