@@ -1226,20 +1226,8 @@ def init_segs_to_native_wf(
1226
1226
name = 'resample' ,
1227
1227
)
1228
1228
1229
- seg_mapping = {'aparc_aseg' : 'aparc+' , 'aparc_a2009s' : 'a2009s+' , 'aparc_dkt' : 'DKTatlas+' }
1230
- if segmentation in seg_mapping :
1231
- name = seg_mapping [segmentation ]
1232
-
1233
- def _sel (files , name = name ):
1234
- if isinstance (files , str ):
1235
- return files
1236
-
1237
- for fl in files :
1238
- if name in fl :
1239
- return fl
1240
- raise FileNotFoundError
1241
-
1242
- segmentation = (segmentation , _sel ) # type: ignore
1229
+ select_seg = pe .Node (niu .Function (function = _select_seg ), name = 'select_seg' )
1230
+ select_seg .inputs .segmentation = segmentation
1243
1231
1244
1232
anat = 'T2' if image_type == 'T2w' else 'T1'
1245
1233
@@ -1251,7 +1239,8 @@ def _sel(files, name=name):
1251
1239
('fsnative2anat_xfm' , 'in_xfms' )]),
1252
1240
(fssource , lta , [(anat , 'moving' )]),
1253
1241
(inputnode , resample , [('in_file' , 'target_file' )]),
1254
- (fssource , resample , [(segmentation , 'source_file' )]),
1242
+ (fssource , select_seg , [(segmentation , 'in_files' )]),
1243
+ (select_seg , resample , [('out_file' , 'source_file' )]),
1255
1244
(lta , resample , [('out_xfm' , 'lta_file' )]),
1256
1245
(resample , outputnode , [('transformed_file' , 'out_file' )]),
1257
1246
]) # fmt:skip
@@ -1675,3 +1664,17 @@ def _get_surfaces(subjects_dir: str, subject_id: str, surfaces: list[str]) -> tu
1675
1664
1676
1665
ret = tuple (all_surfs [surface ] for surface in surfaces )
1677
1666
return ret if len (ret ) > 1 else ret [0 ]
1667
+
1668
+
1669
+ def _select_seg (in_files , segmentation ):
1670
+ if isinstance (in_files , str ):
1671
+ return in_files
1672
+
1673
+ seg_mapping = {'aparc_aseg' : 'aparc+' , 'aparc_a2009s' : 'a2009s+' , 'aparc_dkt' : 'DKTatlas+' }
1674
+ if segmentation in seg_mapping :
1675
+ segmentation = seg_mapping [segmentation ]
1676
+
1677
+ for fl in in_files :
1678
+ if segmentation in fl :
1679
+ return fl
1680
+ raise FileNotFoundError (f'No segmentation containing "{ segmentation } " was found.' )
0 commit comments