9
9
.. autofunction:: init_bold_preproc_trans_wf
10
10
11
11
"""
12
+ from __future__ import annotations
12
13
14
+ import typing as ty
13
15
14
- from os .path import basename
15
-
16
- import nipype .interfaces .workbench as wb
16
+ import templateflow .api as tf
17
17
from nipype import Function
18
18
from nipype .interfaces import freesurfer as fs
19
19
from nipype .interfaces import fsl
20
20
from nipype .interfaces import utility as niu
21
21
from nipype .pipeline import engine as pe
22
22
from niworkflows .interfaces .fixes import FixHeaderApplyTransforms as ApplyTransforms
23
23
from niworkflows .interfaces .freesurfer import MedialNaNs
24
+ from niworkflows .interfaces .workbench import MetricDilate , MetricMask , MetricResample
24
25
25
26
from nibabies .config import DEFAULT_MEMORY_MIN_GB
27
+ from nibabies .data import load_resource
28
+
29
+ if ty .TYPE_CHECKING :
30
+ from niworkflows .utils .spaces import SpatialReferences
26
31
27
32
28
33
def init_bold_surf_wf (
@@ -82,8 +87,6 @@ def init_bold_surf_wf(
82
87
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
83
88
from niworkflows .interfaces .surf import GiftiSetAnatomicalStructure
84
89
85
- from ...interfaces .metric import MetricDilate
86
-
87
90
workflow = Workflow (name = name )
88
91
workflow .__desc__ = """\
89
92
The BOLD time-series were resampled onto the following surfaces
@@ -422,47 +425,6 @@ def _calc_lower_thr(in_stats):
422
425
mem_gb = mem_gb ,
423
426
)
424
427
425
- # make HCP-style "goodvoxels" mask in t1w space for filtering outlier voxels
426
- # in bold timeseries, based on modulated normalized covariance
427
- workflow .connect (
428
- [
429
- (inputnode , ribbon_boldsrc_xfm , [("anat_ribbon" , "input_image" )]),
430
- (inputnode , stdev_volume , [("bold_file" , "in_file" )]),
431
- (inputnode , mean_volume , [("bold_file" , "in_file" )]),
432
- (mean_volume , ribbon_boldsrc_xfm , [("out_file" , "reference_image" )]),
433
- (stdev_volume , cov_volume , [("out_file" , "in_file" )]),
434
- (mean_volume , cov_volume , [("out_file" , "operand_file" )]),
435
- (cov_volume , cov_ribbon , [("out_file" , "in_file" )]),
436
- (ribbon_boldsrc_xfm , cov_ribbon , [("output_image" , "mask_file" )]),
437
- (cov_ribbon , cov_ribbon_mean , [("out_file" , "in_file" )]),
438
- (cov_ribbon , cov_ribbon_std , [("out_file" , "in_file" )]),
439
- (cov_ribbon , cov_ribbon_norm , [("out_file" , "in_file" )]),
440
- (cov_ribbon_mean , cov_ribbon_norm , [("out_stat" , "operand_value" )]),
441
- (cov_ribbon_norm , smooth_norm , [("out_file" , "in_file" )]),
442
- (smooth_norm , merge_smooth_norm , [("out_file" , "in1" )]),
443
- (cov_ribbon_norm , cov_ribbon_norm_smooth , [("out_file" , "in_file" )]),
444
- (merge_smooth_norm , cov_ribbon_norm_smooth , [("out" , "operand_files" )]),
445
- (cov_ribbon_mean , cov_norm , [("out_stat" , "operand_value" )]),
446
- (cov_volume , cov_norm , [("out_file" , "in_file" )]),
447
- (cov_norm , cov_norm_modulate , [("out_file" , "in_file" )]),
448
- (cov_ribbon_norm_smooth , cov_norm_modulate , [("out_file" , "operand_file" )]),
449
- (cov_norm_modulate , cov_norm_modulate_ribbon , [("out_file" , "in_file" )]),
450
- (ribbon_boldsrc_xfm , cov_norm_modulate_ribbon , [("output_image" , "mask_file" )]),
451
- (cov_norm_modulate_ribbon , mod_ribbon_mean , [("out_file" , "in_file" )]),
452
- (cov_norm_modulate_ribbon , mod_ribbon_std , [("out_file" , "in_file" )]),
453
- (mod_ribbon_mean , merge_mod_ribbon_stats , [("out_stat" , "in1" )]),
454
- (mod_ribbon_std , merge_mod_ribbon_stats , [("out_stat" , "in2" )]),
455
- (merge_mod_ribbon_stats , upper_thr_val , [("out" , "in_stats" )]),
456
- (merge_mod_ribbon_stats , lower_thr_val , [("out" , "in_stats" )]),
457
- (mean_volume , bin_mean_volume , [("out_file" , "in_file" )]),
458
- (upper_thr_val , goodvoxels_thr , [("upper_thresh" , "thresh" )]),
459
- (cov_norm_modulate , goodvoxels_thr , [("out_file" , "in_file" )]),
460
- (bin_mean_volume , merge_goodvoxels_operands , [("out_file" , "in1" )]),
461
- (goodvoxels_thr , goodvoxels_mask , [("out_file" , "in_file" )]),
462
- (merge_goodvoxels_operands , goodvoxels_mask , [("out" , "operand_files" )]),
463
- ]
464
- )
465
-
466
428
goodvoxels_ribbon_mask = pe .Node (
467
429
fsl .ApplyMask (),
468
430
name_source = ['in_file' ],
@@ -471,8 +433,44 @@ def _calc_lower_thr(in_stats):
471
433
mem_gb = DEFAULT_MEMORY_MIN_GB ,
472
434
)
473
435
436
+ # make HCP-style "goodvoxels" mask in t1w space for filtering outlier voxels
437
+ # in bold timeseries, based on modulated normalized covariance
474
438
# fmt:off
475
439
workflow .connect ([
440
+ (inputnode , ribbon_boldsrc_xfm , [("anat_ribbon" , "input_image" )]),
441
+ (inputnode , stdev_volume , [("bold_file" , "in_file" )]),
442
+ (inputnode , mean_volume , [("bold_file" , "in_file" )]),
443
+ (mean_volume , ribbon_boldsrc_xfm , [("out_file" , "reference_image" )]),
444
+ (stdev_volume , cov_volume , [("out_file" , "in_file" )]),
445
+ (mean_volume , cov_volume , [("out_file" , "operand_file" )]),
446
+ (cov_volume , cov_ribbon , [("out_file" , "in_file" )]),
447
+ (ribbon_boldsrc_xfm , cov_ribbon , [("output_image" , "mask_file" )]),
448
+ (cov_ribbon , cov_ribbon_mean , [("out_file" , "in_file" )]),
449
+ (cov_ribbon , cov_ribbon_std , [("out_file" , "in_file" )]),
450
+ (cov_ribbon , cov_ribbon_norm , [("out_file" , "in_file" )]),
451
+ (cov_ribbon_mean , cov_ribbon_norm , [("out_stat" , "operand_value" )]),
452
+ (cov_ribbon_norm , smooth_norm , [("out_file" , "in_file" )]),
453
+ (smooth_norm , merge_smooth_norm , [("out_file" , "in1" )]),
454
+ (cov_ribbon_norm , cov_ribbon_norm_smooth , [("out_file" , "in_file" )]),
455
+ (merge_smooth_norm , cov_ribbon_norm_smooth , [("out" , "operand_files" )]),
456
+ (cov_ribbon_mean , cov_norm , [("out_stat" , "operand_value" )]),
457
+ (cov_volume , cov_norm , [("out_file" , "in_file" )]),
458
+ (cov_norm , cov_norm_modulate , [("out_file" , "in_file" )]),
459
+ (cov_ribbon_norm_smooth , cov_norm_modulate , [("out_file" , "operand_file" )]),
460
+ (cov_norm_modulate , cov_norm_modulate_ribbon , [("out_file" , "in_file" )]),
461
+ (ribbon_boldsrc_xfm , cov_norm_modulate_ribbon , [("output_image" , "mask_file" )]),
462
+ (cov_norm_modulate_ribbon , mod_ribbon_mean , [("out_file" , "in_file" )]),
463
+ (cov_norm_modulate_ribbon , mod_ribbon_std , [("out_file" , "in_file" )]),
464
+ (mod_ribbon_mean , merge_mod_ribbon_stats , [("out_stat" , "in1" )]),
465
+ (mod_ribbon_std , merge_mod_ribbon_stats , [("out_stat" , "in2" )]),
466
+ (merge_mod_ribbon_stats , upper_thr_val , [("out" , "in_stats" )]),
467
+ (merge_mod_ribbon_stats , lower_thr_val , [("out" , "in_stats" )]),
468
+ (mean_volume , bin_mean_volume , [("out_file" , "in_file" )]),
469
+ (upper_thr_val , goodvoxels_thr , [("upper_thresh" , "thresh" )]),
470
+ (cov_norm_modulate , goodvoxels_thr , [("out_file" , "in_file" )]),
471
+ (bin_mean_volume , merge_goodvoxels_operands , [("out_file" , "in1" )]),
472
+ (goodvoxels_thr , goodvoxels_mask , [("out_file" , "in_file" )]),
473
+ (merge_goodvoxels_operands , goodvoxels_mask , [("out" , "operand_files" )]),
476
474
(goodvoxels_mask , goodvoxels_ribbon_mask , [("out_file" , "in_file" )]),
477
475
(ribbon_boldsrc_xfm , goodvoxels_ribbon_mask , [("output_image" , "mask_file" )]),
478
476
(goodvoxels_mask , outputnode , [("out_file" , "goodvoxels_mask" )]),
@@ -603,20 +601,31 @@ def init_bold_fsLR_resampling_wf(
603
601
),
604
602
name = 'select_surfaces' ,
605
603
)
606
- select_surfaces .inputs .template_spheres = [
607
- str (sphere )
608
- for sphere in tf .get (
609
- template = 'fsLR' ,
610
- density = fslr_density ,
611
- suffix = 'sphere' ,
612
- space = None ,
613
- extension = '.surf.gii' ,
614
- )
615
- ]
616
- atlases = smriprep_data .load_resource ('atlases' )
604
+ if mcribs :
605
+ atlases = load_resource ('atlases' )
606
+ # use dHCP 32k fsLR instead
607
+ select_surfaces .inputs .template_spheres = [
608
+ str (atlases / 'dHCP' / 'dHCP.week42.L.sphere.surf.gii' ),
609
+ str (atlases / 'dHCP' / 'dHCP.week42.R.sphere.surf.gii' ),
610
+ ]
611
+
612
+ # TODO: different template ROIs?
613
+ else :
614
+ select_surfaces .inputs .template_spheres = [
615
+ str (sphere )
616
+ for sphere in tf .get (
617
+ template = 'fsLR' ,
618
+ density = fslr_density ,
619
+ suffix = 'sphere' ,
620
+ space = None ,
621
+ extension = '.surf.gii' ,
622
+ )
623
+ ]
624
+
625
+ smriprep_atlases = smriprep_data .load_resource ('atlases' )
617
626
select_surfaces .inputs .template_rois = [
618
- str (atlases / 'L.atlasroi.32k_fs_LR.shape.gii' ),
619
- str (atlases / 'R.atlasroi.32k_fs_LR.shape.gii' ),
627
+ str (smriprep_atlases / 'L.atlasroi.32k_fs_LR.shape.gii' ),
628
+ str (smriprep_atlases / 'R.atlasroi.32k_fs_LR.shape.gii' ),
620
629
]
621
630
622
631
# Reimplements lines 282-290 of FreeSurfer2CaretConvertAndRegisterNonlinear.sh
@@ -1208,7 +1217,6 @@ def init_bold_grayords_wf(grayord_density, mem_gb, repetition_time, name="bold_g
1208
1217
BIDS metadata file corresponding to ``cifti_bold``.
1209
1218
1210
1219
"""
1211
- import templateflow as tf
1212
1220
from niworkflows .engine .workflows import LiterateWorkflow as Workflow
1213
1221
from niworkflows .interfaces .utility import KeySelect
1214
1222
@@ -1248,7 +1256,7 @@ def init_bold_grayords_wf(grayord_density, mem_gb, repetition_time, name="bold_g
1248
1256
)
1249
1257
gen_cifti = pe .Node (CiftiCreateDenseTimeseries (timestep = repetition_time ), name = "gen_cifti" )
1250
1258
gen_cifti .inputs .volume_structure_labels = str (
1251
- tf .api . get ("MNI152NLin6Asym" , resolution = mni_density , atlas = "HCP" , suffix = "dseg" )
1259
+ tf .get ("MNI152NLin6Asym" , resolution = mni_density , atlas = "HCP" , suffix = "dseg" )
1252
1260
)
1253
1261
gen_cifti_metadata = pe .Node (
1254
1262
niu .Function (function = _gen_metadata , output_names = ["out_metadata" ]),
@@ -1266,10 +1274,6 @@ def init_bold_grayords_wf(grayord_density, mem_gb, repetition_time, name="bold_g
1266
1274
(split_surfaces , gen_cifti , [
1267
1275
('left_surface' , 'left_metric' ),
1268
1276
('right_surface' , 'right_metric' )]),
1269
- # (resample, split_surfaces, [('out_file', 'in_surfaces')]),
1270
- # (split_surfaces, gen_cifti, [
1271
- # ('left_surface', 'left_metric'),
1272
- # ('right_surface', 'right_metric')]),
1273
1277
(gen_cifti , outputnode , [('out_file' , 'cifti_bold' )]),
1274
1278
(gen_cifti_metadata , outputnode , [('out_metadata' , 'cifti_metadata' )]),
1275
1279
])
0 commit comments