Skip to content

Commit 19853a1

Browse files
committed
rf: Reconstruct motion confounds from minimal derivatives
1 parent ad88ffc commit 19853a1

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

fmriprep/workflows/bold/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,8 @@ 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.hmc_boldref', 'inputnode.hmc_boldref'),
677+
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
677678
('outputnode.rmsd_file', 'inputnode.rmsd_file'),
678679
('outputnode.boldref2anat_xfm', 'inputnode.boldref2anat_xfm'),
679680
('outputnode.dummy_scans', 'inputnode.skip_vols'),

fmriprep/workflows/bold/confounds.py

Lines changed: 15 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,8 @@ def init_bold_confs_wf(
221223
fields=[
222224
'bold',
223225
'bold_mask',
224-
'movpar_file',
226+
'hmc_boldref',
227+
'motion_xfm',
225228
'rmsd_file',
226229
'skip_vols',
227230
't1w_mask',
@@ -262,8 +265,11 @@ def init_bold_confs_wf(
262265
mem_gb=mem_gb,
263266
)
264267

268+
# Motion parameters
269+
motion_params = pe.Node(FSLMotionParams(), name='motion_params')
270+
265271
# Frame displacement
266-
fdisp = pe.Node(nac.FramewiseDisplacement(parameter_source='SPM'), name='fdisp', mem_gb=mem_gb)
272+
fdisp = pe.Node(FramewiseDisplacement(), name='fdisp', mem_gb=mem_gb)
267273

268274
# Generate aCompCor probseg maps
269275
acc_masks = pe.Node(aCompCorMasks(is_aseg=freesurfer), name='acc_masks')
@@ -367,12 +373,6 @@ def init_bold_confs_wf(
367373
mem_gb=0.01,
368374
run_without_submitting=True,
369375
)
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-
)
376376
add_rmsd_header = pe.Node(
377377
AddTSVHeader(columns=['rmsd']),
378378
name='add_rmsd_header',
@@ -518,12 +518,13 @@ def _select_cols(table):
518518
if not col.startswith(('a_comp_cor_', 't_comp_cor_', 'std_dvars'))
519519
]
520520

521-
# fmt:off
522521
workflow.connect([
523522
# connect inputnode to each non-anatomical confound node
524523
(inputnode, dvars, [('bold', 'in_file'),
525524
('bold_mask', 'in_mask')]),
526-
(inputnode, fdisp, [('movpar_file', 'in_file')]),
525+
(inputnode, motion_params, [('motion_xfm', 'xfm_file'),
526+
('hmc_boldref', 'boldref_file')]),
527+
(motion_params, fdisp, [('out_file', 'in_file')]),
527528
# Brain mask
528529
(inputnode, t1w_mask_tfm, [('t1w_mask', 'input_image'),
529530
('bold_mask', 'reference_image'),
@@ -566,7 +567,6 @@ def _select_cols(table):
566567
(merge_rois, signals, [('out', 'label_files')]),
567568

568569
# Collate computed confounds together
569-
(inputnode, add_motion_headers, [('movpar_file', 'in_file')]),
570570
(inputnode, add_rmsd_header, [('rmsd_file', 'in_file')]),
571571
(dvars, add_dvars_header, [('out_nstd', 'in_file')]),
572572
(dvars, add_std_dvars_header, [('out_std', 'in_file')]),
@@ -576,7 +576,7 @@ def _select_cols(table):
576576
('pre_filter_file', 'cos_basis')]),
577577
(rename_acompcor, concat, [('components_file', 'acompcor')]),
578578
(crowncompcor, concat, [('components_file', 'crowncompcor')]),
579-
(add_motion_headers, concat, [('out_file', 'motion')]),
579+
(motion_params, concat, [('out_file', 'motion')]),
580580
(add_rmsd_header, concat, [('out_file', 'rmsd')]),
581581
(add_dvars_header, concat, [('out_file', 'dvars')]),
582582
(add_std_dvars_header, concat, [('out_file', 'std_dvars')]),
@@ -617,8 +617,7 @@ def _select_cols(table):
617617
(concat, conf_corr_plot, [('confounds_file', 'confounds_file'),
618618
(('confounds_file', _select_cols), 'columns')]),
619619
(conf_corr_plot, ds_report_conf_corr, [('out_file', 'in_file')]),
620-
])
621-
# fmt: on
620+
]) # fmt: skip
622621

623622
return workflow
624623

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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
from nipype.interfaces import utility as niu
3333
from nipype.pipeline import engine as pe
3434

35-
from ...config import DEFAULT_MEMORY_MIN_GB
36-
3735

3836
def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'):
3937
"""
@@ -73,14 +71,11 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
7371
-------
7472
xforms
7573
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)
7874
rmsd_file
7975
Root mean squared deviation as measured by ``fsl_motion_outliers`` [Jenkinson2002]_.
8076
8177
"""
8278
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
83-
from niworkflows.interfaces.confounds import NormalizeMotionParams
8479
from niworkflows.interfaces.itk import MCFLIRT2ITK
8580

8681
workflow = Workflow(name=name)
@@ -94,9 +89,7 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
9489
inputnode = pe.Node(
9590
niu.IdentityInterface(fields=['bold_file', 'raw_ref_image']), name='inputnode'
9691
)
97-
outputnode = pe.Node(
98-
niu.IdentityInterface(fields=['xforms', 'movpar_file', 'rmsd_file']), name='outputnode'
99-
)
92+
outputnode = pe.Node(niu.IdentityInterface(fields=['xforms', 'rmsd_file']), name='outputnode')
10093

10194
# Head motion correction (hmc)
10295
mcflirt = pe.Node(
@@ -107,25 +100,17 @@ def init_bold_hmc_wf(mem_gb: float, omp_nthreads: int, name: str = 'bold_hmc_wf'
107100

108101
fsl2itk = pe.Node(MCFLIRT2ITK(), name='fsl2itk', mem_gb=0.05, n_procs=omp_nthreads)
109102

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

117-
# fmt:off
118106
workflow.connect([
119107
(inputnode, mcflirt, [('raw_ref_image', 'ref_file'),
120108
('bold_file', 'in_file')]),
121109
(inputnode, fsl2itk, [('raw_ref_image', 'in_source'),
122110
('raw_ref_image', 'in_reference')]),
123111
(mcflirt, fsl2itk, [('mat_file', 'in_files')]),
124-
(mcflirt, normalize_motion, [('par_file', 'in_file')]),
125112
(mcflirt, outputnode, [(('rms_files', _pick_rel), 'rmsd_file')]),
126113
(fsl2itk, outputnode, [('out_file', 'xforms')]),
127-
(normalize_motion, outputnode, [('out_file', 'movpar_file')]),
128-
])
129-
# fmt:on
114+
]) # fmt:skip
130115

131116
return workflow

0 commit comments

Comments
 (0)