Skip to content

Commit 6a6298c

Browse files
authored
Merge pull request #4 from mnoergaard/main
Refactor of fMRIPrep to PETPrep
2 parents 050dbcd + 94e2dea commit 6a6298c

File tree

12 files changed

+152
-384
lines changed

12 files changed

+152
-384
lines changed

fmriprep/cli/parser.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def _slice_time_ref(value, parser):
145145
raise parser.error(f'Slice time reference must be in range 0-1. Received {value}.')
146146
return value
147147

148+
def _reference_frame(value, parser):
149+
if value == 'average':
150+
return 'average'
151+
try:
152+
return int(value)
153+
except ValueError:
154+
raise parser.error(
155+
"Reference frame must be an integer index or 'average'."
156+
) from None
157+
148158
verstr = f'PETPrep v{config.environment.version}'
149159
currentv = Version(config.environment.version)
150160
is_release = not any((currentv.is_devrelease, currentv.is_prerelease, currentv.is_postrelease))
@@ -158,6 +168,7 @@ def _slice_time_ref(value, parser):
158168
IsFile = partial(_is_file, parser=parser)
159169
PositiveInt = partial(_min_one, parser=parser)
160170
BIDSFilter = partial(_bids_filter, parser=parser)
171+
ReferenceFrame = partial(_reference_frame, parser=parser)
161172

162173
# Arguments as specified by BIDS-Apps
163174
# required, positional arguments
@@ -377,12 +388,15 @@ def _slice_time_ref(value, parser):
377388
help='Deprecated - use `--force no-bbr` instead.',
378389
)
379390
g_conf.add_argument(
380-
'--dummy-scans',
381-
required=False,
391+
'--reference-frame',
382392
action='store',
383-
default=None,
384-
type=int,
385-
help='Number of nonsteady-state volumes. Overrides automatic detection.',
393+
dest='reference_frame',
394+
type=ReferenceFrame,
395+
default='average',
396+
help=(
397+
"Reference frame index (0-based) for PET preprocessing. "
398+
"Use 'average' to compute the standard averaged reference."
399+
),
386400
)
387401
g_conf.add_argument(
388402
'--random-seed',

fmriprep/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,6 @@ class workflow(_Config):
556556
"""Initial transform for PET-to-anatomical registration."""
557557
cifti_output = None
558558
"""Generate HCP Grayordinates, accepts either ``'91k'`` (default) or ``'170k'``."""
559-
dummy_scans = None
560-
"""Set a number of initial scans to be considered nonsteady states."""
561559
hires = None
562560
"""Run FreeSurfer ``recon-all`` with the ``-hires`` flag."""
563561
fs_no_resume = None
@@ -594,7 +592,10 @@ class workflow(_Config):
594592
spaces = None
595593
"""Keeps the :py:class:`~niworkflows.utils.spaces.SpatialReferences`
596594
instance keeping standard and nonstandard spaces."""
595+
reference_frame: int | str | None = None
596+
"""Selected frame index for PET reference generation.
597597
598+
``None`` or ``'average'`` retains the current averaging behavior."""
598599

599600
class loggers:
600601
"""Keep loggers easily accessible (see :py:func:`init`)."""

fmriprep/interfaces/confounds.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,6 @@ class GatherConfoundsInputSpec(BaseInterfaceInputSpec):
336336
std_dvars = File(exists=True, desc='file containing standardized DVARS')
337337
fd = File(exists=True, desc='input framewise displacement')
338338
rmsd = File(exists=True, desc='input RMS framewise displacement')
339-
tcompcor = File(exists=True, desc='input tCompCorr')
340-
acompcor = File(exists=True, desc='input aCompCorr')
341-
crowncompcor = File(exists=True, desc='input crown-based regressors')
342339
cos_basis = File(exists=True, desc='input cosine basis')
343340
motion = File(exists=True, desc='input motion parameters')
344341

@@ -379,9 +376,6 @@ def _run_interface(self, runtime):
379376
std_dvars=self.inputs.std_dvars,
380377
fdisp=self.inputs.fd,
381378
rmsd=self.inputs.rmsd,
382-
tcompcor=self.inputs.tcompcor,
383-
acompcor=self.inputs.acompcor,
384-
crowncompcor=self.inputs.crowncompcor,
385379
cos_basis=self.inputs.cos_basis,
386380
motion=self.inputs.motion,
387381
newpath=runtime.cwd,
@@ -397,9 +391,6 @@ def _gather_confounds(
397391
std_dvars=None,
398392
fdisp=None,
399393
rmsd=None,
400-
tcompcor=None,
401-
acompcor=None,
402-
crowncompcor=None,
403394
cos_basis=None,
404395
motion=None,
405396
newpath=None,
@@ -449,9 +440,6 @@ def _adjust_indices(left_df, right_df):
449440
(dvars, 'DVARS'),
450441
(fdisp, 'Framewise displacement'),
451442
(rmsd, 'Framewise displacement (RMS)'),
452-
(tcompcor, 'tCompCor'),
453-
(acompcor, 'aCompCor'),
454-
(crowncompcor, 'crownCompCor'),
455443
(cos_basis, 'Cosine basis'),
456444
(motion, 'Motion parameters'),
457445
):

fmriprep/interfaces/reports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ def _generate_segment(self):
151151
t2w_seg = f'(+ {len(self.inputs.t2w):d} T2-weighted)'
152152

153153
# Add list of tasks with number of runs
154-
pet_series = self.inputs.bold or []
154+
pet_series = self.inputs.pet or []
155155

156156
counts = Counter(
157-
BIDS_NAME.search(series).groupdict().get('task_id', 'task-<none>')[5:]
157+
(BIDS_NAME.search(series).groupdict().get('task_id') or 'task-<none>')[5:]
158158
for series in pet_series
159159
)
160160

fmriprep/interfaces/tests/test_reports.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,25 @@
5050
)
5151
def test_get_world_pedir(tmpdir, orientation, pe_dir, expected):
5252
assert get_world_pedir(orientation, pe_dir) == expected
53+
54+
55+
def test_subject_summary_handles_missing_task(tmp_path):
56+
from ..reports import SubjectSummary
57+
58+
t1w = tmp_path / 'sub-01_T1w.nii.gz'
59+
t1w.write_text('')
60+
pet1 = tmp_path / 'sub-01_task-rest_run-01_pet.nii.gz'
61+
pet1.write_text('')
62+
pet2 = tmp_path / 'sub-01_run-01_pet.nii.gz'
63+
pet2.write_text('')
64+
65+
summary = SubjectSummary(
66+
t1w=[str(t1w)],
67+
pet=[str(pet1), str(pet2)],
68+
std_spaces=[],
69+
nstd_spaces=[],
70+
)
71+
72+
segment = summary._generate_segment()
73+
assert 'Task: rest (1 run)' in segment
74+
assert 'Task: <none> (1 run)' in segment

