Esempio n. 1
0
 def test_compare_tss(self):
     tr.stat_ta_tss = self.mock.mock_stat_ta_tss
     self.tran.multiparser = self.mock_parser
     gen_file(os.path.join(self.gffs, "test_TSS.gff"),
              self.example.gff_file)
     gen_file(os.path.join(self.gffs, "tmp/test_TSS.gff"),
              self.example.gff_file)
     gen_file(os.path.join(self.out_gff, "test_transcript.gff"),
              self.example.tran_file)
     gff_out = os.path.join(self.out, "gffs")
     gen_file(os.path.join(gff_out, "tmp_ta_tss"), self.example.tran_file)
     gen_file(os.path.join(gff_out, "tmp_tss_ta"), self.example.gff_file)
     args = self.mock_args.mock()
     args.out_folder = self.out
     args.trans = self.trans
     args.compare_tss = self.gffs
     args.fuzzy = 2
     log = open(os.path.join(self.test_folder, "test.log"), "w")
     self.tran._compare_tss(["test"], args, log)
     datas = import_data(os.path.join(self.gffs, "test_TSS.gff"))
     self.assertEqual("\n".join(datas),
                      "##gff-version 3\n" + self.example.gff_file)
     datas = import_data(os.path.join(self.out_gff, "test_transcript.gff"))
     self.assertEqual("\n".join(datas),
                      "##gff-version 3\n" + self.example.tran_file)
Esempio n. 2
0
 def test_convert_circ2gff(self):
     circ_file = os.path.join(self.test_folder, "circ.csv")
     out_all = os.path.join(self.test_folder, "all.gff")
     out_filter = os.path.join(self.test_folder, "best.gff")
     with open(circ_file, "w") as ch:
         ch.write(self.circ_file)
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     self.converter.convert_circ2gff(circ_file, args, out_all, out_filter)
     datas = import_data(out_all)
     f_datas = []
     for data in datas:
         if not data.startswith("#"):
             f_datas.append("\t".join(data.split("\t")[:8]))
     c_datas = []
     for data in self.circ_all.split("\n"):
         if not data.startswith("#"):
             c_datas.append("\t".join(data.split("\t")[:8]))
     self.assertListEqual(f_datas, c_datas)
     datas = import_data(out_filter)
     f_datas = []
     for data in datas:
         if not data.startswith("#"):
             f_datas.append("\t".join(data.split("\t")[:8]))
     c_datas = []
     for data in self.circ_best.split("\n"):
         if not data.startswith("#"):
             c_datas.append("\t".join(data.split("\t")[:8]))
     self.assertListEqual(f_datas, c_datas)
Esempio n. 3
0
 def test_extract_blast(self):
     esi.read_gff = Mock_func().mock_read_gff
     nr_blast = os.path.join(self.test_folder, "nr_table")
     gen_file(nr_blast, self.example.blast_nr_all)
     srna_blast = os.path.join(self.test_folder, "srna_table")
     gen_file(srna_blast, self.example.blast_srna_all)
     output_file = os.path.join(self.test_folder, "out.gff")
     output_table = os.path.join(self.test_folder, "out.csv")
     esi.extract_blast(nr_blast, "test.srna", output_file, output_table,
                       "nr", None, None)
     datas, attributes = extract_info(output_file, "file")
     refs, ref_attributes = extract_info(self.example.out_nr_gff, "string")
     self.assertEqual(set(datas), set(refs[1:]))
     self.assertEqual(set(attributes[0]), set(attributes[0]))
     self.assertEqual(set(attributes[1]), set(attributes[1]))
     datas = import_data(output_table)
     esi.extract_blast(srna_blast, "test.srna", output_file, output_table,
                       "sRNA", None, None)
     datas, attributes = extract_info(output_file, "file")
     refs, ref_attributes = extract_info(self.example.out_srna_gff,
                                         "string")
     self.assertEqual(set(datas), set(refs[1:]))
     self.assertEqual(set(attributes[0]), set(attributes[0]))
     self.assertEqual(set(attributes[1]), set(attributes[1]))
     datas = import_data(output_table)
     self.assertEqual(set(datas),
                      set(self.example.out_srna_csv.split("\n")))
Esempio n. 4
0
 def test_convert_circ2gff(self):
     circ_file = os.path.join(self.test_folder, "circ.csv")
     out_all = os.path.join(self.test_folder, "all.gff")
     out_filter = os.path.join(self.test_folder, "best.gff")  
     with open(circ_file, "w") as ch:
         ch.write(self.circ_file)
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     self.converter.convert_circ2gff(circ_file, args, out_all, out_filter)
     datas = import_data(out_all)
     f_datas = []
     for data in datas:
         if not data.startswith("#"):
             f_datas.append("\t".join(data.split("\t")[:8]))
     c_datas = []
     for data in self.circ_all.split("\n"):
         if not data.startswith("#"):
             c_datas.append("\t".join(data.split("\t")[:8]))
     self.assertListEqual(f_datas, c_datas)
     datas = import_data(out_filter)
     f_datas = []
     for data in datas:
         if not data.startswith("#"):
             f_datas.append("\t".join(data.split("\t")[:8]))
     c_datas = []
     for data in self.circ_best.split("\n"):
         if not data.startswith("#"):
             c_datas.append("\t".join(data.split("\t")[:8]))
     self.assertListEqual(f_datas, c_datas)
Esempio n. 5
0
 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)
Esempio n. 7
0
 def test_compare_tss(self):
     tr.stat_ta_tss = self.mock.mock_stat_ta_tss
     self.tran.multiparser = self.mock_parser
     gen_file(os.path.join(self.gffs, "test_TSS.gff"),
              self.example.gff_file)
     gen_file(os.path.join(self.gffs, "tmp/test_TSS.gff"),
              self.example.gff_file)
     gen_file(os.path.join(self.out_gff, "test_transcript.gff"),
              self.example.tran_file)
     gff_out = os.path.join(self.out, "gffs")
     gen_file(os.path.join(gff_out, "tmp_ta_tss"), self.example.tran_file)
     gen_file(os.path.join(gff_out, "tmp_tss_ta"), self.example.gff_file)
     args = self.mock_args.mock()
     args.out_folder = self.out
     args.trans = self.trans
     args.compare_tss = self.gffs
     args.fuzzy = 2
     log = open(os.path.join(self.test_folder, "test.log"), "w")
     self.tran._compare_tss(["test"], args, log)
     datas = import_data(os.path.join(self.gffs, "test_TSS.gff"))
     self.assertEqual("\n".join(datas),
                      "##gff-version 3\n" + self.example.gff_file)
     datas = import_data(os.path.join(self.out_gff, "test_transcript.gff"))
     self.assertEqual("\n".join(datas),
                      "##gff-version 3\n" + self.example.tran_file)
