|
4 | 4 |
|
5 | 5 | from frites.conn import (conn_reshape_undirected, conn_reshape_directed, |
6 | 6 | conn_ravel_directed, define_windows, plot_windows, |
7 | | - conn_dfc, conn_covgc, conn_get_pairs, conn_net) |
| 7 | + conn_dfc, conn_covgc, conn_get_pairs, conn_net, |
| 8 | + conn_links) |
8 | 9 |
|
9 | 10 |
|
10 | 11 | class TestConnUtils(object): |
@@ -222,3 +223,61 @@ def test_conn_net(self): |
222 | 223 | # test order |
223 | 224 | net = conn_net(conn, roi='space', sep='->', order=['z', 'x', 'y']) |
224 | 225 | np.testing.assert_array_equal(net['space'], ['z-x', 'z-y', 'x-y']) |
| 226 | + |
| 227 | + def test_conn_links(self): |
| 228 | + """Test function conn_links.""" |
| 229 | + roi = ['dlPFC', 'aINS', 'dlPFC', 'vmPFC'] |
| 230 | + # overall testing |
| 231 | + (x_s, x_t), roi_st = conn_links(roi, verbose=False) |
| 232 | + assert len(x_s) == len(x_t) == len(roi_st) |
| 233 | + assert all([f"{roi_st[s]}-{roi_st[t]}" for s, t in zip(x_s, x_t)]) |
| 234 | + |
| 235 | + # test direction |
| 236 | + _, roi_st = conn_links(roi) |
| 237 | + np.testing.assert_array_equal(roi_st, |
| 238 | + ['aINS-dlPFC', 'dlPFC-dlPFC', 'dlPFC-vmPFC', 'aINS-dlPFC', |
| 239 | + 'aINS-vmPFC', 'dlPFC-vmPFC']) |
| 240 | + _, roi_st = conn_links(roi, directed=True, net=False) |
| 241 | + np.testing.assert_array_equal(roi_st, |
| 242 | + ['dlPFC->aINS', 'dlPFC->dlPFC', 'dlPFC->vmPFC', 'aINS->dlPFC', |
| 243 | + 'aINS->dlPFC', 'aINS->vmPFC', 'dlPFC->dlPFC', 'dlPFC->aINS', |
| 244 | + 'dlPFC->vmPFC', 'vmPFC->dlPFC', 'vmPFC->aINS', 'vmPFC->dlPFC']) |
| 245 | + _, roi_st = conn_links(roi, directed=True, net=True) |
| 246 | + np.testing.assert_array_equal(roi_st, |
| 247 | + ['aINS-dlPFC', 'dlPFC-dlPFC', 'dlPFC-vmPFC', 'aINS-dlPFC', |
| 248 | + 'aINS-vmPFC', 'dlPFC-vmPFC']) |
| 249 | + |
| 250 | + # testing removing within roi connections |
| 251 | + _, roi_st = conn_links(roi, within_roi=False) |
| 252 | + assert 'dlPFC-dlPFC' not in roi_st |
| 253 | + _, roi_st = conn_links(roi, directed=True, net=False, within_roi=False) |
| 254 | + assert 'dlPFC->dlPFC' not in roi_st |
| 255 | + _, roi_st = conn_links(roi, directed=True, net=True, within_roi=False) |
| 256 | + assert 'dlPFC-dlPFC' not in roi_st |
| 257 | + |
| 258 | + # remove links without a minimum number of conections |
| 259 | + _, roi_st = conn_links(roi, nb_min_links=2) |
| 260 | + np.testing.assert_array_equal(roi_st, |
| 261 | + ['aINS-dlPFC', 'dlPFC-vmPFC', 'aINS-dlPFC', 'dlPFC-vmPFC']) |
| 262 | + _, roi_st = conn_links(roi, directed=True, nb_min_links=2) |
| 263 | + np.testing.assert_array_equal(roi_st, |
| 264 | + ['dlPFC->aINS', 'dlPFC->dlPFC', 'dlPFC->vmPFC', 'aINS->dlPFC', |
| 265 | + 'aINS->dlPFC', 'dlPFC->dlPFC', 'dlPFC->aINS', 'dlPFC->vmPFC', |
| 266 | + 'vmPFC->dlPFC', 'vmPFC->dlPFC']) |
| 267 | + _, roi_st = conn_links(roi, directed=True, nb_min_links=2, net=True) |
| 268 | + np.testing.assert_array_equal(roi_st, |
| 269 | + ['aINS-dlPFC', 'dlPFC-vmPFC', 'aINS-dlPFC', 'dlPFC-vmPFC']) |
| 270 | + |
| 271 | + # testing string separator |
| 272 | + for direction in [True, False]: |
| 273 | + _, roi_st = conn_links(roi, sep='/', directed=True) |
| 274 | + assert all(['/' in r for r in roi_st]) |
| 275 | + |
| 276 | + # testing pairs |
| 277 | + p_1, p_2 = np.array([0, 2]), np.array([1, 3]) |
| 278 | + _, roi_st = conn_links(roi, pairs=np.c_[p_1, p_2]) |
| 279 | + np.testing.assert_array_equal(roi_st, |
| 280 | + ['aINS-dlPFC', 'dlPFC-vmPFC']) |
| 281 | + _, roi_st = conn_links(roi, pairs=np.c_[p_1, p_2], directed=True) |
| 282 | + np.testing.assert_array_equal(roi_st, |
| 283 | + ['dlPFC->aINS', 'dlPFC->vmPFC']) |
0 commit comments