16
16
mri_convert , \
17
17
wb_command , \
18
18
fslmaths_command , \
19
- VolumeRemoveIslands
19
+ VolumeRemoveIslands , \
20
+ normalize_wmparc
20
21
from CPAC .pipeline .engine import flatten_list
21
22
from CPAC .utils .docs import docstring_parameter
22
23
from CPAC .utils .interfaces .fsl import Merge as fslMerge
@@ -914,16 +915,44 @@ def freesurfer_abcd_brain_connector(wf, cfg, strat_pool, pipe_num, opt):
914
915
### ABCD harmonization - anatomical brain mask generation ###
915
916
# Ref: https://github.com/DCAN-Labs/DCAN-HCP/blob/master/PostFreeSurfer/PostFreeSurferPipeline.sh#L151-L156
916
917
918
+
917
919
wmparc_to_nifti = pe .Node (util .Function (input_names = ['in_file' ,
918
920
'reslice_like' ,
919
921
'args' ],
920
922
output_names = ['out_file' ],
921
923
function = mri_convert ),
922
924
name = f'wmparc_to_nifti_{ pipe_num } ' )
923
- wmparc_to_nifti .inputs .args = '-rt nearest'
925
+
926
+ # Register wmparc file if ingressing FreeSurfer data
927
+ if strat_pool .check_rpool ('pipeline-fs_xfm' ):
928
+
929
+ wmparc_to_native = pe .Node (util .Function (input_names = ['source_file' ,
930
+ 'target_file' ,
931
+ 'xfm' ,
932
+ 'out_file' ],
933
+ output_names = ['transformed_file' ],
934
+ function = normalize_wmparc ),
935
+ name = f'wmparc_to_native_{ pipe_num } ' )
936
+
937
+ wmparc_to_native .inputs .out_file = 'wmparc_warped.mgz'
938
+
939
+ node , out = strat_pool .get_data ('pipeline-fs_wmparc' )
940
+ wf .connect (node , out , wmparc_to_native , 'source_file' )
941
+
942
+ node , out = strat_pool .get_data ('pipeline-fs_raw-average' )
943
+ wf .connect (node , out , wmparc_to_native , 'target_file' )
924
944
925
- node , out = strat_pool .get_data ('pipeline-fs_wmparc' )
926
- wf .connect (node , out , wmparc_to_nifti , 'in_file' )
945
+ node , out = strat_pool .get_data ('pipeline-fs_xfm' )
946
+ wf .connect (node , out , wmparc_to_native , 'xfm' )
947
+
948
+ wf .connect (wmparc_to_native , 'transformed_file' , wmparc_to_nifti , 'in_file' )
949
+
950
+ else :
951
+
952
+ node , out = strat_pool .get_data ('pipeline-fs_wmparc' )
953
+ wf .connect (node , out , wmparc_to_nifti , 'in_file' )
954
+
955
+ wmparc_to_nifti .inputs .args = '-rt nearest'
927
956
928
957
node , out = strat_pool .get_data ('desc-preproc_T1w' )
929
958
wf .connect (node , out , wmparc_to_nifti , 'reslice_like' )
@@ -1244,21 +1273,24 @@ def acpc_align_head(wf, cfg, strat_pool, pipe_num, opt=None):
1244
1273
["anatomical_preproc", "run"]],
1245
1274
"option_key": "None",
1246
1275
"option_val": "None",
1247
- "inputs": ["desc-head_T1w ",
1248
- "desc-preproc_T1w ",
1276
+ "inputs": ["desc-preproc_T1w ",
1277
+ "desc-head_T1w ",
1249
1278
"T1w-ACPC-template"],
1250
1279
"outputs": ["desc-head_T1w",
1251
1280
"desc-preproc_T1w",
1252
1281
"from-T1w_to-ACPC_mode-image_desc-aff2rig_xfm"]}
1253
1282
'''
1254
-
1283
+
1284
+ # NOTE: desc-preproc_T1w and desc-head_T1w are both needed in this
1285
+ # nodeblock despite the list called in get_data() below
1286
+
1255
1287
acpc_align = acpc_alignment (config = cfg ,
1256
1288
acpc_target = cfg .anatomical_preproc [
1257
1289
'acpc_alignment' ]['acpc_target' ],
1258
1290
mask = False ,
1259
1291
wf_name = f'acpc_align_{ pipe_num } ' )
1260
1292
1261
- node , out = strat_pool .get_data (['desc-head_T1w' , 'desc-preproc_T1w ' ])
1293
+ node , out = strat_pool .get_data (['desc-preproc_T1w' , 'desc-head_T1w ' ])
1262
1294
wf .connect (node , out , acpc_align , 'inputspec.anat_leaf' )
1263
1295
1264
1296
node , out = strat_pool .get_data ('T1w-ACPC-template' )
@@ -1772,6 +1804,8 @@ def brain_mask_freesurfer_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
1772
1804
"option_val": "FreeSurfer-ABCD",
1773
1805
"inputs": ["desc-preproc_T1w",
1774
1806
"pipeline-fs_wmparc",
1807
+ "pipeline-fs_raw-average",
1808
+ "pipeline-fs_xfm",
1775
1809
"freesurfer-subject-dir"],
1776
1810
"outputs": ["space-T1w_desc-brain_mask"]}
1777
1811
'''
@@ -1813,6 +1847,8 @@ def brain_mask_acpc_freesurfer_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
1813
1847
"option_val": "FreeSurfer-ABCD",
1814
1848
"inputs": ["desc-preproc_T1w",
1815
1849
"pipeline-fs_wmparc",
1850
+ "pipeline-fs_raw-average",
1851
+ "pipeline-fs_xfm",
1816
1852
"freesurfer-subject-dir"],
1817
1853
"outputs": ["space-T1w_desc-acpcbrain_mask"]}
1818
1854
'''
@@ -2533,10 +2569,10 @@ def brain_extraction_temp_T2(wf, cfg, strat_pool, pipe_num, opt=None):
2533
2569
def freesurfer_abcd_preproc (wf , cfg , strat_pool , pipe_num , opt = None ):
2534
2570
'''
2535
2571
{"name": "freesurfer_abcd_preproc",
2536
- "config": ["anatomical_preproc ", "brain_extraction "],
2537
- "switch": "None" ,
2538
- "option_key": "using ",
2539
- "option_val": "FreeSurfer-ABCD ",
2572
+ "config": ["surface_analysis ", "abcd_prefreesurfer_prep "],
2573
+ "switch": ["run"] ,
2574
+ "option_key": "None ",
2575
+ "option_val": "None ",
2540
2576
"inputs": ["desc-preproc_T1w",
2541
2577
"T1w-template",
2542
2578
"T1w-brain-template-mask",
@@ -2545,16 +2581,17 @@ def freesurfer_abcd_preproc(wf, cfg, strat_pool, pipe_num, opt=None):
2545
2581
"freesurfer-subject-dir"],
2546
2582
"outputs": ["desc-restore_T1w",
2547
2583
"desc-restore-brain_T1w",
2584
+ "desc-ABCDpreproc_T1w",
2548
2585
"pipeline-fs_desc-fast_biasfield",
2549
2586
"pipeline-fs_hemi-L_desc-surface_curv",
2550
- "pipeline-fs_hemi-R_desc-surface_curv",
2587
+ "pipeline-fs_hemi-R_desc-surface_curv",
2551
2588
"pipeline-fs_hemi-L_desc-surfaceMesh_pial",
2552
2589
"pipeline-fs_hemi-R_desc-surfaceMesh_pial",
2553
2590
"pipeline-fs_hemi-L_desc-surfaceMesh_smoothwm",
2554
2591
"pipeline-fs_hemi-R_desc-surfaceMesh_smoothwm",
2555
2592
"pipeline-fs_hemi-L_desc-surfaceMesh_sphere",
2556
2593
"pipeline-fs_hemi-R_desc-surfaceMesh_sphere",
2557
- "pipeline-fs_hemi-L_desc-surfaceMap_sulc",
2594
+ "pipeline-fs_hemi-L_desc-surfaceMap_sulc",
2558
2595
"pipeline-fs_hemi-R_desc-surfaceMap_sulc",
2559
2596
"pipeline-fs_hemi-L_desc-surfaceMap_thickness",
2560
2597
"pipeline-fs_hemi-R_desc-surfaceMap_thickness",
@@ -2565,7 +2602,6 @@ def freesurfer_abcd_preproc(wf, cfg, strat_pool, pipe_num, opt=None):
2565
2602
"pipeline-fs_wmparc",
2566
2603
"freesurfer-subject-dir"]}
2567
2604
'''
2568
-
2569
2605
# fnirt-based brain extraction
2570
2606
brain_extraction = fnirt_based_brain_extraction (config = cfg ,
2571
2607
wf_name = f'fnirt_based_brain_extraction_{ pipe_num } ' )
@@ -2657,52 +2693,15 @@ def freesurfer_abcd_preproc(wf, cfg, strat_pool, pipe_num, opt=None):
2657
2693
wf .connect (average_brain , 'out_stat' ,
2658
2694
normalize_head , 'number' )
2659
2695
2660
- if strat_pool .check_rpool ('freesurfer-subject-dir' ):
2661
- outputs = {
2696
+ outputs = {
2662
2697
'desc-restore_T1w' : (fast_correction , 'outputspec.anat_restore' ),
2663
2698
'desc-restore-brain_T1w' : (fast_correction ,
2664
2699
'outputspec.anat_brain_restore' ),
2665
- 'pipeline-fs_desc-fast_biasfield' : (fast_correction , 'outputspec.bias_field' )}
2666
- return (wf , outputs )
2667
-
2668
- else :
2669
- ### recon-all -all step ###
2670
- reconall = pe .Node (interface = freesurfer .ReconAll (),
2671
- name = f'anat_freesurfer_{ pipe_num } ' ,
2672
- mem_gb = 2.7 )
2673
-
2674
- sub_dir = cfg .pipeline_setup ['working_directory' ]['path' ]
2675
- freesurfer_subject_dir = os .path .join (sub_dir ,
2676
- 'cpac_' + cfg ['subject_id' ],
2677
- f'anat_preproc_freesurfer_{ pipe_num } ' ,
2678
- 'anat_freesurfer' )
2679
-
2680
- # create the directory for FreeSurfer node
2681
- if not os .path .exists (freesurfer_subject_dir ):
2682
- os .makedirs (freesurfer_subject_dir )
2683
-
2684
- reconall .inputs .directive = 'all'
2685
- reconall .inputs .subjects_dir = freesurfer_subject_dir
2686
- reconall .inputs .openmp = cfg .pipeline_setup ['system_config' ]['num_OMP_threads' ]
2687
-
2688
- wf .connect (normalize_head , 'out_file' ,
2689
- reconall , 'T1_files' )
2690
-
2691
- wf , hemisphere_outputs = freesurfer_hemispheres (wf , reconall , pipe_num )
2692
-
2693
- outputs = {
2694
- 'desc-restore_T1w' : (fast_correction , 'outputspec.anat_restore' ),
2695
- 'desc-restore-brain_T1w' : (fast_correction ,
2696
- 'outputspec.anat_brain_restore' ),
2697
- 'pipeline-fs_desc-fast_biasfield' : (fast_correction , 'outputspec.bias_field' ),
2698
- 'pipeline-fs_wmparc' : (reconall , 'wmparc' ),
2699
- 'freesurfer-subject-dir' : (reconall , 'subjects_dir' ),
2700
- ** hemisphere_outputs
2701
- }
2702
-
2700
+ 'pipeline-fs_desc-fast_biasfield' : (fast_correction , 'outputspec.bias_field' ),
2701
+ 'desc-ABCDpreproc_T1w' : (normalize_head , 'out_file' )
2702
+ }
2703
2703
return (wf , outputs )
2704
2704
2705
-
2706
2705
# we're grabbing the postproc outputs and appending them to
2707
2706
# the reconall outputs
2708
2707
@docstring_parameter (postproc_outputs = str (flatten_list (freesurfer_abcd_preproc , 'outputs' )
@@ -2715,7 +2714,8 @@ def freesurfer_reconall(wf, cfg, strat_pool, pipe_num, opt=None):
2715
2714
"switch": ["run_reconall"],
2716
2715
"option_key": "None",
2717
2716
"option_val": "None",
2718
- "inputs": ["desc-preproc_T1w"],
2717
+ "inputs": [["desc-ABCDpreproc_T1w",
2718
+ "desc-preproc_T1w"]],
2719
2719
"outputs": ["freesurfer-subject-dir",
2720
2720
"pipeline-fs_raw-average",
2721
2721
"pipeline-fs_subcortical-seg",
@@ -2748,7 +2748,7 @@ def freesurfer_reconall(wf, cfg, strat_pool, pipe_num, opt=None):
2748
2748
reconall .inputs .args = cfg .surface_analysis ['freesurfer' ][
2749
2749
'reconall_args' ]
2750
2750
2751
- node , out = strat_pool .get_data ("desc-preproc_T1w" )
2751
+ node , out = strat_pool .get_data ([ "desc-ABCDpreproc_T1w" , "desc- preproc_T1w"] )
2752
2752
wf .connect (node , out , reconall , 'T1_files' )
2753
2753
2754
2754
wf , hemisphere_outputs = freesurfer_hemispheres (wf , reconall , pipe_num )
@@ -2983,9 +2983,9 @@ def fast_bias_field_correction(config=None, wf_name='fast_bias_field_correction'
2983
2983
def correct_restore_brain_intensity_abcd (wf , cfg , strat_pool , pipe_num , opt = None ):
2984
2984
'''
2985
2985
{"name": "correct_restore_brain_intensity_abcd",
2986
- "config": ["anatomical_preproc", "brain_extraction"] ,
2987
- "switch": "None" ,
2988
- "option_key": " using",
2986
+ "config": "None" ,
2987
+ "switch": ["anatomical_preproc", "brain_extraction", "run"] ,
2988
+ "option_key": ["anatomical_preproc", "brain_extraction", " using"] ,
2989
2989
"option_val": "FreeSurfer-ABCD",
2990
2990
"inputs": [("desc-preproc_T1w",
2991
2991
"desc-n4_T1w",
0 commit comments