Esempio n. 8
0
 def test_transcript_snp(self):
     fasta = os.path.join(self.test_folder, "NC_007795.1.fa")
     gen_file(fasta, self.example.fasta)
     snp = os.path.join(self.test_folder, "NC_007795.1.csv")
     gen_file(snp, self.example.snp)
     args = self.mock_args.mock()
     args.depth = 5
     args.fraction = 0.3
     args.quality = 2
     args.depth_s = "n_10"
     args.depth_b = "a_2"
     args.dp4_sum = "n_10"
     args.dp4_frac = 0.5
     args.idv = "n_10"
     args.imf = 0.5
     args.filters = ["VDB_s0.1"]
     args.min_sample = 2
     os.mkdir(os.path.join(self.test_folder, "compare_reference/seqs/with_BAQ/test"))
     depth_file = os.path.join(self.test_folder, "tmp_depth")
     gen_file(depth_file, self.example.depth_file)
     self.snp._transcript_snp(fasta, snp, "test", "with",
                              "test", 10, self.table, args)
     datas = import_data(os.path.join(self.test_folder, "compare_reference/statistics/stat_test_with_BAQ_SNP_best.csv"))
     self.assertEqual("\n".join(datas), self.example.out_stat)
     datas = import_data(os.path.join(self.test_folder, "compare_reference/seqs/with_BAQ/test/test_NC_007795.1_1_1.fa"))
     self.assertEqual("\n".join(datas), ">NC_007795.1\nAaTTGaaTCCCGAACGACAGTTAT")
     os.remove("test_seq_reference.csv")
     os.remove("test_best.vcf")
     os.remove("test_NC_007795.1_SNP_QUAL_best.png")
     os.remove("test_NC_007795.1_SNP_QUAL_raw.png")
Esempio n. 9
0
 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)
Esempio n. 10
0
 def test_transcript_snp(self):
     fasta = os.path.join(self.test_folder, "NC_007795.1.fa")
     gen_file(fasta, self.example.fasta)
     snp_folder = os.path.join(
         self.test_folder,
         "compare_related_and_reference_genomes/SNP_raw_outputs/test")
     os.mkdir(snp_folder)
     snp = os.path.join(snp_folder, "test_with_BAQ_NC_007795.1.vcf")
     gen_file(snp, self.example.snp)
     args = self.mock_args.mock()
     args.depth = 5
     args.fraction = 0.3
     args.quality = 2
     args.depth_s = "n_10"
     args.depth_b = "a_2"
     args.dp4_sum = "n_10"
     args.dp4_frac = 0.5
     args.idv = "n_10"
     args.imf = 0.5
     args.filters = ["VDB_s0.1"]
     args.min_sample = 2
     os.mkdir(
         os.path.join(
             self.test_folder,
             "compare_related_and_reference_genomes/seqs/with_BAQ/test"))
     depth_file = os.path.join(self.test_folder, "tmp_depthNC_007795.1")
     gen_file(depth_file, self.example.depth_file)
     bam_datas = [{
         "sample": "NC_007795.1",
         "bam_number": 1,
         "bams": "test",
         "rep": 1
     }]
     self.snp._transcript_snp(
         fasta,
         "test",
         "with",
         "test",
         bam_datas,
         self.table,
         args,
     )
     datas = import_data(
         os.path.join(
             self.test_folder,
             "compare_related_and_reference_genomes/statistics/stat_test_with_BAQ_NC_007795.1_SNP_best.csv"
         ))
     print("\n".join(datas))
     self.assertEqual("\n".join(datas), self.example.out_stat)
     datas = import_data(
         os.path.join(
             self.test_folder,
             "compare_related_and_reference_genomes/seqs/with_BAQ/test/test_NC_007795.1_NC_007795.1_1_1.fa"
         ))
     self.assertEqual("\n".join(datas),
                      ">NC_007795.1\nAaTTGaaTCCCGAACGACAGTTAT")
     os.remove("test_NC_007795.1_seq_reference.csv")
     os.remove("test_NC_007795.1_best.vcf")
     os.remove("test_NC_007795.1_NC_007795.1_SNP_QUAL_best.png")
     os.remove("test_NC_007795.1_NC_007795.1_SNP_QUAL_raw.png")
Esempio n. 11
0
 def test_parser_embl_gbk(self):
     files = [os.path.join(self.test_folder, "aaa.gbk")]
     gen_file(os.path.join(self.test_folder, "aaa.gbk"), self.example.gbk_file)
     self.ratt._parser_embl_gbk(files)
     data = import_data(os.path.join(self.ref_embls, "gbk_tmp/NC_007795.1.gbk"))
     self.assertEqual("\n".join(data), self.example.gbk_file.split("//")[0] + "//")
     data = import_data(os.path.join(self.ref_embls, "gbk_tmp/NC_007799.1.gbk"))
     self.assertEqual("\n".join(data), self.example.gbk_file.split("//")[1].strip() + "\n//")
Esempio n. 12
0
 def test_modify_seq(self):
     mod_table = os.path.join(self.test_folder, "mod")
     gen_file(mod_table, self.example.mutation)
     gen_file(os.path.join(self.fasta, "NC_000915.1.fa"), self.example.fasta)
     self.seq.modify_seq(self.fasta, mod_table, self.test_folder)
     datas = import_data(os.path.join(self.test_folder, "NC_test.1.fa"))
     self.assertEqual("\n".join(datas), self.example.out_1)
     datas = import_data(os.path.join(self.test_folder, "test_case2.fa"))
     self.assertEqual("\n".join(datas), self.example.out_2)
Esempio n. 13
0
 def test_get_pubmed(self):
     out_all = StringIO()
     out_best = StringIO()
     out_noall = StringIO()
     out_nobest = StringIO()
     self.ppi._run_wget = self.mock.mock_run_wget
     files = {
         "id_list": self.test_folder,
         "id_log": "test",
         "pubmed_log": "test",
         "all_specific": out_all,
         "best_specific": out_best,
         "all_nospecific": out_noall,
         "best_nospecific": out_nobest
     }
     row = self.example.ppi_line.split("\t")
     strain_id = {
         "file": "test_file",
         "ptt": "test_ptt",
         "string": "test_string",
         "pie": "test_pie"
     }
     mode = "interaction"
     actor = "test_A"
     score = 11241
     id_file = "SAOUHSC_01684"
     ptt = "test_ptt"
     gen_file(os.path.join(self.test_folder, "SAOUHSC_01684"),
              "93061.SAOUHSC_01684\t93061.SAOUHSC_01683\t333\ttest_aaa")
     gen_file(os.path.join(self.test_folder, "SAOUHSC_01683"),
              "93061.SAOUHSC_01683\t93061.SAOUHSC_01684\t333\ttest_bbb")
     paths = {
         "all": self.test_folder,
         "fig": self.test_folder,
         "best": self.test_folder
     }
     querys = "all"
     first_output = {
         "specific_all": True,
         "specific_best": True,
         "nospecific_all": True,
         "nospecific_best": True
     }
     args = self.mock_args.mock()
     args.out_folder = self.test_folder
     args.querys = "all"
     args.no_specific = True
     args.score = 19
     self.ppi._get_pubmed(row, strain_id, mode, actor, id_file,
                          first_output, ptt, files, paths, args)
     data = import_data(
         "test_folder/without_strain/test_ptt/test_aaa_test_bbb.csv")
     self.assertEqual("\n".join(data), self.example.with_out)
     data = import_data(
         "test_folder/with_strain/test_ptt/test_aaa_test_bbb.csv")
     self.assertEqual("\n".join(data), self.example.with_out)
