Skip to content

Commit 73b2f03

Browse files
committed
FIX: fix petref to report connection and add test
1 parent 4f8d8ef commit 73b2f03

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

fmriprep/workflows/pet/confounds.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,6 @@ def init_pet_confs_wf(
350350
mem_gb=DEFAULT_MEMORY_MIN_GB,
351351
)
352352

353-
def _last(inlist):
354-
return inlist[-1]
355-
356-
def _select_cols(table):
357-
import pandas as pd
358-
359-
return [
360-
col
361-
for col in pd.read_table(table, nrows=2).columns
362-
if not col.startswith(('a_comp_cor_', 't_comp_cor_', 'std_dvars'))
363-
]
364-
365353
workflow.connect([
366354
# connect inputnode to each non-anatomical confound node
367355
(inputnode, dvars, [('pet', 'in_file'),
@@ -619,3 +607,20 @@ def _get_zooms(in_file):
619607
import nibabel as nb
620608

621609
return tuple(nb.load(in_file).header.get_zooms()[:3])
610+
611+
612+
def _last(inlist):
613+
"""Return the last element of a list."""
614+
615+
return inlist[-1]
616+
617+
618+
def _select_cols(table):
619+
"""Return confound columns excluding a/tCompCor and std_dvars."""
620+
import pandas as pd
621+
622+
return [
623+
col
624+
for col in pd.read_table(table, nrows=2).columns
625+
if not col.startswith(("a_comp_cor_", "t_comp_cor_", "std_dvars"))
626+
]

fmriprep/workflows/pet/fit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def init_pet_fit_wf(
228228
('subjects_dir', 'inputnode.subjects_dir'),
229229
('subject_id', 'inputnode.subject_id'),
230230
]),
231+
(petref_buffer, func_fit_reports_wf, [('petref', 'inputnode.petref')]),
231232
(outputnode, func_fit_reports_wf, [
232233
('pet_mask', 'inputnode.pet_mask'),
233234
('petref2anat_xfm', 'inputnode.petref2anat_xfm'),

fmriprep/workflows/pet/tests/test_fit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,17 @@ def test_pet_fit_mask_connections(bids_root: Path, tmp_path: Path):
154154

155155
ds_edge = wf._graph.get_edge_data(merge_mask, wf.get_node('ds_petmask_wf'))
156156
assert ('out', 'inputnode.petmask') in ds_edge['connect']
157+
158+
159+
def test_petref_report_connections(bids_root: Path, tmp_path: Path):
160+
"""Ensure the PET reference is passed to the reports workflow."""
161+
pet_file = str(bids_root / 'sub-01' / 'pet' / 'sub-01_task-rest_run-1_pet.nii.gz')
162+
img = nb.Nifti1Image(np.zeros((2, 2, 2, 1)), np.eye(4))
163+
img.to_filename(pet_file)
164+
165+
with mock_config(bids_dir=bids_root):
166+
wf = init_pet_fit_wf(pet_file=pet_file, precomputed={}, omp_nthreads=1)
167+
168+
petref_buffer = wf.get_node('petref_buffer')
169+
edge = wf._graph.get_edge_data(petref_buffer, wf.get_node('func_fit_reports_wf'))
170+
assert ('petref', 'inputnode.petref') in edge['connect']

0 commit comments

Comments
 (0)