|
3 | 3 | import logging |
4 | 4 | from cmapPy.pandasGEXpress import setup_GCToo_logger as setup_logger |
5 | 5 | import unittest |
| 6 | +import pandas as pd |
6 | 7 | import pandas.util.testing as pandas_testing |
| 8 | +from cmapPy.pandasGEXpress import parse |
| 9 | +from cmapPy.pandasGEXpress import mini_gctoo_for_testing as mini_gctoo_for_testing |
| 10 | +from cmapPy.pandasGEXpress import slice_gct as slice_gct |
| 11 | + |
7 | 12 | from cmapPy.pandasGEXpress import GCToo as GCToo |
8 | 13 | from cmapPy.pandasGEXpress import parse_gctx as parse_gctx |
9 | 14 | from cmapPy.pandasGEXpress import mini_gctoo_for_testing as mini_gctoo_for_testing |
10 | 15 |
|
11 | 16 | __author__ = "Oana Enache" |
12 | 17 | |
13 | 18 |
|
| 19 | +FUNCTIONAL_TESTS_PATH = "functional_tests" |
| 20 | + |
14 | 21 | logger = logging.getLogger(setup_logger.LOGGER_NAME) |
15 | 22 |
|
16 | 23 | class TestParse(unittest.TestCase): |
17 | | - def test_gctx_parsing(self): |
18 | | - pass |
| 24 | + def test_gctx_parsing(self): |
| 25 | + # parse in gctx, no other arguments |
| 26 | + mg1 = mini_gctoo_for_testing.make() |
| 27 | + mg2 = parse("functional_tests/mini_gctoo_for_testing.gctx") |
| 28 | + |
| 29 | + pandas_testing.assert_frame_equal(mg1.data_df, mg2.data_df) |
| 30 | + pandas_testing.assert_frame_equal(mg1.row_metadata_df, mg2.row_metadata_df) |
| 31 | + pandas_testing.assert_frame_equal(mg1.col_metadata_df, mg2.col_metadata_df) |
| 32 | + |
| 33 | + # check convert_neg_666 worked correctly |
| 34 | + self.assertTrue(mg2.col_metadata_df["mfc_plate_id"].isnull().all()) |
| 35 | + |
| 36 | + # parse w/o convert_neg_666 |
| 37 | + mg2_alt = parse("functional_tests/mini_gctoo_for_testing.gctx", convert_neg_666 = False) |
| 38 | + self.assertFalse(mg2_alt.col_metadata_df["mfc_plate_id"].isnull().all()) |
| 39 | + |
| 40 | + # parsing w/rids & cids specified |
| 41 | + test_rids = ['LJP007_MCF10A_24H:TRT_CP:BRD-K93918653:3.33', 'LJP007_MCF7_24H:CTL_VEHICLE:DMSO:-666'] |
| 42 | + test_cids = ['LJP007_MCF7_24H:TRT_POSCON:BRD-A61304759:10'] |
| 43 | + mg3 = slice_gct.slice_gctoo(mg1, rid=test_rids, cid=test_cids) |
| 44 | + mg4 = parse("functional_tests/mini_gctoo_for_testing.gctx", |
| 45 | + rid=test_rids, cid=test_cids) |
| 46 | + pandas_testing.assert_frame_equal(mg3.data_df, mg4.data_df) |
| 47 | + pandas_testing.assert_frame_equal(mg3.row_metadata_df, mg4.row_metadata_df) |
| 48 | + pandas_testing.assert_frame_equal(mg3.col_metadata_df, mg4.col_metadata_df) |
| 49 | + |
| 50 | + # parsing w/ridx & cidx specified |
| 51 | + mg5 = slice_gct.slice_gctoo(mg1, rid=['LJP007_MCF7_24H:CTL_VEHICLE:DMSO:-666'], |
| 52 | + cid='LJP007_MCF7_24H:CTL_VEHICLE:DMSO:-666') |
| 53 | + mg6 = parse("functional_tests/mini_gctoo_for_testing.gctx", ridx=[4], cidx=[4]) |
| 54 | + |
| 55 | + pandas_testing.assert_frame_equal(mg5.data_df, mg6.data_df) |
| 56 | + pandas_testing.assert_frame_equal(mg5.row_metadata_df, mg6.row_metadata_df) |
| 57 | + pandas_testing.assert_frame_equal(mg5.col_metadata_df, mg6.col_metadata_df) |
| 58 | + |
| 59 | + # parsing row metadata only |
| 60 | + mg7 = parse("functional_tests/mini_gctoo_for_testing.gctx", row_meta_only=True) |
| 61 | + pandas_testing.assert_frame_equal(mg7, mg1.row_metadata_df) |
| 62 | + |
| 63 | + # parsing col metadata only |
| 64 | + mg8 = parse("functional_tests/mini_gctoo_for_testing.gctx", col_meta_only=True) |
| 65 | + pandas_testing.assert_frame_equal(mg8, mg1.col_metadata_df) |
| 66 | + |
| 67 | + # parsing w/multiindex |
| 68 | + mg9 = parse("functional_tests/mini_gctoo_for_testing.gctx", make_multiindex=True) |
| 69 | + self.assertTrue(mg9.multi_index_df is not None) |
| 70 | + |
| 71 | + def test_gct_parsing(self): |
| 72 | + # parse in gct, no other arguments |
| 73 | + mg1 = mini_gctoo_for_testing.make() |
| 74 | + mg2 = parse("functional_tests/mini_gctoo_for_testing.gct") |
| 75 | + |
| 76 | + pandas_testing.assert_frame_equal(mg1.data_df, mg2.data_df) |
| 77 | + pandas_testing.assert_frame_equal(mg1.row_metadata_df, mg2.row_metadata_df) |
| 78 | + pandas_testing.assert_frame_equal(mg1.col_metadata_df, mg2.col_metadata_df) |
| 79 | + |
| 80 | + # check convert_neg_666 worked correctly |
| 81 | + self.assertTrue(mg2.col_metadata_df["mfc_plate_id"].isnull().all()) |
| 82 | + |
| 83 | + # parse w/o convert_neg_666 |
| 84 | + mg2_alt = parse("functional_tests/mini_gctoo_for_testing.gct", convert_neg_666 = False) |
| 85 | + self.assertFalse(mg2_alt.col_metadata_df["mfc_plate_id"].isnull().all()) |
| 86 | + |
| 87 | + # check unused rid argument handling |
| 88 | + with self.assertRaises(Exception) as context: |
| 89 | + mg3 = parse("functional_tests/mini_gctoo_for_testing.gct", rid=["a"]) |
| 90 | + self.assertTrue("parse_gct does not use the argument" in str(context.exception)) |
| 91 | + |
| 92 | + # check unused cid argument handling |
| 93 | + with self.assertRaises(Exception) as context: |
| 94 | + mg4 = parse("functional_tests/mini_gctoo_for_testing.gct", cid=["a"]) |
| 95 | + self.assertTrue("parse_gct does not use the argument" in str(context.exception)) |
| 96 | + |
| 97 | + # check unused ridx argument handling |
| 98 | + with self.assertRaises(Exception) as context: |
| 99 | + mg5 = parse("functional_tests/mini_gctoo_for_testing.gct", ridx=[0]) |
| 100 | + self.assertTrue("parse_gct does not use the argument" in str(context.exception)) |
| 101 | + |
| 102 | + # check unused cidx argument handling |
| 103 | + with self.assertRaises(Exception) as context: |
| 104 | + mg6 = parse("functional_tests/mini_gctoo_for_testing.gct", cidx=[0]) |
| 105 | + self.assertTrue("parse_gct does not use the argument" in str(context.exception)) |
| 106 | + |
| 107 | +if __name__ == "__main__": |
| 108 | + setup_logger.setup(verbose=True) |
| 109 | + unittest.main() |
| 110 | + |
| 111 | + |
19 | 112 |
|
20 | | - def test_gct_parsing(self): |
21 | | - pass |
|
0 commit comments