Esempio n. 14
0
 def test_modify_seq(self):
     mod_table = os.path.join(self.test_folder, "mod")
     gen_file(mod_table, self.example.mutation)
     gen_file(os.path.join(self.fasta, "NC_000915.1.fa"),
              self.example.fasta)
     self.seq.modify_seq(self.fasta, mod_table, self.test_folder)
     datas = import_data(os.path.join(self.test_folder, "NC_test.1.fa"))
     self.assertEqual("\n".join(datas), self.example.out_1)
     datas = import_data(os.path.join(self.test_folder, "test_case2.fa"))
     self.assertEqual("\n".join(datas), self.example.out_2)
Esempio n. 15
0
 def test_convert_to_pttrnt(self):
     files = ["aaa.gff"]
     gen_file(os.path.join(self.test_folder, "aaa.gff"), self.example.gff_file)
     os.mkdir(os.path.join(self.tar_fastas, "tmp"))
     gen_file(os.path.join(self.tar_fastas, "tmp/aaa.fa"), self.example.fasta_file)
     self.ratt._convert_to_pttrnt(self.test_folder, files)
     data = import_data(os.path.join(self.test_folder, "aaa.rnt"))
     self.assertEqual("\n".join(data), self.example.rnt_file)
     data = import_data(os.path.join(self.test_folder, "aaa.ptt"))
     self.assertEqual("\n".join(data), self.example.ptt_file)
 def test_regenerate_seq(self):
     out_table = os.path.join(self.test_folder, "table")
     out_seq = os.path.join(self.test_folder, "seq")
     align_file = os.path.join(self.test_folder, "align")
     seq_file = os.path.join(self.test_folder, "ribo_seq")
     gen_file(align_file, self.example.scan_file)
     gen_file(seq_file, self.example.seq_file)
     rr.regenerate_seq(align_file, seq_file, out_table, out_seq)
     data = import_data(out_table)
     self.assertEqual("\n".join(data), "riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t10\t16\tRF00162\t6.2e-18\t5\t12")
     data = import_data(out_seq)
     self.assertEqual("\n".join(data), ">riboswitch_5|Staphylococcus_aureus_HG003|+|SAOUHSC_00013|14|21\nATTATTAC")
Esempio n. 17
0
 def test_convert_to_pttrnt(self):
     files = ["aaa.gff"]
     gen_file(os.path.join(self.test_folder, "aaa.gff"),
              self.example.gff_file)
     os.mkdir(os.path.join(self.tar_fastas, "tmp"))
     gen_file(os.path.join(self.tar_fastas, "tmp/aaa.fa"),
              self.example.fasta_file)
     self.ratt._convert_to_pttrnt(self.test_folder, files)
     data = import_data(os.path.join(self.test_folder, "aaa.rnt"))
     self.assertEqual("\n".join(data), self.example.rnt_file)
     data = import_data(os.path.join(self.test_folder, "aaa.ptt"))
     self.assertEqual("\n".join(data), self.example.ptt_file)
Esempio n. 18
0
 def test_parser_embl_gbk(self):
     files = [os.path.join(self.test_folder, "aaa.gbk")]
     gen_file(os.path.join(self.test_folder, "aaa.gbk"),
              self.example.gbk_file)
     self.ratt._parser_embl_gbk(files)
     data = import_data(
         os.path.join(self.ref_gbk, "gbk_tmp/NC_007795.1.gbk"))
     self.assertEqual("\n".join(data),
                      self.example.gbk_file.split("//")[0] + "//")
     data = import_data(
         os.path.join(self.ref_gbk, "gbk_tmp/NC_007799.1.gbk"))
     self.assertEqual("\n".join(data),
                      self.example.gbk_file.split("//")[1].strip() + "\n//")
Esempio n. 19
0
 def test_convert_to_gff(self):
     files = ["aaa.gff"]
     ratt_result = "chromosome.aaa.final.embl"
     gen_file(os.path.join(self.output_path, ratt_result),
              self.example.embl_file)
     args = self.mock_args.mock()
     args.output_path = self.output_path
     args.gff_outfolder = self.gff_outfolder
     self.ratt._convert_to_gff(ratt_result, args, files)
     data = import_data(os.path.join(self.output_path, "aaa.gff"))
     self.assertEqual("\n".join(data), self.example.embl_gff)
     data = import_data(os.path.join(self.gff_outfolder, "aaa.gff"))
     self.assertEqual("\n".join(data), self.example.embl_gff)
Esempio n. 20
0
    def test_convert_to_gff(self):
        files = ["aaa.gff"]
        ratt_result = "chromosome.aaa.final.embl"
        gen_file(os.path.join(self.output_path, ratt_result), self.example.embl_file)
        args = self.mock_args.mock()
        args.output_path = self.output_path
        args.gff_outfolder = self.gff_outfolder
        self.ratt._convert_to_gff(ratt_result, args, files)
#        self.ratt._convert_to_gff(ratt_result, self.output_path, self.gff_outfolder, files)
        data = import_data(os.path.join(self.output_path, "aaa.gff"))
        self.assertEqual("\n".join(data), self.example.embl_gff)
        data = import_data(os.path.join(self.gff_outfolder, "aaa.gff"))
        self.assertEqual("\n".join(data), self.example.embl_gff)
Esempio n. 21
0
 def test_detect_circrna(self):
     out_file = os.path.join(self.test_folder, "out_all.csv")
     stat_file = os.path.join(self.test_folder, "stat.csv")
     circ.read_file = Mock_read_file().read_file
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     args.hypo = True
     circ.detect_circrna("test.circ", "test.gff", out_file, args, stat_file)
     circs = import_data(out_file)
     stats = import_data(stat_file)
     self.assertEqual(set(circs), set(self.example.out_file.split("\n")))
     self.assertEqual(set(stats), set(self.example.stat_file.split("\n")))
Esempio n. 22
0
 def test_detect_circrna(self):
     out_file = os.path.join(self.test_folder, "out_all.csv")
     stat_file = os.path.join(self.test_folder, "stat.csv")
     circ.read_file = Mock_read_file().read_file
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     args.hypo = True
     circ.detect_circrna("test.circ", "test.gff", out_file, args, stat_file)
     circs = import_data(out_file)
     stats = import_data(stat_file)
     self.assertEqual(set(circs), set(self.example.out_file.split("\n")))
     self.assertEqual(set(stats), set(self.example.stat_file.split("\n")))
Esempio n. 23
0
    def test_modify_table(self):
        result = """#ID\tGenome\tStrand\tAssociated_CDS\tStart_genome\tEnd_genome\tRfam\tE_value\tScore\tStart_align\tEnd_align
riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t15948\t16046\tRF00162\t1.6e-18\t74\t1\t99
riboswitch_11\tStaphylococcus_aureus_HG003\t-\tSAOUHSC_00007\t27955\t28053\tRF00162\t1.6e-18\t74\t1\t99
riboswitch_183\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00372\t377996\t378098\tRF00167\t2.2e-18\t45\t1\t103"""
        table = os.path.join(self.test_folder, "test")
        gen_file(table, self.example.ribos)
        mrt.modify_table(table, True)
        data = import_data(table)
        self.assertEqual("\n".join(data), result)
        gen_file(table, self.example.ribos)
        mrt.modify_table(table, False)
        data = import_data(table)
        self.assertEqual("\n".join(data), result)
