Skip to content

Commit 7b13bce

Browse files
authored
Merge pull request #1924 from e-kenneally/fix/fs_ingress
🐛 Fix FreeSurfer ingress misalignment
2 parents 18206af + 6e07437 commit 7b13bce

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

CPAC/anat_preproc/anat_preproc.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,24 @@ def freesurfer_abcd_brain_connector(wf, cfg, strat_pool, pipe_num, opt):
914914
### ABCD harmonization - anatomical brain mask generation ###
915915
# Ref: https://github.com/DCAN-Labs/DCAN-HCP/blob/master/PostFreeSurfer/PostFreeSurferPipeline.sh#L151-L156
916916

917+
wmparc_to_native = pe.Node(
918+
interface=freesurfer.ApplyVolTransform(),
919+
name='wmparc_to_native')
920+
921+
wmparc_to_native.inputs.reg_header = True
922+
923+
node, out = strat_pool.get_data('pipeline-fs_wmparc')
924+
wf.connect(node, out, wmparc_to_native, 'source_file')
925+
926+
node, out = strat_pool.get_data('pipeline-fs_raw-average')
927+
wf.connect(node, out, wmparc_to_native, 'target_file')
928+
929+
node, out = strat_pool.get_data('pipeline-fs_xfm')
930+
wf.connect(node, out, wmparc_to_native, 'xfm_reg_file')
931+
932+
node, out = strat_pool.get_data('freesurfer-subject-dir')
933+
934+
wf.connect(node, out, wmparc_to_native, 'subjects_dir')
917935
wmparc_to_nifti = pe.Node(util.Function(input_names=['in_file',
918936
'reslice_like',
919937
'args'],
@@ -922,8 +940,7 @@ def freesurfer_abcd_brain_connector(wf, cfg, strat_pool, pipe_num, opt):
922940
name=f'wmparc_to_nifti_{pipe_num}')
923941
wmparc_to_nifti.inputs.args = '-rt nearest'
924942

925-
node, out = strat_pool.get_data('pipeline-fs_wmparc')
926-
wf.connect(node, out, wmparc_to_nifti, 'in_file')
943+
wf.connect(wmparc_to_native, 'transformed_file', wmparc_to_nifti, 'in_file')
927944

928945
node, out = strat_pool.get_data('desc-preproc_T1w')
929946
wf.connect(node, out, wmparc_to_nifti, 'reslice_like')
@@ -1772,6 +1789,8 @@ def brain_mask_freesurfer_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
17721789
"option_val": "FreeSurfer-ABCD",
17731790
"inputs": ["desc-preproc_T1w",
17741791
"pipeline-fs_wmparc",
1792+
"pipeline-fs_raw-average",
1793+
"pipeline-fs_xfm",
17751794
"freesurfer-subject-dir"],
17761795
"outputs": ["space-T1w_desc-brain_mask"]}
17771796
'''
@@ -1813,6 +1832,8 @@ def brain_mask_acpc_freesurfer_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
18131832
"option_val": "FreeSurfer-ABCD",
18141833
"inputs": ["desc-preproc_T1w",
18151834
"pipeline-fs_wmparc",
1835+
"pipeline-fs_raw-average",
1836+
"pipeline-fs_xfm",
18161837
"freesurfer-subject-dir"],
18171838
"outputs": ["space-T1w_desc-acpcbrain_mask"]}
18181839
'''
@@ -2565,7 +2586,6 @@ def freesurfer_abcd_preproc(wf, cfg, strat_pool, pipe_num, opt=None):
25652586
"pipeline-fs_wmparc",
25662587
"freesurfer-subject-dir"]}
25672588
'''
2568-
25692589
# fnirt-based brain extraction
25702590
brain_extraction = fnirt_based_brain_extraction(config=cfg,
25712591
wf_name=f'fnirt_based_brain_extraction_{pipe_num}')
@@ -2666,6 +2686,7 @@ def freesurfer_abcd_preproc(wf, cfg, strat_pool, pipe_num, opt=None):
26662686
return (wf, outputs)
26672687

26682688
else:
2689+
26692690
### recon-all -all step ###
26702691
reconall = pe.Node(interface=freesurfer.ReconAll(),
26712692
name=f'anat_freesurfer_{pipe_num}',

CPAC/pipeline/engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,7 @@ def ingress_raw_anat_data(wf, rpool, cfg, data_paths, unique_id, part_id,
17211721
'pipeline-fs_hemi-R_desc-surfaceMap_volume': 'surf/rh.volume',
17221722
'pipeline-fs_hemi-L_desc-surfaceMesh_white': 'surf/lh.white',
17231723
'pipeline-fs_hemi-R_desc-surfaceMesh_white': 'surf/rh.white',
1724+
'pipeline-fs_xfm': 'mri/transforms/talairach.xfm'
17241725
}
17251726

17261727
for key, outfile in recon_outs.items():

CPAC/seg_preproc/seg_preproc.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,9 @@ def tissue_seg_freesurfer(wf, cfg, strat_pool, pipe_num, opt=None):
796796
"switch": ["run"],
797797
"option_key": ["tissue_segmentation", "using"],
798798
"option_val": "FreeSurfer",
799-
"inputs": ["freesurfer-subject-dir"],
799+
"inputs": ["freesurfer-subject-dir",
800+
"pipeline-fs_raw-average",
801+
"pipeline-fs_subcortical-seg"],
800802
"outputs": ["pipeline-fs_hemi-L_desc-surface_curv",
801803
"pipeline-fs_hemi-R_desc-surface_curv",
802804
"pipeline-fs_hemi-L_desc-surfaceMesh_pial",
@@ -818,12 +820,30 @@ def tissue_seg_freesurfer(wf, cfg, strat_pool, pipe_num, opt=None):
818820
"label-WM_mask"]}
819821
'''
820822

823+
node, out = strat_pool.get_data('freesurfer-subject-dir')
824+
825+
fs_aseg_to_native = pe.Node(interface=freesurfer.ApplyVolTransform(),
826+
name=f'fs_aseg_to_native_{pipe_num}')
827+
fs_aseg_to_native.inputs.reg_header = True
828+
fs_aseg_to_native.inputs.interp = 'nearest'
829+
830+
wf.connect(node, out, fs_aseg_to_native, 'subjects_dir')
831+
832+
node, out = strat_pool.get_data('pipeline-fs_subcortical-seg')
833+
wf.connect(node, out, fs_aseg_to_native, 'source_file')
834+
835+
node, out = strat_pool.get_data('pipeline-fs_raw-average')
836+
wf.connect(node, out, fs_aseg_to_native, 'target_file')
837+
821838
fs_aseg_to_nifti = pe.Node(util.Function(input_names=['in_file'],
822839
output_names=['out_file'],
823840
function=mri_convert),
824841
name=f'fs_aseg_to_nifti_{pipe_num}')
825842
fs_aseg_to_nifti.inputs.args = '-rt nearest'
826843

844+
wf.connect(fs_aseg_to_native, 'transformed_file',
845+
fs_aseg_to_nifti, 'in_file')
846+
827847
pick_tissue = pe.Node(pick_tissue_from_labels_file_interface(),
828848
name=f'select_fs_tissue_{pipe_num}')
829849

0 commit comments

Comments
 (0)