Skip to content

Commit eb00bc6

Browse files
author
Murat Bilgel
committed
feat: enable running petprep on 3D PET
1 parent 73e2851 commit eb00bc6

File tree

2 files changed

+67
-65
lines changed

2 files changed

+67
-65
lines changed

petprep/workflows/pet/base.py

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -750,81 +750,82 @@ def init_pet_wf(
750750
(pet_ref_tacs_wf, ds_ref_tacs, [('outputnode.timeseries', 'in_file')]),
751751
]) # fmt:skip
752752

753-
pet_confounds_wf = init_pet_confs_wf(
754-
mem_gb=mem_gb['largemem'],
755-
metadata=all_metadata[0],
756-
freesurfer=config.workflow.run_reconall,
757-
regressors_all_comps=config.workflow.regressors_all_comps,
758-
regressors_fd_th=config.workflow.regressors_fd_th,
759-
regressors_dvars_th=config.workflow.regressors_dvars_th,
760-
name='pet_confounds_wf',
761-
)
762-
763-
ds_confounds = pe.Node(
764-
DerivativesDataSink(
765-
base_directory=petprep_dir,
766-
desc='confounds',
767-
suffix='timeseries',
768-
),
769-
name='ds_confounds',
770-
run_without_submitting=True,
771-
mem_gb=config.DEFAULT_MEMORY_MIN_GB,
772-
)
773-
ds_confounds.inputs.source_file = pet_file
774-
775-
workflow.connect([
776-
(inputnode, pet_confounds_wf, [
777-
('t1w_tpms', 'inputnode.t1w_tpms'),
778-
('t1w_mask', 'inputnode.t1w_mask'),
779-
]),
780-
(pet_fit_wf, pet_confounds_wf, [
781-
('outputnode.pet_mask', 'inputnode.pet_mask'),
782-
('outputnode.petref', 'inputnode.petref'),
783-
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
784-
('outputnode.petref2anat_xfm', 'inputnode.petref2anat_xfm'),
785-
]),
786-
(pet_native_wf, pet_confounds_wf, [
787-
('outputnode.pet_native', 'inputnode.pet'),
788-
]),
789-
(pet_confounds_wf, ds_confounds, [
790-
('outputnode.confounds_file', 'in_file'),
791-
('outputnode.confounds_metadata', 'meta_dict'),
792-
]),
793-
]) # fmt:skip
794-
795-
if spaces.get_spaces(nonstandard=False, dim=(3,)):
796-
carpetplot_wf = init_carpetplot_wf(
797-
mem_gb=mem_gb['resampled'],
753+
if nvols > 1: # run these only if 4-D PET
754+
pet_confounds_wf = init_pet_confs_wf(
755+
mem_gb=mem_gb['largemem'],
798756
metadata=all_metadata[0],
799-
cifti_output=config.workflow.cifti_output,
800-
name='carpetplot_wf',
757+
freesurfer=config.workflow.run_reconall,
758+
regressors_all_comps=config.workflow.regressors_all_comps,
759+
regressors_fd_th=config.workflow.regressors_fd_th,
760+
regressors_dvars_th=config.workflow.regressors_dvars_th,
761+
name='pet_confounds_wf',
801762
)
802763

803-
if config.workflow.cifti_output:
804-
workflow.connect(
805-
pet_grayords_wf, 'outputnode.cifti_pet', carpetplot_wf, 'inputnode.cifti_pet',
806-
) # fmt:skip
807-
808-
def _last(inlist):
809-
return inlist[-1]
764+
ds_confounds = pe.Node(
765+
DerivativesDataSink(
766+
base_directory=petprep_dir,
767+
desc='confounds',
768+
suffix='timeseries',
769+
),
770+
name='ds_confounds',
771+
run_without_submitting=True,
772+
mem_gb=config.DEFAULT_MEMORY_MIN_GB,
773+
)
774+
ds_confounds.inputs.source_file = pet_file
810775

811776
workflow.connect([
812-
(inputnode, carpetplot_wf, [
813-
('mni2009c2anat_xfm', 'inputnode.std2anat_xfm'),
777+
(inputnode, pet_confounds_wf, [
778+
('t1w_tpms', 'inputnode.t1w_tpms'),
779+
('t1w_mask', 'inputnode.t1w_mask'),
814780
]),
815-
(pet_fit_wf, carpetplot_wf, [
781+
(pet_fit_wf, pet_confounds_wf, [
816782
('outputnode.pet_mask', 'inputnode.pet_mask'),
783+
('outputnode.petref', 'inputnode.petref'),
784+
('outputnode.motion_xfm', 'inputnode.motion_xfm'),
817785
('outputnode.petref2anat_xfm', 'inputnode.petref2anat_xfm'),
818786
]),
819-
(pet_native_wf, carpetplot_wf, [
787+
(pet_native_wf, pet_confounds_wf, [
820788
('outputnode.pet_native', 'inputnode.pet'),
821789
]),
822-
(pet_confounds_wf, carpetplot_wf, [
823-
('outputnode.confounds_file', 'inputnode.confounds_file'),
824-
('outputnode.crown_mask', 'inputnode.crown_mask'),
790+
(pet_confounds_wf, ds_confounds, [
791+
('outputnode.confounds_file', 'in_file'),
792+
('outputnode.confounds_metadata', 'meta_dict'),
825793
]),
826794
]) # fmt:skip
827795

796+
if spaces.get_spaces(nonstandard=False, dim=(3,)):
797+
carpetplot_wf = init_carpetplot_wf(
798+
mem_gb=mem_gb['resampled'],
799+
metadata=all_metadata[0],
800+
cifti_output=config.workflow.cifti_output,
801+
name='carpetplot_wf',
802+
)
803+
804+
if config.workflow.cifti_output:
805+
workflow.connect(
806+
pet_grayords_wf, 'outputnode.cifti_pet', carpetplot_wf, 'inputnode.cifti_pet',
807+
) # fmt:skip
808+
809+
def _last(inlist):
810+
return inlist[-1]
811+
812+
workflow.connect([
813+
(inputnode, carpetplot_wf, [
814+
('mni2009c2anat_xfm', 'inputnode.std2anat_xfm'),
815+
]),
816+
(pet_fit_wf, carpetplot_wf, [
817+
('outputnode.pet_mask', 'inputnode.pet_mask'),
818+
('outputnode.petref2anat_xfm', 'inputnode.petref2anat_xfm'),
819+
]),
820+
(pet_native_wf, carpetplot_wf, [
821+
('outputnode.pet_native', 'inputnode.pet'),
822+
]),
823+
(pet_confounds_wf, carpetplot_wf, [
824+
('outputnode.confounds_file', 'inputnode.confounds_file'),
825+
('outputnode.crown_mask', 'inputnode.crown_mask'),
826+
]),
827+
]) # fmt:skip
828+
828829
# Fill-in datasinks of reportlets seen so far
829830
for node in workflow.list_node_names():
830831
if node.split('.')[-1].startswith('ds_report'):

petprep/workflows/pet/fit.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
#
2121
# https://www.nipreps.org/community/licensing/
2222
#
23-
import os
2423
from pathlib import Path
2524

2625
import nibabel as nb
2726
from nipype.interfaces import utility as niu
2827
from nipype.pipeline import engine as pe
28+
from nitransforms.linear import Affine
2929
from niworkflows.interfaces.header import ValidateImage
3030
from niworkflows.utils.connections import listify
3131

@@ -199,10 +199,11 @@ def init_pet_fit_wf(
199199
)
200200
hmc_buffer = pe.Node(niu.IdentityInterface(fields=['hmc_xforms']), name='hmc_buffer')
201201

202-
if pet_tlen <= 1:
203-
# 3D PET
202+
if pet_tlen <= 1: # 3D PET
204203
petref = pet_file
205-
hmc_xforms = Path(os.getenv('FSLDIR')) / 'etc' / 'flirtsch' / 'ident.mat'
204+
idmat_fname = config.execution.work_dir / 'idmat.tfm'
205+
Affine().to_filename(idmat_fname, fmt='itk')
206+
hmc_xforms = idmat_fname
206207
config.loggers.workflow.debug('3D PET file - motion correction not needed')
207208
if petref:
208209
petref_buffer.inputs.petref = petref

0 commit comments

Comments
 (0)