Esempio n. 24
0
    def test_modify_table(self):
        result = """#ID\tstrain\tstrand\tassociated_CDS\tstart_genome\tend_genome	Rfam	e_value	start_align	end_align
riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t15948\t16046	RF00162	1.6e-18	1	99
riboswitch_11\tStaphylococcus_aureus_HG003\t-\tSAOUHSC_00007\t27955\t28053	RF00162	1.6e-18	1	99
riboswitch_183\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00372\t377996\t378098	RF00167	2.2e-18	1	103"""
        table = os.path.join(self.test_folder, "test")
        gen_file(table, self.example.ribos)
        mrt.modify_table(table, True)
        data = import_data(table)
        self.assertEqual("\n".join(data), result)
        gen_file(table, self.example.ribos)
        mrt.modify_table(table, False)
        data = import_data(table)
        self.assertEqual("\n".join(data), result)
Esempio n. 25
0
 def test_stat_term(self):
     term_gff = os.path.join(self.test_folder, "aaa_term.gff")
     term_table = os.path.join(self.test_folder, "aaa_term.csv")
     stat = os.path.join(self.test_folder, "stat")
     output_decrease = os.path.join(self.test_folder, "decrease")
     output_expression = os.path.join(self.test_folder, "expression")
     output_non = os.path.join(self.test_folder, "non_expressed")
     gen_file(term_gff, self.example.gff)
     gen_file(term_table, self.example.table)
     st.stat_term(term_gff, term_table, stat, output_decrease, output_expression, output_non)
     self.assertTrue(stat)
     datas = import_data(output_decrease + ".csv")
     self.assertEqual("\n".join(datas), self.example.table)
     datas = import_data(output_expression + ".csv")
     self.assertEqual("\n".join(datas), self.example.table)
Esempio n. 26
0
 def test_convert_circ2gff(self):
     circ_file = os.path.join(self.test_folder, "circ.csv")
     out_all = os.path.join(self.test_folder, "all.gff")
     out_filter = os.path.join(self.test_folder, "best.gff")  
     with open(circ_file, "w") as ch:
         ch.write(self.circ_file)
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     self.converter.convert_circ2gff(circ_file, args, out_all, out_filter)
     datas = import_data(out_all)
     self.assertEqual(set(datas), set(self.circ_all.split("\n")))
     datas = import_data(out_filter)
     self.assertEqual(set(datas), set(self.circ_best.split("\n")))
Esempio n. 27
0
 def test_merge_wigs(self):
     gen_file(os.path.join(self.wigs, "test1_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_reverse.wig"), "test_r")
     gen_file(os.path.join(self.wigs, "test1_TEX_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_TEX_reverse.wig"), "test_r")
     libs = ["test1_forward.wig:notex:1:a:+",
             "test1_reverse.wig:notex:1:a:-",
             "test1_TEX_forward.wig:tex:1:a:+",
             "test1_TEX_reverse.wig:tex:1:a:-"]
     self.tss._merge_wigs(self.wigs, "test", libs)
     datas = import_data(os.path.join("tmp", "merge_forward.wig"))
     self.assertEqual("\n".join(datas), "test_ftest_f")
     datas = import_data(os.path.join("tmp", "merge_reverse.wig"))
     self.assertEqual("\n".join(datas), "test_rtest_r")
     shutil.rmtree("tmp")
Esempio n. 28
0
 def test_merge_wigs(self):
     gen_file(os.path.join(self.wigs, "test1_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_reverse.wig"), "test_r")
     gen_file(os.path.join(self.wigs, "test1_TEX_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_TEX_reverse.wig"), "test_r")
     libs = ["test1_forward.wig:notex:1:a:+",
             "test1_reverse.wig:notex:1:a:-",
             "test1_TEX_forward.wig:tex:1:a:+",
             "test1_TEX_reverse.wig:tex:1:a:-"]
     self.tss._merge_wigs(self.wigs, "test", libs)
     datas = import_data(os.path.join("tmp", "merge_forward.wig"))
     self.assertEqual("\n".join(datas), "test_ftest_f")
     datas = import_data(os.path.join("tmp", "merge_reverse.wig"))
     self.assertEqual("\n".join(datas), "test_rtest_r")
     shutil.rmtree("tmp")
Esempio n. 29
0
 def test_stat_term(self):
     term_gff = os.path.join(self.test_folder, "aaa_term.gff")
     term_table = os.path.join(self.test_folder, "aaa_term.csv")
     stat = os.path.join(self.test_folder, "stat")
     output_decrease = os.path.join(self.test_folder, "decrease")
     output_expression = os.path.join(self.test_folder, "expression")
     output_non = os.path.join(self.test_folder, "non_expressed")
     gen_file(term_gff, self.example.gff)
     gen_file(term_table, self.example.table)
     st.stat_term(term_gff, term_table, stat, output_decrease, output_expression, output_non)
     self.assertTrue(stat)
     datas = import_data(output_decrease + ".csv")
     self.assertEqual("\n".join(datas), self.example.table)
     datas = import_data(output_expression + ".csv")
     self.assertEqual("\n".join(datas), self.example.table)
Esempio n. 30
0
 def test_convert_circ2gff(self):
     circ_file = os.path.join(self.test_folder, "circ.csv")
     out_all = os.path.join(self.test_folder, "all.gff")
     out_filter = os.path.join(self.test_folder, "best.gff")
     with open(circ_file, "w") as ch:
         ch.write(self.circ_file)
     args = self.mock_args.mock()
     args.start_ratio = 0.5
     args.end_ratio = 0.5
     args.support = 5
     self.converter.convert_circ2gff(circ_file, args, out_all, out_filter)
     datas = import_data(out_all)
     self.assertEqual(set(datas), set(self.circ_all.split("\n")))
     datas = import_data(out_filter)
     self.assertEqual(set(datas), set(self.circ_best.split("\n")))
Esempio n. 31
0
 def test_stat_ta_gff(self):
     gff_file = os.path.join(self.test_folder, "aaa.gff")
     ta_file = os.path.join(self.test_folder, "aaa_transcript.gff")
     gen_file(gff_file, self.example.gff)
     gen_file(ta_file, self.example.ta)
     stat_file = os.path.join(self.test_folder, "stat")
     out_ta_file = os.path.join(self.test_folder, "out_ta.gff")
     out_gff_file = os.path.join(self.test_folder, "out.gff")
     stc.stat_ta_gff(ta_file, gff_file, stat_file, out_ta_file,
                     out_gff_file, ["gene"])
     datas = import_data(stat_file)
     self.assertEqual("\n".join(datas), "For gene:\n\tAll strains:\n\tThe transcriptome assembly information compares with gene:\n" + \
                                         self.example.print_tag)
     datas, attributes = extract_info(out_ta_file, "file")
     self.assertListEqual(
         datas,
         ['aaa\tfragmented_and_normal\tTranscript\t313\t3344\t.\t+\t.'])
     for attribute in attributes:
         if "type" in attribute:
             self.assertEqual(attribute, "type=cover_CDS")
         if "associated_cds=" in attribute:
             self.assertEqual(attribute, "associated_cds=YP_498609.1")
     datas, attributes = extract_info(out_gff_file, "file")
     self.assertListEqual(datas, [
         'aaa\tRefseq\tgene\t517\t1878\t.\t+\t.',
         'aaa\tRefseq\tCDS\t517\t1878\t.\t+\t.'
     ])
     for attribute in attributes:
         if "Parent_tran" in attribute:
             self.assertEqual(attribute, "Parent_tran=tran0")
