def _compute_utr(self, args_utr): for gff in os.listdir(args_utr.gffs): if gff.endswith(".gff"): prefix = gff[:-4] tss = self.helper.get_correct_file(self.tss_path, "_TSS.gff", prefix, None, None) tran = self.helper.get_correct_file(self.tran_path, "_transcript.gff", prefix, None, None) if args_utr.terms: term = self.helper.get_correct_file( os.path.join(args_utr.terms, "tmp"), "_term.gff", prefix, None, None) else: term = None print("Computing 5'UTR of {0}".format(prefix)) detect_5utr( tss, os.path.join(args_utr.gffs, gff), tran, os.path.join(self.utr5_path, "gffs", "_".join([prefix, "5UTR.gff"])), args_utr) print("Computing 3'UTR of {0}".format(prefix)) detect_3utr( tran, os.path.join(args_utr.gffs, gff), term, os.path.join(self.utr3_path, "gffs", "_".join([prefix, "3UTR.gff"])), args_utr) self.helper.move_all_content(os.getcwd(), self.utr5_stat_path, ["_5utr_length.png"]) self.helper.move_all_content(os.getcwd(), self.utr3_stat_path, ["_3utr_length.png"])
def _compute_utr(self, args_utr): for gff in os.listdir(args_utr.gffs): if gff.endswith(".gff"): prefix = gff[:-4] tss = self.helper.get_correct_file( self.tss_path, "_TSS.gff", prefix, None, None) tran = self.helper.get_correct_file( self.tran_path, "_transcript.gff", prefix, None, None) if args_utr.terms: term = self.helper.get_correct_file( os.path.join(args_utr.terms, "tmp"), "_term.gff", prefix, None, None) else: term = None print("computing 5'UTR of {0} .....".format(prefix)) detect_5utr(tss, os.path.join(args_utr.gffs, gff), tran, os.path.join(self.utr5_path, "gffs", "_".join([prefix, "5UTR.gff"])), args_utr) print("computing 3'UTR of {0} .....".format(prefix)) detect_3utr(tran, os.path.join(args_utr.gffs, gff), term, os.path.join(self.utr3_path, "gffs", "_".join([prefix, "3UTR.gff"])), args_utr) self.helper.move_all_content( os.getcwd(), self.utr5_stat_path, ["_5utr_length.png"]) self.helper.move_all_content( os.getcwd(), self.utr3_stat_path, ["_3utr_length.png"])
def _compute_utr(self, args_utr, log): log.write("Running detect_utr.py to detect UTRs.\n") for gff in os.listdir(args_utr.gffs): if gff.endswith(".gff"): prefix = gff[:-4] tss = self.helper.get_correct_file( self.tss_path, "_TSS.gff", prefix, None, None) tran = self.helper.get_correct_file( self.tran_path, "_transcript.gff", prefix, None, None) if args_utr.terms: term = self.helper.get_correct_file( os.path.join(args_utr.terms, "tmp"), "_term.gff", prefix, None, None) else: term = None print("Computing 5'UTRs of {0}".format(prefix)) detect_5utr(tss, os.path.join(args_utr.gffs, gff), tran, os.path.join(self.utr5_path, "gffs", "_".join([prefix, "5UTR.gff"])), args_utr) print("Computing 3'UTRs of {0}".format(prefix)) detect_3utr(tran, os.path.join(args_utr.gffs, gff), term, os.path.join(self.utr3_path, "gffs", "_".join([prefix, "3UTR.gff"])), args_utr) self.helper.move_all_content( os.getcwd(), self.utr5_stat_path, ["_5utr_length.png"]) self.helper.move_all_content( os.getcwd(), self.utr3_stat_path, ["_3utr_length.png"]) log.write("The following files are generated:\n") for folder in (os.path.join(self.utr5_path, "gffs"), os.path.join(self.utr3_path, "gffs"), self.utr5_stat_path, self.utr3_stat_path): for file_ in os.listdir(folder): log.write("\t" + os.path.join(folder, file_) + "\n")
def test_detect_5utr(self): args = self.mock_args.mock() du.read_file = Mock_func().mock_read_file du.plot = Mock_func().mock_plot out_file = os.path.join(self.test_folder, "5utr.gff") args.source = True args.base_5utr = "both" args.length = 300 du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) header = ["##gff-version 3"] args.source = False args.base_5utr = "both" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) datas = import_data(out_file) ref = header + [self.example.out_5utr_other] self.assertEqual(datas[1], ref[1]) args.base_5utr = "transcript" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) self.assertEqual(set(datas), set(ref)) args.source = True args.base_5utr = "both" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) datas = import_data(out_file) ref = header + [self.example.out_5utr_tsspredator] self.assertListEqual(datas, ref)
def test_detect_5utr(self): args = self.mock_args.mock() du.read_file = Mock_func().mock_read_file du.plot = Mock_func().mock_plot out_file = os.path.join(self.test_folder, "5utr.gff") args.source = True args.base_5utr = "both" args.length = 300 du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) header = ["##gff-version 3"] args.source = False args.base_5utr = "both" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) datas = import_data(out_file) ref = header + [self.example.out_5utr_other] self.assertEqual(datas[1], ref[1]) args.base_5utr = "transcript" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) self.assertEqual(set(datas), set(ref)) args.source = True args.base_5utr = "both" du.detect_5utr("test.tss", "test.gff", "test.ta", out_file, args) datas = import_data(out_file) ref = header + [self.example.out_5utr_tsspredator] self.assertListEqual(datas, ref)
def _compute_utr(self, args_utr, log): log.write("Running detect_utr.py to detect UTRs.\n") for gff in os.listdir(args_utr.gffs): if gff.endswith(".gff"): prefix = gff[:-4] tss = self.helper.get_correct_file(self.tss_path, "_TSS.gff", prefix, None, None) tran = self.helper.get_correct_file(self.tran_path, "_transcript.gff", prefix, None, None) if args_utr.terms: term = self.helper.get_correct_file( os.path.join(args_utr.terms, "tmp"), "_term.gff", prefix, None, None) else: term = None print("Computing 5'UTRs of {0}".format(prefix)) detect_5utr( tss, os.path.join(args_utr.gffs, gff), tran, os.path.join(self.utr5_path, "gffs", "_".join([prefix, "5UTR.gff"])), args_utr) print("Computing 3'UTRs of {0}".format(prefix)) detect_3utr( tran, os.path.join(args_utr.gffs, gff), term, os.path.join(self.utr3_path, "gffs", "_".join([prefix, "3UTR.gff"])), args_utr) self.helper.move_all_content(os.getcwd(), self.utr5_stat_path, ["_5utr_length.png"]) self.helper.move_all_content(os.getcwd(), self.utr3_stat_path, ["_3utr_length.png"]) log.write("The following files are generated:\n") for folder in (os.path.join(self.utr5_path, "gffs"), os.path.join(self.utr3_path, "gffs"), self.utr5_stat_path, self.utr3_stat_path): for file_ in os.listdir(folder): log.write("\t" + os.path.join(folder, file_) + "\n")