|
1 | 1 | import numpy as np
|
| 2 | +import pandas as pd |
2 | 3 |
|
3 | 4 | import flowsom as fs
|
4 | 5 |
|
@@ -153,3 +154,53 @@ def test_FlowSOM_class(FlowSOM_res):
|
153 | 154 | obsm_keys_cluster,
|
154 | 155 | ]
|
155 | 156 | )
|
| 157 | + |
| 158 | + |
| 159 | +def test_mfis(): |
| 160 | + # create a DataFrame with 4 cells and 4 markers with values in non-ascending order |
| 161 | + markers = ["CD3", "CD4", "CD8", "CD19"] |
| 162 | + data = pd.DataFrame( |
| 163 | + [ |
| 164 | + [9, 11, 11, 10], |
| 165 | + [2, 1, 2, 1], |
| 166 | + [10, 11, 11, 10], |
| 167 | + [3, 1, 2, 1], |
| 168 | + ], |
| 169 | + columns=markers, |
| 170 | + ) |
| 171 | + fsom = fs.FlowSOM(data, cols_to_use=markers, n_clusters=2, replace=True, xdim=2, ydim=2, seed=42) |
| 172 | + assert fsom.get_cell_data().shape == (4, 4) |
| 173 | + assert fsom.get_cluster_data().shape == (4, 4) |
| 174 | + np.testing.assert_array_equal( |
| 175 | + fsom.get_cluster_data().X, |
| 176 | + np.array( |
| 177 | + [ |
| 178 | + # 4 clusters, coinciding with the 4 cells |
| 179 | + [2.0, 1.0, 2.0, 1.0], |
| 180 | + [3.0, 1.0, 2.0, 1.0], |
| 181 | + [9.0, 11.0, 11.0, 10.0], |
| 182 | + [10.0, 11.0, 11.0, 10.0], |
| 183 | + ] |
| 184 | + ), |
| 185 | + ) |
| 186 | + # the two metaclusters group cell 0 and 2, and cell 1 and 3 |
| 187 | + pd.testing.assert_series_equal( |
| 188 | + fsom.get_cell_data().obs["metaclustering"], |
| 189 | + pd.Series([0, 1, 0, 1], name="metaclustering", index=pd.Index(range(4), dtype=str)), |
| 190 | + ) |
| 191 | + # test MFI |
| 192 | + assert fsom.get_cluster_data().uns["metacluster_MFIs"].shape == (2, 4) |
| 193 | + assert fsom.get_cluster_data().uns["metacluster_MFIs"].columns.tolist() == markers |
| 194 | + # test values of MFI for clusters |
| 195 | + pd.testing.assert_frame_equal( |
| 196 | + fsom.get_cluster_data().uns["metacluster_MFIs"], |
| 197 | + pd.DataFrame( |
| 198 | + [ |
| 199 | + # MFIs per cluster |
| 200 | + [9.5, 11.0, 11.0, 10.0], |
| 201 | + [2.5, 1.0, 2.0, 1.0], |
| 202 | + ], |
| 203 | + columns=markers, |
| 204 | + index=pd.Index([0, 1], name="metaclustering"), |
| 205 | + ), |
| 206 | + ) |
0 commit comments