Esempio n. 32
0
 def test_stat_ta_tss(self):
     tss_file = os.path.join(self.test_folder, "aaa_TSS.gff")
     ta_file = os.path.join(self.test_folder, "aaa_transcript.gff")
     gen_file(tss_file, self.example.tss)
     gen_file(ta_file, self.example.ta)
     stat_file = os.path.join(self.test_folder, "stat")
     out_ta_file = os.path.join(self.test_folder, "out_ta.gff")
     out_tss_file = os.path.join(self.test_folder, "out_tss.gff")
     stc.stat_ta_tss(ta_file, tss_file, stat_file, out_ta_file,
                     out_tss_file, 5)
     datas = import_data(stat_file)
     self.assertEqual("\n".join(datas),
                      "All strains:\n" + self.example.print_tas)
     datas, attributes = extract_info(out_ta_file, "file")
     self.assertListEqual(
         datas,
         ['aaa\tfragmented_and_normal\tTranscript\t313\t3344\t.\t+\t.'])
     for attribute in attributes:
         if "associated_tss" in attribute:
             self.assertEqual("associated_tss=TSS:2131_f")
     datas, attributes = extract_info(out_tss_file, "file")
     self.assertListEqual(datas,
                          ['aaa\tTSSpredator\tTSS\t2131\t2131\t.\t+\t.'])
     for attribute in attributes:
         if "Parent_tran" in attribute:
             self.assertEqual(attribute, "Parent_tran=tran0")
 def test_gene_expression(self):
     gea.read_wig = MockFunc().mock_read_wig
     gea.read_libs = MockFunc().mock_read_libs
     gea.read_data = MockFunc().mock_read_data
     replicates = {"tex": 1, "frag": 1}
     stat_folder = os.path.join(self.test_folder, "stat")
     gff_folder = os.path.join(self.test_folder, "gff")
     if os.path.exists(gff_folder):
         shutil.rmtree(gff_folder)
     os.mkdir(gff_folder)
     gen_file(os.path.join(gff_folder, "aaa.gff"), "test")
     if not os.path.exists(stat_folder):
         os.mkdir(stat_folder)
     out_gff_folder = os.path.join(self.test_folder, "out_gff")
     if not os.path.exists(out_gff_folder):
         os.mkdir(out_gff_folder)
     gea.gene_expression(None, gff_folder, "all", "all", "test_wig", "test_wig", ["CDS"],
                        "test_wig_folder", 5, 2, replicates, stat_folder, out_gff_folder,
                        "high", 100, 0)
     datas = import_data(os.path.join(stat_folder, "aaa_CDS.csv"))
     dicts = {}
     for data in datas:
         dicts[data] = data
     refs = {}
     for data in self.example.out_stat.split("\n"):
         refs[data] = data
     self.assertDictEqual(dicts, refs)
Esempio n. 34
0
 def test_sort_srna_fasta(self):
     fasta = os.path.join(self.fastas, "test.fa")
     gen_file(fasta, ">aaa\nAAAAAAAA\n>bbb\nCCCC\n>ccc\nGGGGGGGGGGGG")
     self.star._sort_srna_fasta(fasta, "test", self.test_folder)
     datas = import_data(os.path.join(self.test_folder, "tmp_srna_target_test_sRNA.fa"))
     self.assertListEqual(datas, ['>bbb', 'CCCC', '>aaa', 'AAAAAAAA',
                                  '>ccc', 'GGGGGGGGGGGG'])
Esempio n. 35
0
 def test_gen_config(self):
     os.mkdir(os.path.join(self.out, "MasterTables"))
     os.mkdir(os.path.join(self.wigs, "tmp"))
     config_file = os.path.join(self.test_folder, "config")
     libs = [
         "test1_forward.wig:notex:1:a:+", "test1_reverse.wig:notex:1:a:-",
         "test1_TEX_forward.wig:tex:1:a:+",
         "test1_TEX_reverse.wig:tex:1:a:-"
     ]
     args = self.mock_args.mock()
     args.out_folder = self.out
     args.program = "TSS"
     args.height = 0.3
     args.height_reduction = 0.2
     args.factor = 2.0
     args.factor_reduction = 0.5
     args.base_height = 0.00
     args.enrichment_factor = 2.0
     args.processing_factor = 1.5
     args.utr_length = 300
     args.cluster = 3
     args.repmatch = ["all_2"]
     args.libs = libs
     args.output_prefixs = ["test1"]
     args.specify_strains = None
     self.tss._gen_config("test", args, self.gffs + "/tmp/test.gff",
                          self.wigs + "/tmp", self.fastas + "/tmp/test.fa",
                          config_file)
     datas = import_data(config_file)
     self.assertEqual("\n".join(datas), self.example.config)
Esempio n. 36
0
 def test_low_expression(self):
     ts.filter_low_expression = self.mock.mock_filter_low_expression
     gen_file(os.path.join(self.wigs, "test1_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_reverse.wig"), "test_r")
     gen_file(os.path.join(self.wigs, "test1_TEX_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_TEX_reverse.wig"), "test_r")
     gen_file(os.path.join(self.gffs, "test_TSS.gff"),
              self.example.tss_file)
     os.mkdir(os.path.join(self.out, "statistics"))
     os.mkdir(os.path.join(self.out, "statistics/test"))
     libs = [
         "test1_TEX_forward.wig:tex:1:a:+",
         "test1_TEX_reverse.wig:tex:1:a:-", "test1_forward.wig:notex:1:a:+",
         "test1_reverse.wig:notex:1:a:-"
     ]
     args = self.mock_args.mock()
     args.manual = "manual"
     args.libs = libs
     args.wig_folder = self.wigs
     args.program = "TSS"
     args.cluster = 3
     self.tss._low_expression(args, self.gffs)
     shutil.rmtree("tmp")
     datas = import_data(
         os.path.join(
             self.out,
             "statistics/test/stat_test_low_expression_cutoff.csv"))
     self.assertEqual("\n".join(datas),
                      "Genome\tCutoff_coverage\ntest\t100")
 def test_assembly(self):
     wig_f_file = os.path.join(self.test_folder, "aaa_forward.wig")
     wig_r_file = os.path.join(self.test_folder, "aaa_reverse.wig")
     wig_f2_file = os.path.join(self.test_folder, "aaa2_forward.wig")
     wig_r2_file = os.path.join(self.test_folder, "aaa2_reverse.wig")
     gen_file(wig_f_file, self.example.wig_f)
     gen_file(wig_r_file, self.example.wig_r)
     gen_file(wig_f2_file, self.example.wig_f)
     gen_file(wig_r2_file, self.example.wig_r)
     reps = {"tex": 1, "frag": 1}
     out_file = os.path.join(self.test_folder, "out")
     input_lib = ["aaa_forward.wig:frag:1:a:+",
                  "aaa_reverse.wig:frag:1:a:-",
                  "aaa2_forward.wig:tex:1:a:+",
                  "aaa2_reverse.wig:tex:1:a:-"]
     args = self.mock_args.mock()
     args.replicates = reps
     args.height = 10
     args.width = 1
     args.tolerance = 3
     args.tex = 2
     args.low_cutoff = 5
     ta.assembly(wig_f_file, wig_r_file, self.test_folder, input_lib,
                 out_file, "TEX", args)
     datas = import_data(out_file)
     self.assertEqual("\n".join(datas), "##gff-version 3\n" + self.example.out_tran)
