Skip to content

Commit e56a9eb

Browse files
committed
FIX: refmask source files and test
1 parent 22882e5 commit e56a9eb

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

petprep/workflows/pet/fit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,14 @@ def init_pet_fit_wf(
492492
ds_refmask_wf,
493493
[
494494
('segmentation', 'inputnode.segmentation'),
495+
('t1w_preproc', 'inputnode.anat_sources'),
495496
],
496497
),
497498
(
498-
petref_buffer,
499+
gm_select,
499500
ds_refmask_wf,
500501
[
501-
('pet_file', 'inputnode.source_files'),
502+
('out', 'inputnode.source_files'),
502503
],
503504
),
504505
(

petprep/workflows/pet/outputs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,14 @@ def init_ds_refmask_wf(
493493
workflow = pe.Workflow(name=name)
494494

495495
inputnode = pe.Node(
496-
niu.IdentityInterface(fields=['source_files', 'segmentation', 'refmask']),
496+
niu.IdentityInterface(
497+
fields=['source_files', 'anat_sources', 'segmentation', 'refmask']
498+
),
497499
name='inputnode',
498500
)
499501
outputnode = pe.Node(niu.IdentityInterface(fields=['refmask']), name='outputnode')
500502

501-
merge_source_files = pe.Node(niu.Merge(2), name='merge_source_files')
503+
merge_source_files = pe.Node(niu.Merge(3), name='merge_source_files')
502504

503505
sources = pe.Node(
504506
BIDSURI(
@@ -526,7 +528,8 @@ def init_ds_refmask_wf(
526528
workflow.connect([
527529
(inputnode, merge_source_files, [
528530
('source_files', 'in1'),
529-
('segmentation', 'in2'),
531+
('anat_sources', 'in2'),
532+
('segmentation', 'in3'),
530533
]),
531534
(merge_source_files, sources, [('out', 'in1')]),
532535
(inputnode, ds_refmask, [

petprep/workflows/pet/tests/test_outputs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from pathlib import Path
23

34
import nibabel as nb
@@ -52,3 +53,41 @@ def test_datasink_datatype(tmp_path: Path):
5253
assert wf.get_node('ds_pet').inputs.datatype == 'pet'
5354
assert wf.get_node('ds_ref').inputs.datatype == 'pet'
5455
assert wf.get_node('ds_mask').inputs.datatype == 'pet'
56+
57+
58+
def test_refmask_sources(tmp_path: Path):
59+
bids_dir = _prep_bids(tmp_path)
60+
out_dir = tmp_path / 'out'
61+
gm_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_label-GM_probseg.nii.gz'
62+
seg_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_desc-aparcaseg_dseg.nii.gz'
63+
refmask_file = tmp_path / 'refmask.nii.gz'
64+
65+
img = nb.Nifti1Image(np.zeros((2, 2, 2)), np.eye(4))
66+
for path in (gm_file, seg_file, refmask_file):
67+
path.parent.mkdir(parents=True, exist_ok=True)
68+
img.to_filename(path)
69+
70+
t1_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_T1w.nii.gz'
71+
72+
with mock_config(bids_dir=bids_dir):
73+
wf = init_ds_refmask_wf(output_dir=out_dir, ref_name='test')
74+
wf.base_dir = tmp_path / 'work'
75+
76+
inputnode = wf.get_node('inputnode')
77+
inputnode.inputs.source_files = str(gm_file)
78+
inputnode.inputs.anat_sources = str(t1_file)
79+
inputnode.inputs.segmentation = str(seg_file)
80+
inputnode.inputs.refmask = str(refmask_file)
81+
82+
wf.run()
83+
84+
out_files = list(out_dir.rglob('*desc-refmask*_mask.nii.gz'))
85+
assert out_files, 'Reference mask derivative was not generated'
86+
out_file = Path(out_files[0])
87+
metadata = json.loads(out_file.with_suffix('').with_suffix('.json').read_text())
88+
sources = metadata.get('Sources', [])
89+
90+
assert any('label-GM_probseg' in src for src in sources)
91+
assert any('T1w' in src for src in sources)
92+
assert any('dseg' in src for src in sources)
93+
assert all('/pet/' not in src for src in sources)

0 commit comments

Comments
 (0)