fmriprep/workflows/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,20 @@ def init_single_subject_wf(subject_id: str):
199199
### References
200200
201201
"""
202+
from niworkflows.utils.bids import DEFAULT_BIDS_QUERIES
203+
import copy
204+
205+
queries = copy.deepcopy(DEFAULT_BIDS_QUERIES)
206+
queries['t1w'].pop('datatype', None)
202207

203208
subject_data = collect_data(
204-
config.execution.layout,
209+
config.execution.bids_dir,
205210
subject_id,
206-
task=config.execution.task_id,
207211
bids_filters=config.execution.bids_filters,
212+
queries=queries
208213
)[0]
209214

215+
210216
if 'flair' in config.workflow.ignore:
211217
subject_data['flair'] = []
212218
if 't2w' in config.workflow.ignore:

fmriprep/workflows/pet/base.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ def init_pet_wf(
543543
('outputnode.petref', 'inputnode.petref'),
544544
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
545545
('outputnode.petref2anat_xfm', 'inputnode.petref2anat_xfm'),
546-
('outputnode.dummy_scans', 'inputnode.skip_vols'),
547546
]),
548547
(pet_native_wf, pet_confounds_wf, [
549548
('outputnode.pet_native', 'inputnode.pet'),
@@ -575,7 +574,6 @@ def _last(inlist):
575574
('mni2009c2anat_xfm', 'inputnode.std2anat_xfm'),
576575
]),
577576
(pet_fit_wf, carpetplot_wf, [
578-
('outputnode.dummy_scans', 'inputnode.dummy_scans'),
579577
('outputnode.pet_mask', 'inputnode.pet_mask'),
580578
('outputnode.petref2anat_xfm', 'inputnode.petref2anat_xfm'),
581579
]),
@@ -585,7 +583,6 @@ def _last(inlist):
585583
(pet_confounds_wf, carpetplot_wf, [
586584
('outputnode.confounds_file', 'inputnode.confounds_file'),
587585
('outputnode.crown_mask', 'inputnode.crown_mask'),
588-
(('outputnode.acompcor_masks', _last), 'inputnode.acompcor_mask'),
589586
]),
590587
]) # fmt:skip
591588

0 commit comments

Comments
 (0)