Esempio n. 38
0
 def test_stat(self):
     input_file = os.path.join(self.test_folder, "input_file")
     output_file = os.path.join(self.test_folder, "output_file")
     gen_file(input_file, self.example.operon)
     so.stat(input_file, output_file)
     datas = import_data(output_file)
     for data in datas:
         if "the number of operons which have sub-operons and " in data:
             self.assertEqual(
                 data,
                 "\tthe number of operons which have sub-operons and start with tss = 1 (1.0)"
             )
         if "the number of operons which have sub-operons = " in data:
             self.assertEqual(
                 data,
                 "\tthe number of operons which have sub-operons = 1 (1.0)")
         if "the number of operons which start with tss = " in data:
             self.assertEqual(
                 data,
                 "\tthe number of operons which start with tss = 1 (1.0)")
         if "no associated with CDS: " in data:
             self.assertEqual(data, "\tno associated with CDS: 0 (0.0)")
         if "monocistronic: " in data:
             self.assertEqual(data, "\tmonocistronic: 0 (0.0)")
         if "polycistronic: " in data:
             self.assertEqual(data, "\tpolycistronic: 1 (1.0)")
Esempio n. 39
0
 def test_set_gen_config(self):
     os.mkdir(os.path.join(self.fastas, "tmp"))
     os.mkdir(os.path.join(self.gffs, "tmp"))
     os.mkdir(os.path.join(self.wigs, "tmp"))
     os.mkdir(os.path.join(self.out, "MasterTables"))
     gen_file(os.path.join(self.fastas, "tmp/test.fa"), "test")
     gen_file(os.path.join(self.gffs, "tmp/test.gff"), "test")
     gen_file(os.path.join(self.wigs, "tmp/test1_forward.wig_STRAIN_test.wig"), "test")
     gen_file(os.path.join(self.wigs, "tmp/test1_reverse.wig_STRAIN_test.wig"), "test")
     gen_file(os.path.join(self.wigs, "tmp/test1_TEX_forward.wig_STRAIN_test.wig"), "test")
     gen_file(os.path.join(self.wigs, "tmp/test1_TEX_reverse.wig_STRAIN_test.wig"), "test")
     libs = ["test1_forward.wig:notex:1:a:+",
             "test1_reverse.wig:notex:1:a:-",
             "test1_TEX_forward.wig:tex:1:a:+",
             "test1_TEX_reverse.wig:tex:1:a:-"]
     args = self.mock_args.mock()
     args.program = "TSS"
     args.height = 0.3
     args.height_reduction = 0.2
     args.factor = 2.0
     args.factor_reduction = 0.5
     args.base_height = 0.00
     args.enrichment_factor = 2.0
     args.processing_factor = 1.5
     args.utr_length = 300
     args.libs = libs
     args.out_folder = self.out
     args.cluster = 3
     args.repmatch = 2
     args.output_prefixs = ["test1"]
     self.tss._set_gen_config(args, self.test_folder)
     datas = import_data(os.path.join(self.test_folder, "config_test.ini"))
     self.assertEqual("\n".join(datas), self.example.config)
Esempio n. 40
0
 def test_generate_color_png(self):
     self.color._convert_svg = self.mock.mock_convert_svg
     self.color._convert_png = self.mock.mock_convert_png
     self.color.gen_svg = self.mock.mock_gen_svg
     self.color.generate_color_png(4, self.test_folder, "test")
     data = import_data(os.path.join(self.test_folder, "screenshots", "aaa", "forward", "test_f.png"))
     self.assertListEqual(data, ["test"])
Esempio n. 41
0
 def test_low_expression(self):
     ts.filter_low_expression = self.mock.mock_filter_low_expression
     gen_file(os.path.join(self.wigs, "test1_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_reverse.wig"), "test_r")
     gen_file(os.path.join(self.wigs, "test1_TEX_forward.wig"), "test_f")
     gen_file(os.path.join(self.wigs, "test1_TEX_reverse.wig"), "test_r")
     gen_file(os.path.join(self.gffs, "test_TSS.gff"),
              self.example.tss_file)
     os.mkdir(os.path.join(self.out, "statistics"))
     os.mkdir(os.path.join(self.out, "statistics/test"))
     libs = ["test1_TEX_forward.wig:tex:1:a:+",
             "test1_TEX_reverse.wig:tex:1:a:-",
             "test1_forward.wig:notex:1:a:+",
             "test1_reverse.wig:notex:1:a:-"]
     args = self.mock_args.mock()
     args.manual = "manual"
     args.libs = libs
     args.wig_folder = self.wigs
     args.program = "TSS"
     args.cluster = 3
     self.tss._low_expression(args, self.gffs)
     shutil.rmtree("tmp")
     datas = import_data(os.path.join(
         self.out, "statistics/test/stat_test_low_expression_cutoff.csv"))
     self.assertEqual("\n".join(datas),
                      "Genome\tCutoff_coverage\ntest\t100")
Esempio n. 42
0
 def test_operon(self):
     op.read_gff = Mock_func().mock_read_gff
     out_file = os.path.join(self.test_folder, "test.out")
     op.operon("test_ta", "test_tss", "test_gff", "test_term", 3, 5, 5,
               out_file)
     datas = import_data(out_file)
     self.assertEqual(set(datas), set(self.example.out_file.split("\n")))
Esempio n. 43
0
 def test_assembly(self):
     wig_f_file = os.path.join(self.test_folder, "aaa_forward.wig")
     wig_r_file = os.path.join(self.test_folder, "aaa_reverse.wig")
     wig_f2_file = os.path.join(self.test_folder, "aaa2_forward.wig")
     wig_r2_file = os.path.join(self.test_folder, "aaa2_reverse.wig")
     gen_file(wig_f_file, self.example.wig_f)
     gen_file(wig_r_file, self.example.wig_r)
     gen_file(wig_f2_file, self.example.wig_f)
     gen_file(wig_r2_file, self.example.wig_r)
     reps = {"tex": "all_1", "frag": "all_1"}
     out_file = os.path.join(self.test_folder, "out")
     input_lib = [
         "aaa_forward.wig:frag:1:a:+", "aaa_reverse.wig:frag:1:a:-",
         "aaa2_forward.wig:tex:1:a:+", "aaa2_reverse.wig:tex:1:a:-"
     ]
     args = self.mock_args.mock()
     args.replicates = reps
     args.height = 10
     args.width = 1
     args.tolerance = 3
     args.tex = 2
     args.low_cutoff = 5
     ta.detect_transcript(wig_f_file, wig_r_file, self.test_folder,
                          input_lib, out_file, "TEX", args)
     datas = import_data(out_file)
     self.assertEqual("\n".join(datas),
                      "##gff-version 3\n" + self.example.out_tran)
