Skip to content

Commit 691dd54

Browse files
committed
RF: Reuse cortical mask ROI and downsampled midthickness
1 parent f0eff51 commit 691dd54

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

fmriprep/workflows/base.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def init_single_subject_wf(subject_id: str):
162162
init_gifti_morphometrics_wf,
163163
init_hcp_morphometrics_wf,
164164
init_morph_grayords_wf,
165+
init_resample_midthickness_wf,
165166
)
166167

167168
from fmriprep.workflows.bold.base import init_bold_wf
@@ -435,6 +436,9 @@ def init_single_subject_wf(subject_id: str):
435436
grayord_density=config.workflow.cifti_output,
436437
omp_nthreads=omp_nthreads,
437438
)
439+
resample_midthickness_wf = init_resample_midthickness_wf(
440+
grayord_density=config.workflow.cifti_output,
441+
)
438442
ds_grayord_metrics_wf = init_ds_grayord_metrics_wf(
439443
bids_root=bids_root,
440444
output_dir=fmriprep_dir,
@@ -456,6 +460,13 @@ def init_single_subject_wf(subject_id: str):
456460
(curv_wf, hcp_morphometrics_wf, [
457461
("outputnode.curv", "inputnode.curv"),
458462
]),
463+
(anat_fit_wf, resample_midthickness_wf, [
464+
('outputnode.midthickness', 'inputnode.midthickness'),
465+
(
466+
f"outputnode.sphere_reg_{'msm' if msm_sulc else 'fsLR'}",
467+
"inputnode.sphere_reg_fsLR",
468+
),
469+
]),
459470
(anat_fit_wf, morph_grayords_wf, [
460471
("outputnode.midthickness", "inputnode.midthickness"),
461472
(
@@ -469,6 +480,9 @@ def init_single_subject_wf(subject_id: str):
469480
("outputnode.sulc", "inputnode.sulc"),
470481
("outputnode.roi", "inputnode.roi"),
471482
]),
483+
(resample_midthickness_wf, morph_grayords_wf, [
484+
('outputnode.midthickness_fsLR', 'inputnode.midthickness_fsLR'),
485+
]),
472486
(anat_fit_wf, ds_grayord_metrics_wf, [
473487
('outputnode.t1w_valid_list', 'inputnode.source_files'),
474488
]),
@@ -648,7 +662,6 @@ def init_single_subject_wf(subject_id: str):
648662
('outputnode.white', 'inputnode.white'),
649663
('outputnode.pial', 'inputnode.pial'),
650664
('outputnode.midthickness', 'inputnode.midthickness'),
651-
('outputnode.thickness', 'inputnode.thickness'),
652665
('outputnode.anat_ribbon', 'inputnode.anat_ribbon'),
653666
(
654667
f'outputnode.sphere_reg_{"msm" if msm_sulc else "fsLR"}',
@@ -696,6 +709,12 @@ def init_single_subject_wf(subject_id: str):
696709
workflow.connect([
697710
(select_MNI6_xfm, bold_wf, [("anat2std_xfm", "inputnode.anat2mni6_xfm")]),
698711
(select_MNI6_tpl, bold_wf, [("brain_mask", "inputnode.mni6_mask")]),
712+
(hcp_morphometrics_wf, bold_wf, [
713+
("outputnode.roi", "inputnode.cortex_mask"),
714+
]),
715+
(resample_midthickness_wf, bold_wf, [
716+
('outputnode.midthickness_fsLR', 'inputnode.midthickness_fsLR'),
717+
]),
699718
]) # fmt:skip
700719

701720
return clean_datasinks(workflow)

fmriprep/workflows/bold/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ def init_bold_wf(
113113
FreeSurfer pial surfaces, in T1w space, collated left, then right
114114
sphere_reg_fsLR
115115
Registration spheres from fsnative to fsLR space, collated left, then right
116-
thickness
117-
FreeSurfer thickness metrics, collated left, then right
118116
anat_ribbon
119117
Binary cortical ribbon mask in T1w space
120118
fmap_id
@@ -235,7 +233,8 @@ def init_bold_wf(
235233
"midthickness",
236234
"pial",
237235
"sphere_reg_fsLR",
238-
"thickness",
236+
"midthickness_fsLR",
237+
"cortex_mask",
239238
"anat_ribbon",
240239
# Fieldmap registration
241240
"fmap",
@@ -580,8 +579,9 @@ def init_bold_wf(
580579
("white", "inputnode.white"),
581580
("pial", "inputnode.pial"),
582581
("midthickness", "inputnode.midthickness"),
583-
("thickness", "inputnode.thickness"),
582+
("midthickness_fsLR", "inputnode.midthickness_fsLR"),
584583
("sphere_reg_fsLR", "inputnode.sphere_reg_fsLR"),
584+
("cortex_mask", "inputnode.cortex_mask"),
585585
("anat_ribbon", "inputnode.anat_ribbon"),
586586
]),
587587
(bold_anat_wf, bold_fsLR_resampling_wf, [

fmriprep/workflows/bold/resampling.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -587,27 +587,28 @@ def init_bold_fsLR_resampling_wf(
587587
niu.IdentityInterface(
588588
fields=[
589589
'bold_file',
590+
'anat_ribbon',
590591
'white',
591592
'pial',
592593
'midthickness',
593-
'thickness',
594+
'midthickness_fsLR',
594595
'sphere_reg_fsLR',
595-
'anat_ribbon',
596+
'cortex_mask',
596597
]
597598
),
598599
name='inputnode',
599600
)
600601

601-
itersource = pe.Node(
602+
hemisource = pe.Node(
602603
niu.IdentityInterface(fields=['hemi']),
603-
name='itersource',
604+
name='hemisource',
604605
iterables=[('hemi', ['L', 'R'])],
605606
)
606607

607608
joinnode = pe.JoinNode(
608609
niu.IdentityInterface(fields=['bold_fsLR']),
609610
name='joinnode',
610-
joinsource='itersource',
611+
joinsource='hemisource',
611612
)
612613

613614
outputnode = pe.Node(
@@ -622,9 +623,10 @@ def init_bold_fsLR_resampling_wf(
622623
"white",
623624
"pial",
624625
"midthickness",
625-
"thickness",
626-
"sphere_reg",
626+
'midthickness_fsLR',
627+
"sphere_reg_fsLR",
627628
"template_sphere",
629+
'cortex_mask',
628630
"template_roi",
629631
],
630632
keys=["L", "R"],
@@ -648,20 +650,6 @@ def init_bold_fsLR_resampling_wf(
648650
str(atlases / 'R.atlasroi.32k_fs_LR.shape.gii'),
649651
]
650652

651-
# Reimplements lines 282-290 of FreeSurfer2CaretConvertAndRegisterNonlinear.sh
652-
initial_roi = pe.Node(CreateROI(), name="initial_roi", mem_gb=DEFAULT_MEMORY_MIN_GB)
653-
654-
# Lines 291-292
655-
fill_holes = pe.Node(MetricFillHoles(), name="fill_holes", mem_gb=DEFAULT_MEMORY_MIN_GB)
656-
native_roi = pe.Node(MetricRemoveIslands(), name="native_roi", mem_gb=DEFAULT_MEMORY_MIN_GB)
657-
658-
# Line 393 of FreeSurfer2CaretConvertAndRegisterNonlinear.sh
659-
downsampled_midthickness = pe.Node(
660-
SurfaceResample(method='BARYCENTRIC'),
661-
name="downsampled_midthickness",
662-
mem_gb=DEFAULT_MEMORY_MIN_GB,
663-
)
664-
665653
# RibbonVolumeToSurfaceMapping.sh
666654
# Line 85 thru ...
667655
volume_to_surface = pe.Node(
@@ -689,23 +677,11 @@ def init_bold_fsLR_resampling_wf(
689677
('white', 'white'),
690678
('pial', 'pial'),
691679
('midthickness', 'midthickness'),
692-
('thickness', 'thickness'),
693-
('sphere_reg_fsLR', 'sphere_reg'),
694-
]),
695-
(itersource, select_surfaces, [('hemi', 'key')]),
696-
# Native ROI file from thickness
697-
(itersource, initial_roi, [('hemi', 'hemisphere')]),
698-
(select_surfaces, initial_roi, [('thickness', 'thickness_file')]),
699-
(select_surfaces, fill_holes, [('midthickness', 'surface_file')]),
700-
(select_surfaces, native_roi, [('midthickness', 'surface_file')]),
701-
(initial_roi, fill_holes, [('roi_file', 'metric_file')]),
702-
(fill_holes, native_roi, [('out_file', 'metric_file')]),
703-
# Downsample midthickness to fsLR density
704-
(select_surfaces, downsampled_midthickness, [
705-
('midthickness', 'surface_in'),
706-
('sphere_reg', 'current_sphere'),
707-
('template_sphere', 'new_sphere'),
680+
('midthickness_fsLR', 'midthickness_fsLR'),
681+
('sphere_reg_fsLR', 'sphere_reg_fsLR'),
682+
('cortex_mask', 'cortex_mask'),
708683
]),
684+
(hemisource, select_surfaces, [('hemi', 'key')]),
709685
# Resample BOLD to native surface, dilate and mask
710686
(inputnode, volume_to_surface, [
711687
('bold_file', 'volume_file'),
@@ -716,17 +692,17 @@ def init_bold_fsLR_resampling_wf(
716692
('pial', 'outer_surface'),
717693
]),
718694
(select_surfaces, metric_dilate, [('midthickness', 'surf_file')]),
695+
(select_surfaces, mask_native, [('cortex_mask', 'mask')]),
719696
(volume_to_surface, metric_dilate, [('out_file', 'in_file')]),
720-
(native_roi, mask_native, [('out_file', 'mask')]),
721697
(metric_dilate, mask_native, [('out_file', 'in_file')]),
722698
# Resample BOLD to fsLR and mask
723699
(select_surfaces, resample_to_fsLR, [
724-
('sphere_reg', 'current_sphere'),
700+
('sphere_reg_fsLR', 'current_sphere'),
725701
('template_sphere', 'new_sphere'),
726702
('midthickness', 'current_area'),
703+
('midthickness_fsLR', 'new_area'),
704+
('cortex_mask', 'roi_metric'),
727705
]),
728-
(downsampled_midthickness, resample_to_fsLR, [('surface_out', 'new_area')]),
729-
(native_roi, resample_to_fsLR, [('out_file', 'roi_metric')]),
730706
(mask_native, resample_to_fsLR, [('out_file', 'in_file')]),
731707
(select_surfaces, mask_fsLR, [('template_roi', 'mask')]),
732708
(resample_to_fsLR, mask_fsLR, [('out_file', 'in_file')]),

0 commit comments

Comments
 (0)