|
12 | 12 | def test_make_chromarms():
|
13 | 13 |
|
14 | 14 | ### test the case where columns have different names
|
15 |
| - df1 = pd.DataFrame( |
| 15 | + df = pd.DataFrame( |
16 | 16 | [["chrX", 0, 8]],
|
17 | 17 | columns=["chromosome", "lo", "hi"],
|
18 | 18 | )
|
19 |
| - |
20 |
| - df2 = pd.DataFrame([["chrX", 4]], columns=["chromosome", "loc"]) |
21 |
| - |
22 |
| - df_result = pd.DataFrame( |
| 19 | + mids = pd.DataFrame([["chrX", 4]], columns=["chromosome", "loc"]) |
| 20 | + arms = pd.DataFrame( |
23 | 21 | [
|
24 | 22 | ["chrX", 0, 4, "chrX_p"],
|
25 | 23 | ["chrX", 4, 8, "chrX_q"],
|
26 | 24 | ],
|
27 |
| - columns=["chromosome", "lo", "hi", "name"], |
| 25 | + columns=["chrom", "start", "end", "name"], |
28 | 26 | )
|
| 27 | + arms = arms.astype({"start": pd.Int64Dtype(), "end": pd.Int64Dtype()}) |
29 | 28 |
|
30 | 29 | # test passing 3 columns
|
| 30 | + result = bioframe.make_chromarms( |
| 31 | + df, |
| 32 | + mids, |
| 33 | + cols_chroms=["chromosome", "lo", "hi"], |
| 34 | + cols_mids=["chromosome", "loc"], |
| 35 | + ) |
31 | 36 | pd.testing.assert_frame_equal(
|
32 |
| - df_result.astype({"lo": pd.Int64Dtype(), "hi": pd.Int64Dtype()}), |
33 |
| - bioframe.make_chromarms( |
34 |
| - df1, |
35 |
| - df2, |
36 |
| - cols_chroms=["chromosome", "lo", "hi"], |
37 |
| - cols_mids=["chromosome", "loc"], |
38 |
| - ), |
| 37 | + result, |
| 38 | + arms.rename(columns={"chrom": "chromosome", "start": "lo", "end": "hi"}) |
39 | 39 | )
|
40 | 40 |
|
41 | 41 | # test passing 2 columns
|
| 42 | + result = bioframe.make_chromarms( |
| 43 | + df, |
| 44 | + mids, |
| 45 | + cols_chroms=["chromosome", "hi"], |
| 46 | + cols_mids=["chromosome", "loc"], |
| 47 | + ) |
42 | 48 | pd.testing.assert_frame_equal(
|
43 |
| - df_result.astype({"lo": pd.Int64Dtype(), "hi": pd.Int64Dtype()}).rename( |
44 |
| - columns={"lo": "start", "hi": "end"} |
45 |
| - ), |
46 |
| - bioframe.make_chromarms( |
47 |
| - df1, |
48 |
| - df2, |
49 |
| - cols_chroms=["chromosome", "hi"], |
50 |
| - cols_mids=["chromosome", "loc"], |
51 |
| - ), |
| 49 | + result |
| 50 | + arms.rename(columns={"chrom": "chromosome"}), |
52 | 51 | )
|
53 | 52 |
|
54 |
| - # todo: test for passing pd.series ! |
| 53 | + # test for passing Series or dict |
| 54 | + result = bioframe.make_chromarms(pd.Series({"chrX": 8}), mids, cols_mids=["chromosome", "loc"]) |
| 55 | + pd.testing.assert_frame_equal(arms, result) |
| 56 | + |
| 57 | + result = bioframe.make_chromarms(pd.Series({"chrX": 8}), pd.Series({"chrX": 4})) |
| 58 | + pd.testing.assert_frame_equal(arms, result) |
| 59 | + |
| 60 | + bioframe.make_chromarms({"chrX": 8}, mids, cols_mids=["chromosome", "loc"]) |
| 61 | + pd.testing.assert_frame_equal(arms, result) |
| 62 | + |
| 63 | + bioframe.make_chromarms({"chrX": 8}, pd.Series({"chrX": 4})) |
| 64 | + pd.testing.assert_frame_equal(arms, result) |
| 65 | + |
| 66 | + bioframe.make_chromarms({"chrX": 8}, {"chrX": 4}) |
| 67 | + pd.testing.assert_frame_equal(arms, result) |
55 | 68 |
|
56 | 69 |
|
57 | 70 | def test_binnify():
|
|
0 commit comments