示例#1
0
    def test_output_csv(self):

        outfile = self.Blast_dir + "test.csv"
#        blast = RunBlast(records=self.record_index, e_value=self.e_threshold, wdir=self.Blast_dir,
#                            infile=None, outfile=outfile)
        data = dict({"GO:01": 1,
                     "GO:03": 2,
                     "GO:04": 2,
                     "GO:05": 1, })
        run_BLAST.output_csv(outfile, "Sample", data)
        f = open(outfile, "r")
        expected_header = "GOterm,Sample\r\n"
        expected_content = ["GO:01,1\r\n",
                            "GO:03,2\r\n",
                            "GO:04,2\r\n",
                            "GO:05,1\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)


        self.assertEqual(i, 4)
示例#2
0
    def test_merge_output_csv_to_MINE(self):
        outfile1 = self.working_dir + "test1.csv"
        outfile2 = self.working_dir + "test2.csv"
        outfile3 = self.working_dir + "test3.csv"
        data = dict({"GO:01": 1,
                     "GO:03": 2,
                     "GO:04": 2,
                     "GO:05": 1, })
        run_BLAST.output_csv(outfile1, "Sample", data)

        data = dict({"GO:01": 7,
                     "GO:02": 9,
                     "GO:04": 2,
                     "GO:05": 8, })
        run_BLAST.output_csv(outfile2, "Species", data)

        data = dict({"GO:01": 3,
                     "GO:02": 1,
                     "GO:03": 2,
                     "GO:04": 2,
                     "GO:05": 2,
                     "GO:06": 1,
                     "GO:07": 1})
        run_BLAST.output_csv(outfile3, "Something", data)

        outfile = self.working_dir + "test12.csv"
        csv_files = [outfile1, outfile2]
        run_MINE.merge_output_csv_to_MINE(outfile, csv_files)

        f = open(outfile, "r")
        expected_header = "Sample_0,Species_1\r\n"
        expected_content = ["1,7\r\n",
                            "2,0\r\n",
                            "2,2\r\n",
                            "1,8\r\n",
                            "0,9\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)
        self.assertEqual(i, 5)


        outfile = self.working_dir + "test123.csv"
        csv_files = [outfile1, outfile2, outfile3]
        run_MINE.merge_output_csv_to_MINE(outfile, csv_files, isMINE=False)
        f = open(outfile, "r")
        expected_header = "GOterm,Sample_0,Species_1,Something_2\r\n"
        expected_content = ["GO:01,1,7,3\r\n",
                            "GO:03,2,0,2\r\n",
                            "GO:04,2,2,2\r\n",
                            "GO:05,1,8,2\r\n",
                            "GO:02,0,9,1\r\n",
                            "GO:06,0,0,1\r\n",
                            "GO:07,0,0,1\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)
        self.assertEqual(i, 7)

        run_MINE.merge_output_csv_to_MINE(outfile, csv_files, isMINE=True)
        f = open(outfile, "r")
        expected_header = "Sample_0,Species_1,Something_2\r\n"
        expected_content = ["1,7,3\r\n",
                            "2,0,2\r\n",
                            "2,2,2\r\n",
                            "1,8,2\r\n",
                            "0,9,1\r\n",
                            "0,0,1\r\n",
                            "0,0,1\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)
        self.assertEqual(i, 7)
示例#3
0
    def test_update_output_csv(self):
        outfile1 = self.Blast_dir + "test1.csv"
        outfile2 = self.Blast_dir + "test2.csv"
        outfile3 = self.Blast_dir + "test3.csv"
#        blast = RunBlast(records=self.record_index, e_value=self.e_threshold,
#            wdir=self.Blast_dir, outfile=outfile1)
        data = dict({"GO:01": 1,
                     "GO:03": 2,
                     "GO:04": 2,
                     "GO:05": 1, })
        run_BLAST.output_csv(outfile1, "Sample", data)
        blast = RunBlast(records=self.record_index, e_value=self.e_threshold,
            wdir=self.Blast_dir, outfile=outfile2)  # , comparison_file="test.csv")
        data = dict({"GO:01": 7,
                     "GO:02": 9,
                     "GO:04": 2,
                     "GO:05": 8, })
#        blast.output_csv("Species", data)
        run_BLAST._update_output_csv(outfile2, "Species", data, existing_csv=outfile1)

        f = open(outfile2, "r")
        expected_header = "GOterm,Sample,Species\r\n"
        expected_content = ["GO:01,1,7\r\n",
                            "GO:03,2,0\r\n",
                            "GO:04,2,2\r\n",
                            "GO:05,1,8\r\n",
                            "GO:02,0,9\r\n"]
#        expected_header = "Sample,Species\r\n"
#        expected_content = ["1,7\r\n",
#                            "2,0\r\n",
#                            "2,2\r\n",
#                            "1,8\r\n",
#                            "0,9\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)

        self.assertEqual(i, 5)


        new_data = dict({"GO:01": 3,
                         "GO:02": 1,
                         "GO:03": 2,
                         "GO:04": 2,
                         "GO:05": 2,
                         "GO:06": 1,
                         "GO:07": 1})
#        blast.output_csv("Something", new_data)
        run_BLAST._update_output_csv(outfile3, "Something", new_data, existing_csv=outfile2)

        f = open(outfile3, "r")
        expected_header = "GOterm,Sample,Species,Something\r\n"
        expected_content = ["GO:01,1,7,3\r\n",
                            "GO:03,2,0,2\r\n",
                            "GO:04,2,2,2\r\n",
                            "GO:05,1,8,2\r\n",
                            "GO:02,0,9,1\r\n",
                            "GO:06,0,0,1\r\n",
                            "GO:07,0,0,1\r\n"]

        for i, line in enumerate(f):
            if i == 0:
                self.assertEqual(line, expected_header)
            else:
                self.assertIn(line, expected_content)

        self.assertEqual(i, 7)