Esempio n. 44
0
 def test_gene_expression(self):
     gea.read_wig = MockFunc().mock_read_wig
     gea.read_libs = MockFunc().mock_read_libs
     gea.read_data = MockFunc().mock_read_data
     replicates = {"tex": 1, "frag": 1}
     stat_folder = os.path.join(self.test_folder, "stat")
     gff_folder = os.path.join(self.test_folder, "gff")
     if os.path.exists(gff_folder):
         shutil.rmtree(gff_folder)
     os.mkdir(gff_folder)
     gen_file(os.path.join(gff_folder, "aaa.gff"), "test")
     if not os.path.exists(stat_folder):
         os.mkdir(stat_folder)
     out_gff_folder = os.path.join(self.test_folder, "out_gff")
     if not os.path.exists(out_gff_folder):
         os.mkdir(out_gff_folder)
     gea.gene_expression(None, gff_folder, "all", "all", "test_wig",
                         "test_wig", ["CDS"], "test_wig_folder", 5, 2,
                         replicates, stat_folder, out_gff_folder, "high",
                         100, 0)
     datas = import_data(os.path.join(stat_folder, "aaa_CDS.csv"))
     dicts = {}
     for data in datas:
         dicts[data] = data
     refs = {}
     for data in self.example.out_stat.split("\n"):
         refs[data] = data
     self.assertDictEqual(dicts, refs)
Esempio n. 45
0
 def test_gen_config(self):
     os.mkdir(os.path.join(self.out, "MasterTables"))
     os.mkdir(os.path.join(self.wigs, "tmp"))
     config_file = os.path.join(self.test_folder, "config")
     libs = ["test1_forward.wig:notex:1:a:+",
             "test1_reverse.wig:notex:1:a:-",
             "test1_TEX_forward.wig:tex:1:a:+",
             "test1_TEX_reverse.wig:tex:1:a:-"]
     args = self.mock_args.mock()
     args.out_folder = self.out
     args.program = "TSS"
     args.height = 0.3
     args.height_reduction = 0.2
     args.factor = 2.0
     args.factor_reduction = 0.5
     args.base_height = 0.00
     args.enrichment_factor = 2.0
     args.processing_factor = 1.5
     args.utr_length = 300
     args.cluster = 3
     args.repmatch = ["all_2"]
     args.libs = libs
     args.output_prefixs = ["test1"]
     args.specify_strains = None
     log = open(os.path.join(self.test_folder, "test.log"), "w")
     self.tss._gen_config(
         "test", args, self.gffs + "/tmp/test.gff",
         self.wigs + "/tmp", self.fastas + "/tmp/test.fa", config_file, log)
     datas = import_data(config_file)
     self.assertEqual("\n".join(datas), self.example.config)
Esempio n. 46
0
 def test_change_format(self):
     input_file = os.path.join(self.test_folder, "input")
     output_file = os.path.join(self.test_folder, "output")
     gen_file(input_file, ">srna_1|Staphylococcus|Aar|12314|12444|forward\nATAGATTCCCGCGTATAGTCATCATTGTAC")
     cdf.change_format(input_file, output_file)
     data = import_data(output_file)
     self.assertListEqual(data, ['>srna_1|Staphylococcus|Aar', 'ATAGATTCCCGCGTATAGTCATCATTGTAC'])
 def test_stat_ta_gff(self):
     gff_file = os.path.join(self.test_folder, "aaa.gff")
     ta_file = os.path.join(self.test_folder, "aaa_transcript.gff")
     gen_file(gff_file, self.example.gff)
     gen_file(ta_file, self.example.ta)
     stat_file = os.path.join(self.test_folder, "stat")
     out_ta_file = os.path.join(self.test_folder, "out_ta.gff")
     out_gff_file = os.path.join(self.test_folder, "out.gff")
     stc.stat_ta_gff(ta_file, gff_file, stat_file,
                     out_ta_file, out_gff_file, ["gene"])
     datas = import_data(stat_file)
     self.assertEqual("\n".join(datas),
                      ("For gene:\n\tAll genomes:\n\tThe transcript "
                       "information compares with gene:\n" + \
                       self.example.print_tag))
     datas, attributes = extract_info(out_ta_file, "file")
     self.assertListEqual(
         datas,
         ['aaa\tfragmented_and_normal\tTranscript\t313\t3344\t.\t+\t.'])
     for attribute in attributes:
         if "type" in attribute:
             self.assertEqual(attribute, "type=cover_CDS")
         if "associated_cds=" in attribute:
             self.assertEqual(attribute, "associated_cds=YP_498609.1")
     datas, attributes = extract_info(out_gff_file, "file")
     self.assertListEqual(datas, ['aaa\tRefseq\tgene\t517\t1878\t.\t+\t.',
                                  'aaa\tRefseq\tCDS\t517\t1878\t.\t+\t.'])
     for attribute in attributes:
         if "Parent_tran" in attribute:
             self.assertEqual(attribute, "Parent_tran=tran0")
 def test_stat_ta_tss(self):
     tss_file = os.path.join(self.test_folder, "aaa_TSS.gff")
     ta_file = os.path.join(self.test_folder, "aaa_transcript.gff")
     gen_file(tss_file, self.example.tss)
     gen_file(ta_file, self.example.ta)
     stat_file = os.path.join(self.test_folder, "stat")
     out_ta_file = os.path.join(self.test_folder, "out_ta.gff")
     out_tss_file = os.path.join(self.test_folder, "out_tss.gff")
     stc.stat_ta_tss(ta_file, tss_file, stat_file,
                     out_ta_file, out_tss_file, 5)
     datas = import_data(stat_file)
     self.assertEqual("\n".join(datas),
                      "All genomes:\n" + self.example.print_tas)
     datas, attributes = extract_info(out_ta_file, "file")
     self.assertListEqual(
         datas,
         ['aaa\tfragmented_and_normal\tTranscript\t313\t3344\t.\t+\t.'])
     for attribute in attributes:
         if "associated_tss" in attribute:
             self.assertEqual("associated_tss=TSS:2131_f")
     datas, attributes = extract_info(out_tss_file, "file")
     self.assertListEqual(datas,
                          ['aaa\tTSSpredator\tTSS\t2131\t2131\t.\t+\t.'])
     for attribute in attributes:
         if "Parent_tran" in attribute:
             self.assertEqual(attribute, "Parent_tran=tran0")
 def test_operon(self):
     op.read_gff = Mock_func().mock_read_gff
     out_file = os.path.join(self.test_folder, "test.out")
     op.operon("test_ta", "test_tss", "test_gff", "test_term", 3,
               5, 5, out_file)
     datas = import_data(out_file)
     self.assertEqual(set(datas), set(self.example.out_file.split("\n")))
Esempio n. 50
0
 def test_sort_srna_fasta(self):
     fasta = os.path.join(self.fastas, "test.fa")
     gen_file(fasta, ">aaa\nAAAAAAAA\n>bbb\nCCCC\n>ccc\nGGGGGGGGGGGG")
     self.star._sort_srna_fasta(fasta, "test", self.test_folder)
     datas = import_data(os.path.join(self.test_folder, "tmp_srna_target_test_sRNA.fa"))
     self.assertListEqual(datas, ['>bbb', 'CCCC', '>aaa', 'AAAAAAAA',
                                  '>ccc', 'GGGGGGGGGGGG'])
