13
13
from niworkflows .utils .connections import pop_file
14
14
from smriprep .workflows .anatomical import (
15
15
_is_skull_stripped ,
16
- init_anat_ribbon_wf ,
17
16
init_anat_template_wf ,
18
17
)
19
18
from smriprep .workflows .fit .registration import init_register_template_wf
20
19
from smriprep .workflows .outputs import (
21
20
init_ds_dseg_wf ,
22
21
init_ds_fs_registration_wf ,
23
22
init_ds_mask_wf ,
23
+ init_ds_surface_masks_wf ,
24
24
init_ds_surface_metrics_wf ,
25
25
init_ds_surfaces_wf ,
26
26
init_ds_template_registration_wf ,
27
27
init_ds_template_wf ,
28
28
init_ds_tpms_wf ,
29
29
)
30
30
from smriprep .workflows .surfaces import (
31
+ init_anat_ribbon_wf ,
32
+ init_cortex_masks_wf ,
31
33
init_fsLR_reg_wf ,
32
34
init_gifti_morphometrics_wf ,
33
35
init_gifti_surfaces_wf ,
@@ -147,6 +149,7 @@ def init_infant_anat_fit_wf(
147
149
'sphere_reg' ,
148
150
'sphere_reg_fsLR' ,
149
151
'sphere_reg_msm' ,
152
+ 'cortex_mask' ,
150
153
'anat_ribbon' ,
151
154
# Reverse transform; not computable from forward transform
152
155
'std2anat_xfm' ,
@@ -1273,13 +1276,13 @@ def init_infant_anat_fit_wf(
1273
1276
(fsnative_buffer , gifti_surfaces_wf , [
1274
1277
('fsnative2anat_xfm' , 'inputnode.fsnative2anat_xfm' ),
1275
1278
]),
1276
- (gifti_surfaces_wf , surfaces_buffer , [
1277
- (f'outputnode.{ surf } ' , surf ) for surf in surfs
1278
- ]),
1279
1279
(sourcefile_buffer , ds_surfaces_wf , [('anat_source_files' , 'inputnode.source_files' )]),
1280
1280
(gifti_surfaces_wf , ds_surfaces_wf , [
1281
1281
(f'outputnode.{ surf } ' , f'inputnode.{ surf } ' ) for surf in surfs
1282
1282
]),
1283
+ (ds_surfaces_wf , surfaces_buffer , [
1284
+ (f'outputnode.{ surf } ' , surf ) for surf in surfs
1285
+ ]),
1283
1286
]) # fmt:skip
1284
1287
if spheres :
1285
1288
gifti_spheres_wf = init_gifti_surfaces_wf (
@@ -1297,13 +1300,13 @@ def init_infant_anat_fit_wf(
1297
1300
('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
1298
1301
# No transform for spheres, following HCP pipelines' lead
1299
1302
]),
1300
- (gifti_spheres_wf , surfaces_buffer , [
1301
- (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
1302
- ]),
1303
1303
(sourcefile_buffer , ds_spheres_wf , [('anat_source_files' , 'inputnode.source_files' )]),
1304
1304
(gifti_spheres_wf , ds_spheres_wf , [
1305
1305
(f'outputnode.{ sphere } ' , f'inputnode.{ sphere } ' ) for sphere in spheres
1306
1306
]),
1307
+ (ds_spheres_wf , surfaces_buffer , [
1308
+ (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
1309
+ ]),
1307
1310
]) # fmt:skip
1308
1311
metrics = [metric for metric in needed_metrics if metric not in found_surfs ]
1309
1312
if metrics :
@@ -1321,13 +1324,13 @@ def init_infant_anat_fit_wf(
1321
1324
('outputnode.subject_id' , 'inputnode.subject_id' ),
1322
1325
('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
1323
1326
]),
1324
- (gifti_morph_wf , surfaces_buffer , [
1325
- (f'outputnode.{ metric } ' , metric ) for metric in metrics
1326
- ]),
1327
1327
(sourcefile_buffer , ds_morph_wf , [('anat_source_files' , 'inputnode.source_files' )]),
1328
1328
(gifti_morph_wf , ds_morph_wf , [
1329
1329
(f'outputnode.{ metric } ' , f'inputnode.{ metric } ' ) for metric in metrics
1330
1330
]),
1331
+ (ds_morph_wf , surfaces_buffer , [
1332
+ (f'outputnode.{ metric } ' , metric ) for metric in metrics
1333
+ ]),
1331
1334
]) # fmt:skip
1332
1335
1333
1336
if 'anat_ribbon' not in precomputed :
@@ -1413,6 +1416,32 @@ def init_infant_anat_fit_wf(
1413
1416
else :
1414
1417
LOGGER .info ('ANAT Stage 9: Found pre-computed fsLR registration sphere' )
1415
1418
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' ])
1416
1445
return workflow
1417
1446
1418
1447
@@ -1476,6 +1505,7 @@ def init_infant_single_anat_fit_wf(
1476
1505
'sphere_reg' ,
1477
1506
'sphere_reg_fsLR' ,
1478
1507
'sphere_reg_msm' ,
1508
+ 'cortex_mask' ,
1479
1509
'anat_ribbon' ,
1480
1510
# Reverse transform; not computable from forward transform
1481
1511
'std2anat_xfm' ,
@@ -2202,13 +2232,13 @@ def init_infant_single_anat_fit_wf(
2202
2232
(fsnative_buffer , gifti_surfaces_wf , [
2203
2233
('fsnative2anat_xfm' , 'inputnode.fsnative2anat_xfm' ),
2204
2234
]),
2205
- (gifti_surfaces_wf , surfaces_buffer , [
2206
- (f'outputnode.{ surf } ' , surf ) for surf in surfs
2207
- ]),
2208
2235
(sourcefile_buffer , ds_surfaces_wf , [('anat_source_files' , 'inputnode.source_files' )]),
2209
2236
(gifti_surfaces_wf , ds_surfaces_wf , [
2210
2237
(f'outputnode.{ surf } ' , f'inputnode.{ surf } ' ) for surf in surfs
2211
2238
]),
2239
+ (ds_surfaces_wf , surfaces_buffer , [
2240
+ (f'outputnode.{ surf } ' , surf ) for surf in surfs
2241
+ ]),
2212
2242
]) # fmt:skip
2213
2243
if spheres :
2214
2244
gifti_spheres_wf = init_gifti_surfaces_wf (
@@ -2226,13 +2256,13 @@ def init_infant_single_anat_fit_wf(
2226
2256
('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
2227
2257
# No transform for spheres, following HCP pipelines' lead
2228
2258
]),
2229
- (gifti_spheres_wf , surfaces_buffer , [
2230
- (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
2231
- ]),
2232
2259
(sourcefile_buffer , ds_spheres_wf , [('anat_source_files' , 'inputnode.source_files' )]),
2233
2260
(gifti_spheres_wf , ds_spheres_wf , [
2234
2261
(f'outputnode.{ sphere } ' , f'inputnode.{ sphere } ' ) for sphere in spheres
2235
2262
]),
2263
+ (ds_spheres_wf , surfaces_buffer , [
2264
+ (f'outputnode.{ sphere } ' , sphere ) for sphere in spheres
2265
+ ]),
2236
2266
]) # fmt:skip
2237
2267
metrics = [metric for metric in needed_metrics if metric not in found_surfs ]
2238
2268
if metrics :
@@ -2250,13 +2280,13 @@ def init_infant_single_anat_fit_wf(
2250
2280
('outputnode.subject_id' , 'inputnode.subject_id' ),
2251
2281
('outputnode.subjects_dir' , 'inputnode.subjects_dir' ),
2252
2282
]),
2253
- (gifti_morph_wf , surfaces_buffer , [
2254
- (f'outputnode.{ metric } ' , metric ) for metric in metrics
2255
- ]),
2256
2283
(sourcefile_buffer , ds_morph_wf , [('anat_source_files' , 'inputnode.source_files' )]),
2257
2284
(gifti_morph_wf , ds_morph_wf , [
2258
2285
(f'outputnode.{ metric } ' , f'inputnode.{ metric } ' ) for metric in metrics
2259
2286
]),
2287
+ (ds_morph_wf , surfaces_buffer , [
2288
+ (f'outputnode.{ metric } ' , metric ) for metric in metrics
2289
+ ]),
2260
2290
]) # fmt:skip
2261
2291
2262
2292
if 'anat_ribbon' not in precomputed :
@@ -2342,4 +2372,30 @@ def init_infant_single_anat_fit_wf(
2342
2372
else :
2343
2373
LOGGER .info ('ANAT Stage 9: Found pre-computed fsLR registration sphere' )
2344
2374
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' ])
2345
2401
return workflow
0 commit comments