Skip to content

Commit ff81887

Browse files
authored
Merge pull request #116 from nipreps/fix_ref_pvc_output
ENH: Update reference mask workflow outputs when PVC is on
2 parents 544642f + c313a80 commit ff81887

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

petprep/workflows/pet/fit.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ def init_pet_fit_wf(
400400
ds_petmask_wf.inputs.inputnode.source_files = [pet_file]
401401
workflow.connect([(merge_mask, ds_petmask_wf, [('out', 'inputnode.petmask')])])
402402

403+
pvc_method = getattr(config.workflow, 'pvc_method', None)
404+
403405
# Stage 4: Reference mask generation
404406
if config.workflow.ref_mask_name:
405407
config.loggers.workflow.info(
@@ -437,22 +439,23 @@ def init_pet_fit_wf(
437439
)
438440
pet_ref_tacs_wf.inputs.inputnode.ref_mask_name = config.workflow.ref_mask_name
439441

440-
ds_ref_tacs = pe.Node(
441-
DerivativesDataSink(
442-
base_directory=config.execution.petprep_dir,
443-
suffix='tacs',
444-
seg=config.workflow.seg,
445-
desc='preproc',
446-
ref=config.workflow.ref_mask_name,
447-
allowed_entities=('seg', 'ref'),
448-
TaskName=metadata.get('TaskName'),
449-
**timing_parameters,
450-
),
451-
name='ds_ref_tacs',
452-
run_without_submitting=True,
453-
mem_gb=config.DEFAULT_MEMORY_MIN_GB,
454-
)
455-
ds_ref_tacs.inputs.source_file = pet_file
442+
if pvc_method is None:
443+
ds_ref_tacs = pe.Node(
444+
DerivativesDataSink(
445+
base_directory=config.execution.petprep_dir,
446+
suffix='tacs',
447+
seg=config.workflow.seg,
448+
desc='preproc',
449+
ref=config.workflow.ref_mask_name,
450+
allowed_entities=('seg', 'ref'),
451+
TaskName=metadata.get('TaskName'),
452+
**timing_parameters,
453+
),
454+
name='ds_ref_tacs',
455+
run_without_submitting=True,
456+
mem_gb=config.DEFAULT_MEMORY_MIN_GB,
457+
)
458+
ds_ref_tacs.inputs.source_file = pet_file
456459

457460
workflow.connect([(inputnode, gm_select, [('t1w_tpms', 'inlist')])])
458461

@@ -534,15 +537,20 @@ def init_pet_fit_wf(
534537
('outputnode.refmask_file', 'inputnode.mask_file'),
535538
],
536539
),
537-
(
538-
pet_ref_tacs_wf,
539-
ds_ref_tacs,
540-
[
541-
('outputnode.timeseries', 'in_file'),
542-
],
543-
),
544540
]
545541
)
542+
if pvc_method is None:
543+
workflow.connect(
544+
[
545+
(
546+
pet_ref_tacs_wf,
547+
ds_ref_tacs,
548+
[
549+
('outputnode.timeseries', 'in_file'),
550+
],
551+
),
552+
]
553+
)
546554
else:
547555
config.loggers.workflow.info('PET Stage 4: Reference mask generation skipped')
548556

petprep/workflows/pet/tests/test_fit.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ def test_petref_report_connections(bids_root: Path, tmp_path: Path):
191191
assert ('petref', 'inputnode.petref') in edge['connect']
192192

193193

194-
def test_refmask_report_connections(bids_root: Path, tmp_path: Path):
194+
@pytest.mark.parametrize('pvc_method', [None, 'gtm'])
195+
def test_refmask_report_connections(bids_root: Path, tmp_path: Path, pvc_method):
195196
"""Ensure the reference mask report is passed to the reports workflow."""
196197
pet_series = [str(bids_root / 'sub-01' / 'pet' / 'sub-01_task-rest_run-1_pet.nii.gz')]
197198
img = nb.Nifti1Image(np.zeros((2, 2, 2, 1)), np.eye(4))
@@ -212,6 +213,8 @@ def test_refmask_report_connections(bids_root: Path, tmp_path: Path):
212213

213214
with mock_config(bids_dir=bids_root):
214215
config.workflow.ref_mask_name = 'cerebellum'
216+
if pvc_method is not None:
217+
config.workflow.pvc_method = pvc_method
215218
wf = init_pet_fit_wf(
216219
pet_series=pet_series,
217220
precomputed=precomputed,
@@ -240,13 +243,16 @@ def test_refmask_report_connections(bids_root: Path, tmp_path: Path):
240243
assert ('out', 'inputnode.gm_probseg') in edge_prob['connect']
241244

242245
assert any(name.startswith('pet_ref_tacs_wf') for name in wf.list_node_names())
243-
assert 'ds_ref_tacs' in wf.list_node_names()
244-
ds_tacs = wf.get_node('ds_ref_tacs')
245-
assert ds_tacs.inputs.ref == 'cerebellum'
246-
assert ds_tacs.inputs.seg == config.workflow.seg
247-
assert ds_tacs.inputs.desc == 'preproc'
248-
edge_tacs = wf._graph.get_edge_data(wf.get_node('pet_ref_tacs_wf'), ds_tacs)
249-
assert ('outputnode.timeseries', 'in_file') in edge_tacs['connect']
246+
if pvc_method is None:
247+
assert 'ds_ref_tacs' in wf.list_node_names()
248+
ds_tacs = wf.get_node('ds_ref_tacs')
249+
assert ds_tacs.inputs.ref == 'cerebellum'
250+
assert ds_tacs.inputs.seg == config.workflow.seg
251+
assert ds_tacs.inputs.desc == 'preproc'
252+
edge_tacs = wf._graph.get_edge_data(wf.get_node('pet_ref_tacs_wf'), ds_tacs)
253+
assert ('outputnode.timeseries', 'in_file') in edge_tacs['connect']
254+
else:
255+
assert 'ds_ref_tacs' not in wf.list_node_names()
250256

251257

252258
def test_pet_fit_stage1_inclusion(bids_root: Path, tmp_path: Path):

0 commit comments

Comments
 (0)