@@ -144,7 +144,7 @@ def conn_get_pairs(roi, directed=False, nb_min_suj=-np.inf, verbose=None):
144144
145145def conn_links (roi , directed = False , net = False , within_roi = True , sep = 'auto' ,
146146 nb_min_links = None , pairs = None , sort = True , triu_k = 1 ,
147- verbose = None ):
147+ hemisphere = None , hemi_links = 'both' , verbose = None ):
148148 """Construct pairwise links for functional connectivity.
149149
150150 This function can be used for defining the pairwise links for computing
@@ -179,6 +179,17 @@ def conn_links(roi, directed=False, net=False, within_roi=True, sep='auto',
179179 triu_k : int | 1
180180 Diagonal offset when estimating the undirected links to use. By
181181 default, triu_k=1 means that we skip auto-connections
182+ hemisphere : array_like | None
183+ List of hemisphere names
184+ hemi_links : {'both', 'intra', 'inter'}
185+ Specify whether connectivity links should be :
186+
187+ * 'both': intra-hemispheric and inter-hemispheric (default)
188+ * 'intra': intra-hemispheric
189+ * 'inter': inter-hemispheric
190+
191+ In order to work, you should provide the hemisphere name using the
192+ input `hemisphere`
182193
183194 Returns
184195 -------
@@ -244,6 +255,19 @@ def conn_links(roi, directed=False, net=False, within_roi=True, sep='auto',
244255 keep = [df .loc [r ] >= nb_min_links for r in roi_st ]
245256 x_s , x_t = x_s [keep ], x_t [keep ]
246257
258+ # hemisphere selection
259+ if isinstance (hemisphere , (list , np .ndarray )):
260+ assert hemi_links in ['both' , 'intra' , 'inter' ]
261+ hemisphere = np .asarray (hemisphere )
262+ h_s , h_t = hemisphere [x_s ], hemisphere [x_t ]
263+ if hemi_links in ['intra' , 'inter' ]:
264+ keep = h_s == h_t if hemi_links == 'intra' else h_s != h_t
265+ x_s , x_t = x_s [keep ], x_t [keep ]
266+ else :
267+ keep = np .array ([True ] * len (x_s ))
268+ logger .info (f" Hemispheric selection (hemi_links={ hemi_links } , "
269+ f"dropped={ (~ keep ).sum ()} links)" )
270+
247271 # build pairs of brain region names
248272 roi_st = np .asarray ([f"{ s } { sep } { t } " for s , t in zip (roi [x_s ], roi [x_t ])])
249273
0 commit comments