@@ -1226,20 +1226,8 @@ def init_segs_to_native_wf(
12261226 name = 'resample' ,
12271227 )
12281228
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
12431231
12441232 anat = 'T2' if image_type == 'T2w' else 'T1'
12451233
@@ -1251,7 +1239,8 @@ def _sel(files, name=name):
12511239 ('fsnative2anat_xfm' , 'in_xfms' )]),
12521240 (fssource , lta , [(anat , 'moving' )]),
12531241 (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' )]),
12551244 (lta , resample , [('out_xfm' , 'lta_file' )]),
12561245 (resample , outputnode , [('transformed_file' , 'out_file' )]),
12571246 ]) # fmt:skip
@@ -1675,3 +1664,17 @@ def _get_surfaces(subjects_dir: str, subject_id: str, surfaces: list[str]) -> tu
16751664
16761665 ret = tuple (all_surfs [surface ] for surface in surfaces )
16771666 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