1313from niworkflows .utils .connections import pop_file
1414from smriprep .workflows .anatomical import (
1515 _is_skull_stripped ,
16- init_anat_ribbon_wf ,
1716 init_anat_template_wf ,
1817)
1918from smriprep .workflows .fit .registration import init_register_template_wf
2019from smriprep .workflows .outputs import (
2120 init_ds_dseg_wf ,
2221 init_ds_fs_registration_wf ,
2322 init_ds_mask_wf ,
23+ init_ds_surface_masks_wf ,
2424 init_ds_surface_metrics_wf ,
2525 init_ds_surfaces_wf ,
2626 init_ds_template_registration_wf ,
2727 init_ds_template_wf ,
2828 init_ds_tpms_wf ,
2929)
3030from smriprep .workflows .surfaces import (
31+ init_anat_ribbon_wf ,
32+ init_cortex_masks_wf ,
3133 init_fsLR_reg_wf ,
3234 init_gifti_morphometrics_wf ,
3335 init_gifti_surfaces_wf ,
@@ -147,6 +149,7 @@ def init_infant_anat_fit_wf(
147149 'sphere_reg' ,
148150 'sphere_reg_fsLR' ,
149151 'sphere_reg_msm' ,
152+ 'cortex_mask' ,
150153 'anat_ribbon' ,
151154 # Reverse transform; not computable from forward transform
152155 'std2anat_xfm' ,
@@ -1273,13 +1276,13 @@ def init_infant_anat_fit_wf(
12731276 (fsnative_buffer , gifti_surfaces_wf , [
12741277 ('fsnative2anat_xfm' , 'inputnode.fsnative2anat_xfm' ),
12751278 ]),
1276- (gifti_surfaces_wf , surfaces_buffer , [
1277- (f'outputnode.{ surf } ' , surf ) for surf in surfs
1278- ]),
12791279 (sourcefile_buffer , ds_surfaces_wf , [('anat_source_files' , 'inputnode.source_files' )]),
12801280 (gifti_surfaces_wf , ds_surfaces_wf , [
12811281 (f'outputnode.{ surf } ' , f'inputnode.{ surf } ' ) for surf in surfs
12821282 ]),
1283+ (ds_surfaces_wf , surfaces_buffer , [
1284+ (f'outputnode.{ surf } ' , surf ) for surf in surfs
1285+ ]),
12831286 ]) # fmt:skip
12841287 if spheres :
12851288 gifti_spheres_wf = init_gifti_surfaces_wf (
@@ -1297,13 +1300,13 @@ def init_infant_anat_fit_wf(
12971300 ('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
12981301 # No transform for spheres, following HCP pipelines' lead
12991302 ]),
1300- (gifti_spheres_wf , surfaces_buffer , [
1301- (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
1302- ]),
13031303 (sourcefile_buffer , ds_spheres_wf , [('anat_source_files' , 'inputnode.source_files' )]),
13041304 (gifti_spheres_wf , ds_spheres_wf , [
13051305 (f'outputnode.{ sphere } ' , f'inputnode.{ sphere } ' ) for sphere in spheres
13061306 ]),
1307+ (ds_spheres_wf , surfaces_buffer , [
1308+ (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
1309+ ]),
13071310 ]) # fmt:skip
13081311 metrics = [metric for metric in needed_metrics if metric not in found_surfs ]
13091312 if metrics :
@@ -1321,13 +1324,13 @@ def init_infant_anat_fit_wf(
13211324 ('outputnode.subject_id' , 'inputnode.subject_id' ),
13221325 ('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
13231326 ]),
1324- (gifti_morph_wf , surfaces_buffer , [
1325- (f'outputnode.{ metric } ' , metric ) for metric in metrics
1326- ]),
13271327 (sourcefile_buffer , ds_morph_wf , [('anat_source_files' , 'inputnode.source_files' )]),
13281328 (gifti_morph_wf , ds_morph_wf , [
13291329 (f'outputnode.{ metric } ' , f'inputnode.{ metric } ' ) for metric in metrics
13301330 ]),
1331+ (ds_morph_wf , surfaces_buffer , [
1332+ (f'outputnode.{ metric } ' , metric ) for metric in metrics
1333+ ]),
13311334 ]) # fmt:skip
13321335
13331336 if 'anat_ribbon' not in precomputed :
@@ -1413,6 +1416,32 @@ def init_infant_anat_fit_wf(
14131416 else :
14141417 LOGGER .info ('ANAT Stage 9: Found pre-computed fsLR registration sphere' )
14151418 fsLR_buffer .inputs .sphere_reg_fsLR = sorted (precomputed ['sphere_reg_fsLR' ])
1419+
1420+ # Stage 10: Cortical surface mask
1421+ if len (precomputed .get ('cortex_mask' , [])) < 2 :
1422+ LOGGER .info ('ANAT Stage 11: Creating cortical surface mask' )
1423+
1424+ cortex_masks_wf = init_cortex_masks_wf ()
1425+ ds_cortex_masks_wf = init_ds_surface_masks_wf (
1426+ output_dir = output_dir ,
1427+ mask_type = 'cortex' ,
1428+ name = 'ds_cortex_masks_wf' ,
1429+ )
1430+
1431+ workflow .connect ([
1432+ (surfaces_buffer , cortex_masks_wf , [
1433+ ('midthickness' , 'inputnode.midthickness' ),
1434+ ('thickness' , 'inputnode.thickness' ),
1435+ ]),
1436+ (cortex_masks_wf , ds_cortex_masks_wf , [
1437+ ('outputnode.cortex_masks' , 'inputnode.mask_files' ),
1438+ ('outputnode.source_files' , 'inputnode.source_files' ),
1439+ ]),
1440+ (ds_cortex_masks_wf , outputnode , [('outputnode.mask_files' , 'cortex_mask' )]),
1441+ ]) # fmt:skip
1442+ else :
1443+ LOGGER .info ('ANAT Stage 11: Found pre-computed cortical surface mask' )
1444+ outputnode .inputs .cortex_mask = sorted (precomputed ['cortex_mask' ])
14161445 return workflow
14171446
14181447
@@ -1476,6 +1505,7 @@ def init_infant_single_anat_fit_wf(
14761505 'sphere_reg' ,
14771506 'sphere_reg_fsLR' ,
14781507 'sphere_reg_msm' ,
1508+ 'cortex_mask' ,
14791509 'anat_ribbon' ,
14801510 # Reverse transform; not computable from forward transform
14811511 'std2anat_xfm' ,
@@ -2202,13 +2232,13 @@ def init_infant_single_anat_fit_wf(
22022232 (fsnative_buffer , gifti_surfaces_wf , [
22032233 ('fsnative2anat_xfm' , 'inputnode.fsnative2anat_xfm' ),
22042234 ]),
2205- (gifti_surfaces_wf , surfaces_buffer , [
2206- (f'outputnode.{ surf } ' , surf ) for surf in surfs
2207- ]),
22082235 (sourcefile_buffer , ds_surfaces_wf , [('anat_source_files' , 'inputnode.source_files' )]),
22092236 (gifti_surfaces_wf , ds_surfaces_wf , [
22102237 (f'outputnode.{ surf } ' , f'inputnode.{ surf } ' ) for surf in surfs
22112238 ]),
2239+ (ds_surfaces_wf , surfaces_buffer , [
2240+ (f'outputnode.{ surf } ' , surf ) for surf in surfs
2241+ ]),
22122242 ]) # fmt:skip
22132243 if spheres :
22142244 gifti_spheres_wf = init_gifti_surfaces_wf (
@@ -2226,13 +2256,13 @@ def init_infant_single_anat_fit_wf(
22262256 ('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
22272257 # No transform for spheres, following HCP pipelines' lead
22282258 ]),
2229- (gifti_spheres_wf , surfaces_buffer , [
2230- (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
2231- ]),
22322259 (sourcefile_buffer , ds_spheres_wf , [('anat_source_files' , 'inputnode.source_files' )]),
22332260 (gifti_spheres_wf , ds_spheres_wf , [
22342261 (f'outputnode.{ sphere } ' , f'inputnode.{ sphere } ' ) for sphere in spheres
22352262 ]),
2263+ (ds_spheres_wf , surfaces_buffer , [
2264+ (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
2265+ ]),
22362266 ]) # fmt:skip
22372267 metrics = [metric for metric in needed_metrics if metric not in found_surfs ]
22382268 if metrics :
@@ -2250,13 +2280,13 @@ def init_infant_single_anat_fit_wf(
22502280 ('outputnode.subject_id' , 'inputnode.subject_id' ),
22512281 ('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
22522282 ]),
2253- (gifti_morph_wf , surfaces_buffer , [
2254- (f'outputnode.{ metric } ' , metric ) for metric in metrics
2255- ]),
22562283 (sourcefile_buffer , ds_morph_wf , [('anat_source_files' , 'inputnode.source_files' )]),
22572284 (gifti_morph_wf , ds_morph_wf , [
22582285 (f'outputnode.{ metric } ' , f'inputnode.{ metric } ' ) for metric in metrics
22592286 ]),
2287+ (ds_morph_wf , surfaces_buffer , [
2288+ (f'outputnode.{ metric } ' , metric ) for metric in metrics
2289+ ]),
22602290 ]) # fmt:skip
22612291
22622292 if 'anat_ribbon' not in precomputed :
@@ -2342,4 +2372,30 @@ def init_infant_single_anat_fit_wf(
23422372 else :
23432373 LOGGER .info ('ANAT Stage 9: Found pre-computed fsLR registration sphere' )
23442374 fsLR_buffer .inputs .sphere_reg_fsLR = sorted (precomputed ['sphere_reg_fsLR' ])
2375+
2376+ # Stage 10: Cortical surface mask
2377+ if len (precomputed .get ('cortex_mask' , [])) < 2 :
2378+ LOGGER .info ('ANAT Stage 11: Creating cortical surface mask' )
2379+
2380+ cortex_masks_wf = init_cortex_masks_wf ()
2381+ ds_cortex_masks_wf = init_ds_surface_masks_wf (
2382+ output_dir = output_dir ,
2383+ mask_type = 'cortex' ,
2384+ name = 'ds_cortex_masks_wf' ,
2385+ )
2386+
2387+ workflow .connect ([
2388+ (surfaces_buffer , cortex_masks_wf , [
2389+ ('midthickness' , 'inputnode.midthickness' ),
2390+ ('thickness' , 'inputnode.thickness' ),
2391+ ]),
2392+ (cortex_masks_wf , ds_cortex_masks_wf , [
2393+ ('outputnode.cortex_masks' , 'inputnode.mask_files' ),
2394+ ('outputnode.source_files' , 'inputnode.source_files' ),
2395+ ]),
2396+ (ds_cortex_masks_wf , outputnode , [('outputnode.mask_files' , 'cortex_mask' )]),
2397+ ]) # fmt:skip
2398+ else :
2399+ LOGGER .info ('ANAT Stage 11: Found pre-computed cortical surface mask' )
2400+ outputnode .inputs .cortex_mask = sorted (precomputed ['cortex_mask' ])
23452401 return workflow
0 commit comments