Skip to content

Commit 834bdf6

Browse files
feilongmgxd
authored andcommitted
feat: Resample to surface template spaces using the Connectome Workbench.
1 parent 2c140ea commit 834bdf6

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,115 @@ def init_bold_wf(
494494
]),
495495
]) # fmt:skip
496496

497+
surf_std = spaces.get_standard(dim=(2,))
498+
if surf_std: # Probably ensure reconall and msmsulc are run
499+
workflow.__postdesc__ += """\
500+
Non-gridded (surface) resamplings were performed using the Connectome
501+
Workbench.
502+
"""
503+
config.loggers.workflow.debug('Creating BOLD surface workbench resampling workflow.')
504+
from smriprep.workflows.surfaces import init_resample_surfaces_wb_wf
505+
506+
from .resampling import (
507+
init_goodvoxels_bold_mask_wf,
508+
init_wb_surf_surf_wf,
509+
init_wb_vol_surf_wf,
510+
)
511+
512+
wb_vol_surf_wf = init_wb_vol_surf_wf(
513+
name='wb_vol_surf_wf',
514+
omp_nthreads=omp_nthreads,
515+
mem_gb=mem_gb['resampled'],
516+
dilate=True,
517+
)
518+
workflow.connect([
519+
(inputnode, wb_vol_surf_wf,[
520+
('white', 'inputnode.white'),
521+
('pial', 'inputnode.pial'),
522+
('midthickness', 'inputnode.midthickness'),
523+
]),
524+
(bold_anat_wf, wb_vol_surf_wf, [
525+
('outputnode.bold_file', 'inputnode.bold_file'),
526+
]),
527+
]) # fmt:skip
528+
529+
if config.workflow.project_goodvoxels:
530+
goodvoxels_bold_mask_wf = init_goodvoxels_bold_mask_wf(mem_gb['resampled'])
531+
532+
workflow.connect([
533+
(inputnode, goodvoxels_bold_mask_wf, [('anat_ribbon', 'inputnode.anat_ribbon')]),
534+
(bold_anat_wf, goodvoxels_bold_mask_wf, [
535+
('outputnode.bold_file', 'inputnode.bold_file'),
536+
]),
537+
(goodvoxels_bold_mask_wf, wb_vol_surf_wf, [
538+
('outputnode.goodvoxels_mask', 'inputnode.volume_roi'),
539+
]),
540+
]) # fmt:skip
541+
workflow.__desc__ += """\
542+
A "goodvoxels" mask was applied during volume-to-surface sampling, excluding
543+
voxels whose time-series have a locally high coefficient of variation.
544+
"""
545+
546+
for ref_ in surf_std:
547+
space, den = ref_.space, ref_.spec['den']
548+
549+
resample_surfaces_wb_wf = init_resample_surfaces_wb_wf(
550+
name=f'resample_surfaces_wb_wf_{space}_{den}',
551+
surfaces=['midthickness'],
552+
space=space,
553+
density=den,
554+
)
555+
556+
wb_surf_surf_wf = init_wb_surf_surf_wf(
557+
space=space,
558+
density=den,
559+
name=f'wb_surf_surf_wf_{space}_{den}',
560+
omp_nthreads=omp_nthreads,
561+
mem_gb=mem_gb['resampled'],
562+
)
563+
564+
ds_bold_surf_wb = pe.Node(
565+
DerivativesDataSink(
566+
base_directory=fmriprep_dir,
567+
hemi=['L', 'R'],
568+
dismiss_entities=dismiss_echo(),
569+
space=space,
570+
density=den,
571+
suffix='bold',
572+
# compress=False, # not sure if needed for gii.
573+
TaskName=all_metadata[0].get('TaskName'),
574+
extension='.func.gii',
575+
**prepare_timing_parameters(all_metadata[0]),
576+
),
577+
iterfield=('in_file', 'hemi'),
578+
name=f'ds_bold_surf_wb_{space}_{den}',
579+
run_without_submitting=True,
580+
)
581+
ds_bold_surf_wb.inputs.source_file = bold_file
582+
583+
workflow.connect([
584+
(inputnode, resample_surfaces_wb_wf, [
585+
('midthickness', 'inputnode.midthickness'),
586+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
587+
]),
588+
(wb_vol_surf_wf, wb_surf_surf_wf, [
589+
('outputnode.bold_fsnative', 'inputnode.bold_fsnative'),
590+
]),
591+
(inputnode, wb_surf_surf_wf, [
592+
('midthickness', 'inputnode.midthickness'),
593+
# # TODO: check inputnode.midthickness_resampled
594+
# ('midthickness_resampled', 'inputnode.midthickness_resampled'),
595+
('sphere_reg_fsLR', 'inputnode.sphere_reg_fsLR'),
596+
]),
597+
(resample_surfaces_wb_wf, wb_surf_surf_wf, [
598+
('outputnode.midthickness_resampled', 'inputnode.midthickness_resampled'),
599+
]),
600+
(wb_surf_surf_wf, ds_bold_surf_wb, [
601+
('outputnode.bold_resampled', 'in_file'),
602+
# TODO: json metadata?
603+
]),
604+
]) # fmt:skip
605+
497606
if config.workflow.run_reconall and freesurfer_spaces:
498607
workflow.__postdesc__ += """\
499608
Non-gridded (surface) resamplings were performed using `mri_vol2surf`

0 commit comments

Comments
 (0)