def ribos(self): """riboswitch and RNA thermometer prediction""" print("Running riboswitch and RNA thermometer prediction") self.check_multi_files( [self._args.annotation_files, self._args.fasta_files, self._args.tss_files, self._args.transcript_files], ["--annotation_files", "--fasta_files", "--tss_files", "--transcript_files"]) if (self._args.program == "both"): self.check_file([self._args.riboswitch_id_file, self._args.rfam_path], ["--riboswitch_id_file", "--rfam_path"], True) self.check_file([self._args.rna_thermometer_id_file, self._args.rfam_path], ["--rna_thermometer_id_file", "--rfam_path"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) project_creator.create_subfolders( self._paths.required_folders("thermometer")) ribos_path = self._paths.ribos_output_folder thermo_path = self._paths.thermo_output_folder elif (self._args.program == "thermometer"): self.check_file([self._args.rna_thermometer_id_file, self._args.rfam_path], ["--thermometer_id_file", "--rfam_path"], True) project_creator.create_subfolders( self._paths.required_folders("thermometer")) ribos_path = None thermo_path = self._paths.thermo_output_folder elif (self._args.program == "riboswitch"): self.check_file([self._args.riboswitch_id_file, self._args.rfam_path], ["--riboswitch_id_file", "--rfam_path"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) ribos_path = self._paths.ribos_output_folder thermo_path = None else: print("Error: Please assign \"thermometer\", \"riboswitch\" " "or \"both\" in --program!") sys.exit() self._args.cmscan_path = self.check_execute_file(self._args.cmscan_path) self._args.cmpress_path = self.check_execute_file(self._args.cmpress_path) args_ribo = self.args_container.container_ribos( self._args.program, self._args.rna_thermometer_id_file, self._args.cmscan_path, self._args.cmpress_path, self._args.riboswitch_id_file, self._args.annotation_files, self._args.fasta_files, self._args.tss_files, self._args.transcript_files, self._args.rfam_path, ribos_path, thermo_path, self._args.e_value, self._args.output_all, self._paths.database_folder, self._args.tolerance, self._args.start_codon, self._args.min_dist_rbs, self._args.max_dist_rbs, self._args.tolerance_rbs, self._args.utr_length) ribos = Ribos(args_ribo) ribos.run_ribos(args_ribo)
def ribos(self): """riboswitch and RNA thermometer prediction""" print("Running riboswitch and RNA thermometer prediction...") self.check_folder([self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path]) if (self._args.program == "both"): self.check_file([self._args.riboswitch_ID, self._args.Rfam], ["--riboswitch_ID", "--Rfam"], True) self.check_file([self._args.RNA_thermometer_ID, self._args.Rfam], ["--RNA_thermometer_ID", "--Rfam"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) project_creator.create_subfolders( self._paths.required_folders("thermometer")) ribos_path = self._paths.ribos_output_folder thermo_path = self._paths.thermo_output_folder elif (self._args.program == "thermometer"): self.check_file([self._args.RNA_thermometer_ID, self._args.Rfam], ["--thermometer_ID", "--Rfam"], True) project_creator.create_subfolders( self._paths.required_folders("thermometer")) ribos_path = None thermo_path = self._paths.thermo_output_folder elif (self._args.program == "riboswitch"): self.check_file([self._args.riboswitch_ID, self._args.Rfam], ["--riboswitch_ID", "--Rfam"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) ribos_path = self._paths.ribos_output_folder thermo_path = None else: print("Error: Please assign \"thermometer\", \"riboswitch\" " "or \"both\" in --program!!") sys.exit() args_ribo = self.args_container.container_ribos( self._args.program, self._args.RNA_thermometer_ID, self._args.infernal_path, self._args.riboswitch_ID, self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path, self._args.Rfam, ribos_path, thermo_path, self._args.e_value, self._args.output_all, self._paths.database_folder, self._args.fuzzy, self._args.start_codon, self._args.min_dist_rbs, self._args.max_dist_rbs, self._args.fuzzy_rbs, self._args.UTR_length) ribos = Ribos(args_ribo) ribos.run_ribos(args_ribo)
def setUp(self): self.example = Example() self.mock_args = MockClass() self.mock = Mock_func() self.test_folder = "test_folder" self.gffs = os.path.join(self.test_folder, "gffs") self.fastas = os.path.join(self.test_folder, "fastas") self.out_folder = os.path.join(self.test_folder, "output") self.database = os.path.join(self.test_folder, "database") self.seq_path = os.path.join(self.test_folder, "seqs") self.tables = os.path.join(self.out_folder, "tables") self.stat = os.path.join(self.out_folder, "statistics") self.scan = os.path.join(self.test_folder, "scan") self.tsss = os.path.join(self.test_folder, "tsss") self.trans = os.path.join(self.test_folder, "trans") self.out_gff = os.path.join(self.out_folder, "gffs") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tsss) os.mkdir(os.path.join(self.tsss, "tmp")) os.mkdir(self.trans) os.mkdir(os.path.join(self.trans, "tmp")) os.mkdir(self.gffs) os.mkdir(os.path.join(self.gffs, "tmp")) os.mkdir(self.fastas) os.mkdir(os.path.join(self.fastas, "tmp")) os.mkdir(self.out_folder) os.mkdir(self.database) os.mkdir(self.seq_path) os.mkdir(os.path.join(self.out_folder, "tmp_table")) os.mkdir(os.path.join(self.out_folder, "tmp_scan")) os.mkdir(os.path.join(self.out_folder, "tmp_fasta")) os.mkdir(os.path.join(self.out_folder, "scan_Rfam")) os.mkdir(self.tables) os.mkdir(self.scan) os.mkdir(self.stat) os.mkdir(self.out_gff) args = self.mock_args.mock() args.gffs = self.gffs args.fastas = self.fastas args.ribos_out_folder = self.out_folder args.database = self.database args.tsss = self.tsss args.trans = self.trans args.program = 'riboswtich' self.ribo = Ribos(args)
def ribos(self): """riboswitch prediction""" print("Running riboswitch prediction...") self.check_folder([self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path]) self.check_file([self._args.riboswitch_ID, self._args.Rfam], ["--riboswitch_ID", "--Rfam"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) args_ribo = self.args_container.container_ribos( self._args.infernal_path, self._args.riboswitch_ID, self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path, self._args.Rfam, self._paths.ribos_output_folder, self._args.e_value, self._args.output_all, self._paths.database_folder, self._args.fuzzy, self._args.start_codon, self._args.min_dist_rbs, self._args.max_dist_rbs, self._args.fuzzy_rbs, self._args.UTR_length) ribos = Ribos(args_ribo) ribos.run_ribos(args_ribo)
def ribos(self): """riboswitch prediction""" print("Running riboswitch prediction...") self.check_folder([ self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path ]) self.check_file([self._args.riboswitch_ID, self._args.Rfam], ["--riboswitch_ID", "--Rfam"], True) project_creator.create_subfolders( self._paths.required_folders("riboswitch")) args_ribo = self.args_container.container_ribos( self._args.infernal_path, self._args.riboswitch_ID, self._args.gff_path, self._args.fasta_path, self._args.tss_path, self._args.transcript_path, self._args.Rfam, self._paths.ribos_output_folder, self._args.e_value, self._args.output_all, self._paths.database_folder, self._args.fuzzy, self._args.start_codon, self._args.min_dist_rbs, self._args.max_dist_rbs, self._args.fuzzy_rbs, self._args.UTR_length) ribos = Ribos(args_ribo) ribos.run_ribos(args_ribo)
class TestRibos(unittest.TestCase): def setUp(self): self.example = Example() self.mock_args = MockClass() self.mock = Mock_func() self.test_folder = "test_folder" self.gffs = os.path.join(self.test_folder, "gffs") self.fastas = os.path.join(self.test_folder, "fastas") self.out_folder = os.path.join(self.test_folder, "output") self.database = os.path.join(self.test_folder, "database") self.seq_path = os.path.join(self.test_folder, "seqs") self.tables = os.path.join(self.out_folder, "tables") self.stat = os.path.join(self.out_folder, "statistics") self.scan = os.path.join(self.test_folder, "scan") self.tsss = os.path.join(self.test_folder, "tsss") self.trans = os.path.join(self.test_folder, "trans") self.out_gff = os.path.join(self.out_folder, "gffs") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tsss) os.mkdir(os.path.join(self.tsss, "tmp")) os.mkdir(self.trans) os.mkdir(os.path.join(self.trans, "tmp")) os.mkdir(self.gffs) os.mkdir(os.path.join(self.gffs, "tmp")) os.mkdir(self.fastas) os.mkdir(os.path.join(self.fastas, "tmp")) os.mkdir(self.out_folder) os.mkdir(self.database) os.mkdir(self.seq_path) os.mkdir(os.path.join(self.out_folder, "tmp_table")) os.mkdir(os.path.join(self.out_folder, "tmp_scan")) os.mkdir(os.path.join(self.out_folder, "tmp_fasta")) os.mkdir(os.path.join(self.out_folder, "scan_Rfam")) os.mkdir(self.tables) os.mkdir(self.scan) os.mkdir(self.stat) os.mkdir(self.out_gff) args = self.mock_args.mock() args.gffs = self.gffs args.fastas = self.fastas args.ribos_out_folder = self.out_folder args.database = self.database args.tsss = self.tsss args.trans = self.trans args.program = 'riboswtich' self.ribo = Ribos(args) def tearDown(self): if os.path.exists(self.test_folder): shutil.rmtree(self.test_folder) def test_scan_extract_rfam(self): self.ribo._run_cmscan = self.mock.mock_run_cmscan rb.modify_table = self.mock.mock_modify_table rb.regenerate_seq = self.mock.mock_regenerate_seq rb.reextract_rbs = self.mock.mock_reextract_rbs prefixs = [] gen_file(os.path.join(self.gffs, "tmp/test.gff"), self.example.gff_file) gen_file(os.path.join(self.fastas, "tmp/test.fa"), self.example.fasta_file) gen_file(os.path.join(self.seq_path, "test.fa"), self.example.fasta_file) gen_file(os.path.join(self.tsss, "tmp/test_TSS.gff"), self.example.tss_file) gen_file(os.path.join(self.trans, "tmp/test_transcript.gff"), self.example.tran_file) gen_file(os.path.join(self.out_folder, "tmp_fasta", "test.fa"), self.example.fasta_file) args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.fuzzy = 5 args.fuzzy_rbs = 2 args.utr = True args.output_all = "test" tmp_files = { "fasta": os.path.join(self.out_folder, "tmp_fasta"), "scan": "tmp_scan", "table": os.path.join(self.out_folder, "tmp_table") } rfam = "Rfam_.cm" suffixs = { "csv": "test.csv", "txt": "test_prescan.txt", "re_txt": "test_scan.txt", "re_csv": "test_scan.csv" } self.ribo._scan_extract_rfam(prefixs, args, tmp_files, suffixs, "test", rfam) self.assertListEqual(prefixs, ["test"]) self.assertTrue( os.path.exists( os.path.join(self.out_folder, "tmp_fasta", "test_regenerate.fa"))) def test_merge_results(self): rb.stat_and_covert2gff = self.mock.mock_stat_and_covert2gff gen_file(os.path.join(self.gffs, "test.gff"), self.example.gff_file) gen_file( os.path.join(self.out_folder, "tmp_table/test_riboswitch.csv"), self.example.table) gen_file( os.path.join(self.out_folder, "tmp_scan/test_riboswitch_prescan.txt"), self.example.rescan_file) gen_file( os.path.join(self.out_folder, "tmp_scan/test_riboswitch_scan.txt"), self.example.rescan_file) gen_file(os.path.join(self.test_folder, "ids"), self.example.ids) gen_file(os.path.join(self.tables, "test_riboswitch.csv"), self.example.table) gen_file('test_folder/output/tmp_table/test_test_scan.csv', "test") gen_file( os.path.join("test_folder/output", "tmp_fasta", "test_regenerate.fa"), "test") gen_file('test_folder/output/tmp_scan/test_test_prescan.txt', "test") gen_file('test_folder/output/tmp_scan/test_test_scan.txt', "test") if not os.path.exists('test_folder/output/tmp_table/test_test.csv'): gen_file('test_folder/output/tmp_table/test_test.csv', "test") args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.ribos_id = os.path.join(self.test_folder, "ids") args.fuzzy = 3 suffixs = { "csv": "test.csv", "txt": "test_prescan.txt", "re_txt": "test_scan.txt", "re_csv": "test_scan.csv" } tmp_files = { "fasta": os.path.join(self.out_folder, "tmp_fasta"), "scan": os.path.join(self.out_folder, "tmp_scan"), "table": os.path.join(self.out_folder, "tmp_table") } rfam = "Rfam_.cm" self.ribo._merge_results(args, os.path.join(self.out_folder, "tmp_scan"), suffixs, tmp_files, os.path.join(self.out_folder, "tmp_scan"), os.path.join(self.out_folder, "scan_Rfam"), os.path.join(self.out_folder, "scan_Rfam"), os.path.join(self.out_folder, "gffs"), "riboswitch")
class TestRibos(unittest.TestCase): def setUp(self): self.example = Example() self.mock_args = MockClass() self.mock = Mock_func() self.test_folder = "test_folder" self.gffs = os.path.join(self.test_folder, "gffs") self.fastas = os.path.join(self.test_folder, "fastas") self.out_folder = os.path.join(self.test_folder, "output") self.database = os.path.join(self.test_folder, "database") self.seq_path = os.path.join(self.test_folder, "seqs") self.tables = os.path.join(self.out_folder, "tables") self.stat = os.path.join(self.out_folder, "statistics") self.scan = os.path.join(self.test_folder, "scan") self.tsss = os.path.join(self.test_folder, "tsss") self.trans = os.path.join(self.test_folder, "trans") self.out_gff = os.path.join(self.out_folder, "gffs") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tsss) os.mkdir(os.path.join(self.tsss, "tmp")) os.mkdir(self.trans) os.mkdir(os.path.join(self.trans, "tmp")) os.mkdir(self.gffs) os.mkdir(os.path.join(self.gffs, "tmp")) os.mkdir(self.fastas) os.mkdir(os.path.join(self.fastas, "tmp")) os.mkdir(self.out_folder) os.mkdir(self.database) os.mkdir(self.seq_path) os.mkdir(os.path.join(self.out_folder, "tmp_table")) os.mkdir(os.path.join(self.out_folder, "tmp_scan")) os.mkdir(os.path.join(self.out_folder, "tmp_fasta")) os.mkdir(os.path.join(self.out_folder, "scan_Rfam")) os.mkdir(self.tables) os.mkdir(self.scan) os.mkdir(self.stat) os.mkdir(self.out_gff) args = self.mock_args.mock() args.gffs = self.gffs args.fastas = self.fastas args.out_folder = self.out_folder args.database = self.database args.tsss = self.tsss args.trans = self.trans self.ribo = Ribos(args) def tearDown(self): if os.path.exists(self.test_folder): shutil.rmtree(self.test_folder) def test_scan_extract_rfam(self): self.ribo._run_infernal = self.mock.mock_run_infernal rb.modify_table = self.mock.mock_modify_table prefixs = [] gen_file(os.path.join(self.gffs, "tmp/test.gff"), self.example.gff_file) gen_file(os.path.join(self.fastas, "tmp/test.fa"), self.example.fasta_file) gen_file(os.path.join(self.seq_path, "test.fa"), self.example.fasta_file) gen_file(os.path.join(self.tsss, "tmp/test_TSS.gff"), self.example.tss_file) gen_file(os.path.join(self.trans, "tmp/test_transcript.gff"), self.example.tran_file) gen_file(os.path.join(self.out_folder, "tmp_fasta", "test.fa"), self.example.fasta_file) args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.fuzzy = 5 args.fuzzy_rbs = 2 args.utr = True args.output_all = "test" self.ribo._scan_extract_rfam(prefixs, args) self.assertListEqual(prefixs, ["test"]) self.assertTrue(os.path.exists(os.path.join(self.out_folder, "tmp_fasta", "test_regenerate.fa"))) def test_merge_results(self): gen_file(os.path.join(self.gffs, "test.gff"), self.example.gff_file) gen_file(os.path.join(self.out_folder, "tmp_table/test_riboswitch.csv"), self.example.table) gen_file(os.path.join(self.out_folder, "tmp_scan/test_riboswitch_prescan.txt"), self.example.rescan_file) gen_file(os.path.join(self.out_folder, "tmp_scan/test_riboswitch_scan.txt"), self.example.rescan_file) gen_file(os.path.join(self.test_folder, "ids"), self.example.ids) gen_file(os.path.join(self.tables, "test_riboswitch.csv"), self.example.table) args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.ribos_id = os.path.join(self.test_folder, "ids") args.fuzzy = 3 self.ribo._merge_results(args)
class TestRibos(unittest.TestCase): def setUp(self): self.example = Example() self.mock_args = MockClass() self.mock = Mock_func() self.test_folder = "test_folder" self.gffs = os.path.join(self.test_folder, "gffs") self.fastas = os.path.join(self.test_folder, "fastas") self.out_folder = os.path.join(self.test_folder, "output") self.database = os.path.join(self.test_folder, "database") self.seq_path = os.path.join(self.test_folder, "seqs") self.tables = os.path.join(self.out_folder, "tables") self.stat = os.path.join(self.out_folder, "statistics") self.scan = os.path.join(self.test_folder, "scan") self.tsss = os.path.join(self.test_folder, "tsss") self.trans = os.path.join(self.test_folder, "trans") self.out_gff = os.path.join(self.out_folder, "gffs") if (not os.path.exists(self.test_folder)): os.mkdir(self.test_folder) os.mkdir(self.tsss) os.mkdir(os.path.join(self.tsss, "tmp")) os.mkdir(self.trans) os.mkdir(os.path.join(self.trans, "tmp")) os.mkdir(self.gffs) os.mkdir(os.path.join(self.gffs, "tmp")) os.mkdir(self.fastas) os.mkdir(os.path.join(self.fastas, "tmp")) os.mkdir(self.out_folder) os.mkdir(self.database) os.mkdir(self.seq_path) os.mkdir(os.path.join(self.out_folder, "tmp_table")) os.mkdir(os.path.join(self.out_folder, "tmp_scan")) os.mkdir(os.path.join(self.out_folder, "tmp_fasta")) os.mkdir(os.path.join(self.out_folder, "scan_Rfam")) os.mkdir(self.tables) os.mkdir(self.scan) os.mkdir(self.stat) os.mkdir(self.out_gff) args = self.mock_args.mock() args.gffs = self.gffs args.fastas = self.fastas args.ribos_out_folder = self.out_folder args.database = self.database args.tsss = self.tsss args.trans = self.trans args.program = 'riboswtich' self.ribo = Ribos(args) def tearDown(self): if os.path.exists(self.test_folder): shutil.rmtree(self.test_folder) def test_scan_extract_rfam(self): self.ribo._run_cmscan = self.mock.mock_run_cmscan rb.modify_table = self.mock.mock_modify_table rb.regenerate_seq = self.mock.mock_regenerate_seq rb.reextract_rbs = self.mock.mock_reextract_rbs prefixs = [] gen_file(os.path.join(self.gffs, "tmp/test.gff"), self.example.gff_file) gen_file(os.path.join(self.fastas, "tmp/test.fa"), self.example.fasta_file) gen_file(os.path.join(self.seq_path, "test.fa"), self.example.fasta_file) gen_file(os.path.join(self.tsss, "tmp/test_TSS.gff"), self.example.tss_file) gen_file(os.path.join(self.trans, "tmp/test_transcript.gff"), self.example.tran_file) gen_file(os.path.join(self.out_folder, "tmp_fasta", "test.fa"), self.example.fasta_file) args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.fuzzy = 5 args.fuzzy_rbs = 2 args.utr = True args.without_rbs = False args.rbs_seq = ["AGGAGG"] args.output_all = "test" args.cutoff = "e_0.01" tmp_files = {"fasta": os.path.join(self.out_folder, "tmp_fasta"), "scan": "tmp_scan", "table": os.path.join(self.out_folder, "tmp_table")} rfam = "Rfam_.cm" suffixs = {"csv": "test.csv", "txt": "test_prescan.txt", "re_txt": "test_scan.txt", "re_csv": "test_scan.csv"} log = open(os.path.join(self.test_folder, "test.log"), "w") self.ribo._scan_extract_rfam(prefixs, args, tmp_files, suffixs, "test", rfam, log) self.assertListEqual(prefixs, ["test"]) self.assertTrue(os.path.exists(os.path.join( self.out_folder, "tmp_fasta", "test_regenerate.fa"))) def test_merge_results(self): rb.stat_and_covert2gff = self.mock.mock_stat_and_covert2gff gen_file(os.path.join(self.gffs, "test.gff"), self.example.gff_file) gen_file(os.path.join( self.out_folder, "tmp_table/test_riboswitch.csv"), self.example.table) gen_file(os.path.join( self.out_folder, "tmp_scan/test_riboswitch_prescan.txt"), self.example.rescan_file) gen_file(os.path.join( self.out_folder, "tmp_scan/test_riboswitch_scan.txt"), self.example.rescan_file) gen_file(os.path.join( self.test_folder, "ids"), self.example.ids) gen_file(os.path.join( self.tables, "test_riboswitch.csv"), self.example.table) gen_file('test_folder/output/tmp_table/test_test_scan.csv', "test") gen_file(os.path.join("test_folder/output", "tmp_fasta", "test_regenerate.fa"), "test") gen_file('test_folder/output/tmp_scan/test_test_prescan.txt', "test") gen_file('test_folder/output/tmp_scan/test_test_scan.txt', "test") if not os.path.exists('test_folder/output/tmp_table/test_test.csv'): gen_file('test_folder/output/tmp_table/test_test.csv', "test") args = self.mock_args.mock() args.start_codons = ["ATG"] args.fastas = self.fastas args.out_folder = self.out_folder args.gffs = self.gffs args.ribos_id = os.path.join(self.test_folder, "ids") args.fuzzy = 3 suffixs = {"csv": "test.csv", "txt": "test_prescan.txt", "re_txt": "test_scan.txt", "re_csv": "test_scan.csv"} tmp_files = {"fasta": os.path.join(self.out_folder, "tmp_fasta"), "scan": os.path.join(self.out_folder, "tmp_scan"), "table": os.path.join(self.out_folder, "tmp_table")} rfam = "Rfam_.cm" log = open(os.path.join(self.test_folder, "test.log"), "w") self.ribo._merge_results( args, os.path.join(self.out_folder, "tmp_scan"), suffixs, tmp_files, os.path.join(self.out_folder, "tmp_scan"), os.path.join(self.out_folder, "scan_Rfam"), os.path.join(self.out_folder, "scan_Rfam"), os.path.join(self.out_folder, "gffs"), "riboswitch", log)