@@ -1170,11 +1170,11 @@ def init_hcp_morphometrics_wf(
1170
1170
def init_segs_to_native_wf (
1171
1171
* ,
1172
1172
image_type : ty .Literal ['T1w' , 'T2w' ] = 'T1w' ,
1173
- segmentation : ty .Literal ['aseg' , 'aparc_aseg' , 'wmparc' ] = 'aseg' ,
1173
+ segmentation : ty .Literal ['aseg' , 'aparc_aseg' , 'aparc_a2009s' , 'aparc_dkt' ] | str = 'aseg' ,
1174
1174
name : str = 'segs_to_native_wf' ,
1175
1175
) -> Workflow :
1176
1176
"""
1177
- Get a segmentation from FreeSurfer conformed space into native T1w space.
1177
+ Get a segmentation from FreeSurfer conformed space into native anatomical space.
1178
1178
1179
1179
Workflow Graph
1180
1180
.. workflow::
@@ -1219,30 +1219,15 @@ def init_segs_to_native_wf(
1219
1219
1220
1220
lta = pe .Node (ConcatenateXFMs (out_fmt = 'fs' ), name = 'lta' , run_without_submitting = True )
1221
1221
1222
- # Resample from T1.mgz to T1w.nii.gz , applying any offset in fsnative2anat_xfm,
1222
+ # Resample from Freesurfer anat to native anat , applying any offset in fsnative2anat_xfm,
1223
1223
# and convert to NIfTI while we're at it
1224
1224
resample = pe .Node (
1225
1225
fs .ApplyVolTransform (transformed_file = 'seg.nii.gz' , interp = 'nearest' ),
1226
1226
name = 'resample' ,
1227
1227
)
1228
1228
1229
- if segmentation .startswith ('aparc' ):
1230
- if segmentation == 'aparc_aseg' :
1231
-
1232
- def _sel (x ):
1233
- return [parc for parc in x if 'aparc+' in parc ][0 ] # noqa
1234
-
1235
- elif segmentation == 'aparc_a2009s' :
1236
-
1237
- def _sel (x ):
1238
- return [parc for parc in x if 'a2009s+' in parc ][0 ] # noqa
1239
-
1240
- elif segmentation == 'aparc_dkt' :
1241
-
1242
- def _sel (x ):
1243
- return [parc for parc in x if 'DKTatlas+' in parc ][0 ] # noqa
1244
-
1245
- segmentation = (segmentation , _sel )
1229
+ select_seg = pe .Node (niu .Function (function = _select_seg ), name = 'select_seg' )
1230
+ select_seg .inputs .segmentation = segmentation
1246
1231
1247
1232
anat = 'T2' if image_type == 'T2w' else 'T1'
1248
1233
@@ -1254,7 +1239,8 @@ def _sel(x):
1254
1239
('fsnative2anat_xfm' , 'in_xfms' )]),
1255
1240
(fssource , lta , [(anat , 'moving' )]),
1256
1241
(inputnode , resample , [('in_file' , 'target_file' )]),
1257
- (fssource , resample , [(segmentation , 'source_file' )]),
1242
+ (fssource , select_seg , [(segmentation , 'in_files' )]),
1243
+ (select_seg , resample , [('out' , 'source_file' )]),
1258
1244
(lta , resample , [('out_xfm' , 'lta_file' )]),
1259
1245
(resample , outputnode , [('transformed_file' , 'out_file' )]),
1260
1246
]) # fmt:skip
@@ -1678,3 +1664,17 @@ def _get_surfaces(subjects_dir: str, subject_id: str, surfaces: list[str]) -> tu
1678
1664
1679
1665
ret = tuple (all_surfs [surface ] for surface in surfaces )
1680
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