Skip to content

Commit 85f725c

Browse files
committed
rf: Reconstruct motion confounds from minimal derivatives
1 parent 607c8e9 commit 85f725c

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def init_bold_wf(
673673
]),
674674
(bold_fit_wf, bold_confounds_wf, [
675675
('outputnode.bold_mask', 'inputnode.bold_mask'),
676-
('outputnode.movpar_file', 'inputnode.movpar_file'),
676+
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
677677
('outputnode.rmsd_file', 'inputnode.rmsd_file'),
678678
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
679679
('outputnode.dummy_scans', 'inputnode.skip_vols'),

fmriprep/workflows/bold/confounds.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
from ...interfaces.confounds import (
3939
FilterDropped,
4040
FMRISummary,
41+
FramewiseDisplacement,
42+
FSLMotionParams,
4143
GatherConfounds,
4244
RenameACompCor,
4345
)
@@ -120,8 +122,8 @@ def init_bold_confs_wf(
120122
when available.
121123
bold_mask
122124
BOLD series mask
123-
movpar_file
124-
SPM-formatted motion parameters file
125+
motion_xfm
126+
ITK-formatted head motion transforms
125127
rmsd_file
126128
Root mean squared deviation as measured by ``fsl_motion_outliers`` [Jenkinson2002]_.
127129
skip_vols
@@ -221,7 +223,7 @@ def init_bold_confs_wf(
221223
fields=[
222224
'bold',
223225
'bold_mask',
224-
'movpar_file',
226+
'motion_xfm',
225227
'rmsd_file',
226228
'skip_vols',
227229
't1w_mask',
@@ -262,8 +264,11 @@ def init_bold_confs_wf(
262264
mem_gb=mem_gb,
263265
)
264266

267+
# Motion parameters
268+
motion_params = pe.Node(FSLMotionParams(), name='motion_params')
269+
265270
# Frame displacement
266-
fdisp = pe.Node(nac.FramewiseDisplacement(parameter_source='SPM'), name='fdisp', mem_gb=mem_gb)
271+
fdisp = pe.Node(FramewiseDisplacement(), name='fdisp', mem_gb=mem_gb)
267272

268273
# Generate aCompCor probseg maps
269274
acc_masks = pe.Node(aCompCorMasks(is_aseg=freesurfer), name='acc_masks')
@@ -367,12 +372,6 @@ def init_bold_confs_wf(
367372
mem_gb=0.01,
368373
run_without_submitting=True,
369374
)
370-
add_motion_headers = pe.Node(
371-
AddTSVHeader(columns=['trans_x', 'trans_y', 'trans_z', 'rot_x', 'rot_y', 'rot_z']),
372-
name='add_motion_headers',
373-
mem_gb=0.01,
374-
run_without_submitting=True,
375-
)
376375
add_rmsd_header = pe.Node(
377376
AddTSVHeader(columns=['rmsd']),
378377
name='add_rmsd_header',
@@ -518,12 +517,13 @@ def _select_cols(table):
518517
if not col.startswith(('a_comp_cor_', 't_comp_cor_', 'std_dvars'))
519518
]
520519

521-
# fmt:off
522520
workflow.connect([
523521
# connect inputnode to each non-anatomical confound node
524522
(inputnode, dvars, [('bold', 'in_file'),
525523
('bold_mask', 'in_mask')]),
526-
(inputnode, fdisp, [('movpar_file', 'in_file')]),
524+
(inputnode, motion_params, [('motion_xfm', 'xfm_file'),
525+
('bold_mask', 'boldref_file')]),
526+
(motion_params, fdisp, [('out_file', 'in_file')]),
527527
# Brain mask
528528
(inputnode, t1w_mask_tfm, [('t1w_mask', 'input_image'),
529529
('bold_mask', 'reference_image'),
@@ -566,7 +566,6 @@ def _select_cols(table):
566566
(merge_rois, signals, [('out', 'label_files')]),
567567

568568
# Collate computed confounds together
569-
(inputnode, add_motion_headers, [('movpar_file', 'in_file')]),
570569
(inputnode, add_rmsd_header, [('rmsd_file', 'in_file')]),
571570
(dvars, add_dvars_header, [('out_nstd', 'in_file')]),
572571
(dvars, add_std_dvars_header, [('out_std', 'in_file')]),
@@ -576,7 +575,7 @@ def _select_cols(table):
576575
('pre_filter_file', 'cos_basis')]),
577576
(rename_acompcor, concat, [('components_file', 'acompcor')]),
578577
(crowncompcor, concat, [('components_file', 'crowncompcor')]),
579-
(add_motion_headers, concat, [('out_file', 'motion')]),
578+
(motion_params, concat, [('out_file', 'motion')]),
580579
(add_rmsd_header, concat, [('out_file', 'rmsd')]),
581580
(add_dvars_header, concat, [('out_file', 'dvars')]),
582581
(add_std_dvars_header, concat, [('out_file', 'std_dvars')]),
@@ -617,8 +616,7 @@ def _select_cols(table):
617616
(concat, conf_corr_plot, [('confounds_file', 'confounds_file'),
618617
(('confounds_file', _select_cols), 'columns')]),
619618
(conf_corr_plot, ds_report_conf_corr, [('out_file', 'in_file')]),
620-
])
621-
# fmt: on
619+
]) # fmt: skip
622620

623621
return workflow
624622

fmriprep/workflows/bold/fit.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ def init_bold_fit_wf(
178178
boldref2fmap_xfm
179179
Affine transform mapping from BOLD reference space to the fieldmap
180180
space, if applicable.
181-
movpar_file
182-
MCFLIRT motion parameters, normalized to SPM format (X, Y, Z, Rx, Ry, Rz)
183181
rmsd_file
184182
Root mean squared deviation as measured by ``fsl_motion_outliers`` [Jenkinson2002]_.
185183
dummy_scans
@@ -287,7 +285,6 @@ def init_bold_fit_wf(
287285
'motion_xfm',
288286
'boldref2anat_xfm',
289287
'boldref2fmap_xfm',
290-
'movpar_file',
291288
'rmsd_file',
292289
],
293290
),
@@ -303,7 +300,7 @@ def init_bold_fit_wf(
303300
)
304301
fmapref_buffer = pe.Node(niu.Function(function=_select_ref), name='fmapref_buffer')
305302
hmc_buffer = pe.Node(
306-
niu.IdentityInterface(fields=['hmc_xforms', 'movpar_file', 'rmsd_file']), name='hmc_buffer'
303+
niu.IdentityInterface(fields=['hmc_xforms', 'rmsd_file']), name='hmc_buffer'
307304
)
308305
fmapreg_buffer = pe.Node(
309306
niu.IdentityInterface(fields=['boldref2fmap_xfm']), name='fmapreg_buffer'
@@ -357,7 +354,6 @@ def init_bold_fit_wf(
357354
(fmapreg_buffer, outputnode, [('boldref2fmap_xfm', 'boldref2fmap_xfm')]),
358355
(hmc_buffer, outputnode, [
359356
('hmc_xforms', 'motion_xfm'),
360-
('movpar_file', 'movpar_file'),
361357
('rmsd_file', 'rmsd_file'),
362358
]),
363359
(inputnode, func_fit_reports_wf, [
@@ -449,7 +445,6 @@ def init_bold_fit_wf(
449445
]),
450446
(bold_hmc_wf, ds_hmc_wf, [('outputnode.xforms', 'inputnode.xforms')]),
451447
(bold_hmc_wf, hmc_buffer, [
452-
('outputnode.movpar_file', 'movpar_file'),
453448
('outputnode.rmsd_file', 'rmsd_file'),
454449
]),
455450
(ds_hmc_wf, hmc_buffer, [('outputnode.xforms', 'hmc_xforms')]),

fmriprep/workflows/bold/hmc.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
7373
-------
7474
xforms
7575
ITKTransform file aligning each volume to ``ref_image``
76-
movpar_file
77-
MCFLIRT motion parameters, normalized to SPM format (X, Y, Z, Rx, Ry, Rz)
7876
rmsd_file
7977
Root mean squared deviation as measured by ``fsl_motion_outliers`` [Jenkinson2002]_.
8078
8179
"""
8280
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
83-
from niworkflows.interfaces.confounds import NormalizeMotionParams
8481
from niworkflows.interfaces.itk import MCFLIRT2ITK
8582

8683
workflow = Workflow(name=name)
@@ -95,7 +92,7 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
9592
niu.IdentityInterface(fields=['bold_file', 'raw_ref_image']), name='inputnode'
9693
)
9794
outputnode = pe.Node(
98-
niu.IdentityInterface(fields=['xforms', 'movpar_file', 'rmsd_file']), name='outputnode'
95+
niu.IdentityInterface(fields=['xforms', 'rmsd_file']), name='outputnode'
9996
)
10097

10198
# Head motion correction (hmc)
@@ -107,25 +104,17 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
107104

108105
fsl2itk = pe.Node(MCFLIRT2ITK(), name='fsl2itk', mem_gb=0.05, n_procs=omp_nthreads)
109106

110-
normalize_motion = pe.Node(
111-
NormalizeMotionParams(format='FSL'), name='normalize_motion', mem_gb=DEFAULT_MEMORY_MIN_GB
112-
)
113-
114107
def _pick_rel(rms_files):
115108
return rms_files[-1]
116109

117-
# fmt:off
118110
workflow.connect([
119111
(inputnode, mcflirt, [('raw_ref_image', 'ref_file'),
120112
('bold_file', 'in_file')]),
121113
(inputnode, fsl2itk, [('raw_ref_image', 'in_source'),
122114
('raw_ref_image', 'in_reference')]),
123115
(mcflirt, fsl2itk, [('mat_file', 'in_files')]),
124-
(mcflirt, normalize_motion, [('par_file', 'in_file')]),
125116
(mcflirt, outputnode, [(('rms_files', _pick_rel), 'rmsd_file')]),
126117
(fsl2itk, outputnode, [('out_file', 'xforms')]),
127-
(normalize_motion, outputnode, [('out_file', 'movpar_file')]),
128-
])
129-
# fmt:on
118+
]) # fmt:skip
130119

131120
return workflow

0 commit comments

Comments
 (0)