Esempio n. 51
0
 def test_compute_2d_and_energy(self):
     sr.extract_energy = self.mock.mock_extract_energy
     sr.change_format = self.mock.mock_change_format
     self.srna._run_replot = self.mock.mock_run_replot
     self.srna._convert_pdf = self.mock.mock_convert_pdf
     self.srna._run_mountain = self.mock.mock_run_mountain
     sec_path = os.path.join(self.out, "figs")
     os.mkdir(sec_path)
     os.mkdir(os.path.join(sec_path, "sec_plots"))
     os.mkdir(os.path.join(sec_path, "dot_plots"))
     os.mkdir(os.path.join(sec_path, "mountain_plots"))
     tmp_paths = {"dot": self.out, "sec": self.fastas,
                  "tmp": self.tsss, "main": self.test_folder}
     gen_file(os.path.join(self.fastas, "tmp/test.fa"),
              ">test\nAAATTTGGGCCC")
     gen_file(os.path.join(self.out, "tmp_basic_test"),
              self.example.srna_file)
     gen_file(os.path.join(self.out, "tmp_energy_test"), "test")
     log = open(os.path.join(self.test_folder, "test.log"), "w")
     args = self.mock_args.mock()
     args.out_folder = self.out
     args.fastas = self.fastas
     args.rnafold = "test"
     args.relplot_pl = "test"
     args.mountain_pl = "test"
     args.mountain = True
     args.ps2pdf14_path = "test"
     self.srna._compute_2d_and_energy(args, ["test"], log)
     datas = import_data(os.path.join(self.out, "tmp_basic_test"))
     self.assertEqual("\n".join(datas), "test")
Esempio n. 52
0
 def test_print_file(self):
     num_all = {
         "all_cds": 600,
         "all_tRNA": 30,
         "all_rRNA": 30,
         "cds": 250,
         "tRNA": 20,
         "rRNA": 20
     }
     num_strain = {
         "test": {
             "all_cds": 300,
             "all_tRNA": 20,
             "all_rRNA": 20,
             "cds": 100,
             "tRNA": 10,
             "rRNA": 10
         }
     }
     out_cds_file = os.path.join(self.test_folder, "cds_file")
     stat_file = os.path.join(self.test_folder, "stat_file")
     vg.print_file(self.example.gffs, out_cds_file, stat_file, num_all,
                   num_strain)
     datas, attribute = extract_info(out_cds_file, "file")
     self.assertEqual("\n".join(datas),
                      "test\tRefSeq\tCDS\t200\t270\t.\t+\t.")
     datas = import_data(stat_file)
     self.assertEqual("\n".join(datas), self.example.out_stat_test)
    def test_reextract_rbs(self):
        align_file = os.path.join(self.test_folder, "align")
        first_file = os.path.join(self.test_folder, "first")
        output_file = os.path.join(self.test_folder, "output")
        first_content = """riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t10\t16	RF00162	6.2e-18	5	12"""
        gen_file(align_file, self.example.scan_file)
        gen_file(first_file, first_content)
        rr.reextract_rbs(align_file, first_file, output_file)
        data = import_data(output_file)
        self.assertEqual("\n".join(data), first_content)
        first_content = """riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t10\t16	RF00178	6.2e-20	13	17"""
        gen_file(first_file, first_content)
        rr.reextract_rbs(align_file, first_file, output_file)
        data = import_data(output_file)
        self.assertEqual("\n".join(data), 
"""riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t10\t16	RF00162	6.2e-18	5	12
riboswitch_5\tStaphylococcus_aureus_HG003\t+\tSAOUHSC_00013\t10\t16	RF00178	6.2e-20	13	17""")
Esempio n. 54
0
 def test_convert_transtermhp2gff(self):
     transterm_file = os.path.join(self.test_folder, "test_best_terminator_after_gene.bag")
     gff_file = os.path.join(self.test_folder, "transterm.gff")
     with open(transterm_file, "w") as th:
         th.write(self.transterm)
     self.converter.convert_transtermhp2gff(transterm_file, gff_file)
     datas = import_data(gff_file)
     self.assertEqual(set(datas), set(self.term_file.split("\n")))
Esempio n. 55
0
 def test_get_pubmed(self):
     out_all = StringIO()
     out_best = StringIO()
     out_noall = StringIO()
     out_nobest = StringIO()
     self.ppi._run_wget = self.mock.mock_run_wget
     files = {"id_list": self.test_folder, "id_log": "test",
              "pubmed_log": "test",
              "all_specific": out_all, "best_specific": out_best,
              "all_nospecific": out_noall, "best_nospecific": out_nobest}
     row = self.example.ppi_line.split("\t")
     strain_id = {"file": "test_file","ptt": "test_ptt",
                  "string": "test_string", "pie": "test_pie"}
     mode = "interaction"
     actor = "test_A"
     score = 11241
     id_file = "SAOUHSC_01684"
     ptt = "test_ptt"
     gen_file(os.path.join(self.test_folder, "SAOUHSC_01684"),
              "93061.SAOUHSC_01684\t93061.SAOUHSC_01683\t333\ttest_aaa")
     gen_file(os.path.join(self.test_folder, "SAOUHSC_01683"),
              "93061.SAOUHSC_01683\t93061.SAOUHSC_01684\t333\ttest_bbb")
     gen_file(os.path.join(self.test_folder, "tmp_specific"),
              "")
     gen_file(os.path.join(self.test_folder, "tmp_nospecific"),
              "12949105\t0.151711\n1404401\t-0.210303")
     paths = {"all": self.test_folder, "fig": self.test_folder,
              "best": self.test_folder}
     querys = "all"
     first_output = {"specific_all": True, "specific_best": True,
                     "nospecific_all": True, "nospecific_best": True}
     args = self.mock_args.mock()
     args.out_folder = self.test_folder
     args.querys = "all"
     args.no_specific = True
     args.score = 0
     log = open(os.path.join(self.test_folder, "test.log"), "w")
     self.ppi._get_pubmed(row, strain_id, mode, actor, id_file, first_output,
                          ptt, files, paths, args, log)
     data = import_data(
         "test_folder/without_strain/test_ptt/test_aaa_test_bbb.csv")
     self.assertEqual("\n".join(data), self.example.without_out)
     data = import_data(
         "test_folder/with_strain/test_ptt/test_aaa_test_bbb.csv")
     self.assertEqual("\n".join(data), self.example.with_out)
Esempio n. 56
0
 def test_convert_transtermhp2gff(self):
     transterm_file = os.path.join(self.test_folder,
                                   "test_best_terminator_after_gene.bag")
     gff_file = os.path.join(self.test_folder, "transterm.gff")
     with open(transterm_file, "w") as th:
         th.write(self.transterm)
     self.converter.convert_transtermhp2gff(transterm_file, gff_file)
     datas = import_data(gff_file)
     self.assertEqual(set(datas), set(self.term_file.split("\n")))
Esempio n. 57
0
 def test_get_seq(self):
     gff_file = os.path.join(self.test_folder, "test.gff")
     out_file = os.path.join(self.test_folder, "test.cds")
     lines = self.example.gff_out.split("\n")
     with open(gff_file, "w") as gh:
         gh.write(lines[1])
     self.helper.get_seq(self.gff_file, self.seq_file, out_file)
     datas = import_data(out_file)
     self.assertEqual(set(datas), set([">cds0|aaa|1|10|+", "CGCAGGTTGA"]))