Skip to content

Commit d3efa06

Browse files
authored
RF: Move most PET GLM logic to GLMFit
1 parent 4fbd1f0 commit d3efa06

File tree

2 files changed

+36
-83
lines changed

2 files changed

+36
-83
lines changed

nipype/interfaces/freesurfer/model.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,17 @@ class GLMFitInputSpec(FSTraitedSpec):
404404
mrtm1 = InputMultiPath(
405405
traits.Tuple(File(exists=True), File(exists=True)),
406406
argstr="--mrtm1 %s %s...",
407-
desc="Reference time activity curve and frame times",
407+
desc="RefTac TimeSec : perform MRTM1 kinetic modeling",
408408
)
409409
mrtm2 = InputMultiPath(
410410
traits.Tuple(File(exists=True), File(exists=True), traits.Float),
411411
argstr="--mrtm2 %s %s %f...",
412-
desc="Reference time activity curve, frame times and k2p",
412+
desc="RefTac TimeSec k2prime : perform MRTM2 kinetic modeling",
413413
)
414414
logan = InputMultiPath(
415415
traits.Tuple(File(exists=True), File(exists=True), traits.Float),
416416
argstr="--logan %s %s %f...",
417-
desc="Reference time activity curve, frame times and tstar",
417+
desc="RefTac TimeSec tstar : perform Logan kinetic modeling",
418418
)
419419
force_perm = traits.Bool(
420420
argstr="--perm-force",
@@ -438,10 +438,9 @@ class GLMFitInputSpec(FSTraitedSpec):
438438
sim_done_file = File(
439439
argstr="--sim-done %s", desc="create file when simulation finished"
440440
)
441-
nii_gz = traits.Bool(
442-
argstr='--nii.gz',
443-
desc='save outputs as nii.gz',
444-
)
441+
_ext_xor = ['nii', 'nii_gz']
442+
nii = traits.Bool(argstr='--nii', desc='save outputs as nii', xor=_ext_xor)
443+
nii_gz = traits.Bool(argstr='--nii.gz', desc='save outputs as nii.gz', xor=_ext_xor)
445444

446445

447446
class GLMFitOutputSpec(TraitedSpec):
@@ -463,6 +462,8 @@ class GLMFitOutputSpec(TraitedSpec):
463462
frame_eigenvectors = File(desc="matrix of frame eigenvectors from residual PCA")
464463
singular_values = File(desc="matrix singular values from residual PCA")
465464
svd_stats_file = File(desc="text file summarizing the residual PCA")
465+
k2p_file = File(desc="estimate of k2p parameter")
466+
bp_file = File(desc="Binding potential estimates")
466467

467468

468469
class GLMFit(FSCommand):
@@ -497,22 +498,33 @@ def _list_outputs(self):
497498
glmdir = os.path.abspath(self.inputs.glm_dir)
498499
outputs["glm_dir"] = glmdir
499500

501+
if isdefined(self.inputs.nii_gz):
502+
ext = '.nii.gz'
503+
if isdefined(self.inputs.nii):
504+
ext = '.nii'
505+
else:
506+
ext = '.mgh'
507+
500508
# Assign the output files that always get created
501-
outputs["beta_file"] = os.path.join(glmdir, "beta.mgh")
502-
outputs["error_var_file"] = os.path.join(glmdir, "rvar.mgh")
503-
outputs["error_stddev_file"] = os.path.join(glmdir, "rstd.mgh")
504-
outputs["mask_file"] = os.path.join(glmdir, "mask.mgh")
509+
outputs["beta_file"] = os.path.join(glmdir, f"beta.{ext}")
510+
outputs["error_var_file"] = os.path.join(glmdir, f"rvar.{ext}")
511+
outputs["error_stddev_file"] = os.path.join(glmdir, f"rstd.{ext}")
512+
outputs["mask_file"] = os.path.join(glmdir, f"mask.{ext}")
505513
outputs["fwhm_file"] = os.path.join(glmdir, "fwhm.dat")
506514
outputs["dof_file"] = os.path.join(glmdir, "dof.dat")
507515
# Assign the conditional outputs
508-
if isdefined(self.inputs.save_residual) and self.inputs.save_residual:
509-
outputs["error_file"] = os.path.join(glmdir, "eres.mgh")
510-
if isdefined(self.inputs.save_estimate) and self.inputs.save_estimate:
511-
outputs["estimate_file"] = os.path.join(glmdir, "yhat.mgh")
516+
if self.inputs.save_residual:
517+
outputs["error_file"] = os.path.join(glmdir, "eres.{ext}")
518+
if self.inputs.save_estimate:
519+
outputs["estimate_file"] = os.path.join(glmdir, "yhat.{ext}")
520+
if any((self.inputs.mrtm1, self.inputs.mrtm2, self.inputs.logan)):
521+
outputs["bp_file"] = os.path.join(glmdir, f"bp.{ext}")
522+
if self.inputs.mrtm1:
523+
outputs["k2p_file"] = os.path.join(glmdir, "k2prime.dat")
512524

513525
# Get the contrast directory name(s)
526+
contrasts = []
514527
if isdefined(self.inputs.contrast):
515-
contrasts = []
516528
for c in self.inputs.contrast:
517529
if split_filename(c)[2] in [".mat", ".dat", ".mtx", ".con"]:
518530
contrasts.append(split_filename(c)[1])
@@ -522,19 +534,19 @@ def _list_outputs(self):
522534
contrasts = ["osgm"]
523535

524536
# Add in the contrast images
525-
outputs["sig_file"] = [os.path.join(glmdir, c, "sig.mgh") for c in contrasts]
526-
outputs["ftest_file"] = [os.path.join(glmdir, c, "F.mgh") for c in contrasts]
537+
outputs["sig_file"] = [os.path.join(glmdir, c, f"sig.{ext}") for c in contrasts]
538+
outputs["ftest_file"] = [os.path.join(glmdir, c, f"F.{ext}") for c in contrasts]
527539
outputs["gamma_file"] = [
528-
os.path.join(glmdir, c, "gamma.mgh") for c in contrasts
540+
os.path.join(glmdir, c, f"gamma.{ext}") for c in contrasts
529541
]
530542
outputs["gamma_var_file"] = [
531-
os.path.join(glmdir, c, "gammavar.mgh") for c in contrasts
543+
os.path.join(glmdir, c, f"gammavar.{ext}") for c in contrasts
532544
]
533545

534546
# Add in the PCA results, if relevant
535547
if isdefined(self.inputs.pca) and self.inputs.pca:
536548
pcadir = os.path.join(glmdir, "pca-eres")
537-
outputs["spatial_eigenvectors"] = os.path.join(pcadir, "v.mgh")
549+
outputs["spatial_eigenvectors"] = os.path.join(pcadir, f"v.{ext}")
538550
outputs["frame_eigenvectors"] = os.path.join(pcadir, "u.mtx")
539551
outputs["singluar_values"] = os.path.join(pcadir, "sdiag.mat")
540552
outputs["svd_stats_file"] = os.path.join(pcadir, "stats.dat")

nipype/interfaces/freesurfer/petsurfer.py

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -519,23 +519,17 @@ def _format_arg(self, name, spec, value):
519519

520520

521521
class MRTMInputSpec(GLMFitInputSpec):
522-
523522
mrtm1 = InputMultiPath(
524-
traits.Tuple(
525-
File(exists=True, mandatory=True), File(exists=True, mandatory=True)
526-
),
523+
traits.Tuple(File(exists=True), File(exists=True)),
524+
mandatory=True,
527525
argstr="--mrtm1 %s %s...",
528526
desc="RefTac TimeSec : perform MRTM1 kinetic modeling",
529527
)
530528

531529

532-
class MRTMOutputSpec(GLMFitInputSpec):
533-
534-
k2p = File(desc="estimate of k2p parameter")
535-
536-
537530
class MRTM(GLMFit):
538531
"""Perform MRTM1 kinetic modeling.
532+
539533
Examples
540534
--------
541535
>>> mrtm = MRTM()
@@ -546,35 +540,17 @@ class MRTM(GLMFit):
546540
'mri_glmfit --glmdir mrtm --y tac.nii --mrtm1 ref_tac.dat timing.dat'
547541
"""
548542

549-
_cmd = "mri_glmfit"
550543
input_spec = MRTMInputSpec
551-
output_spec = MRTMOutputSpec
552-
553-
def _list_outputs(self):
554-
outputs = self.output_spec().get()
555-
outputs['k2p'] = os.path.join(self.inputs.glm_dir, 'k2prime.dat')
556-
return outputs
557544

558545

559546
class MRTM2InputSpec(GLMFitInputSpec):
560-
561547
mrtm2 = InputMultiPath(
562548
traits.Tuple(File(exists=True), File(exists=True), traits.Float),
563549
mandatory=True,
564550
argstr="--mrtm2 %s %s %f...",
565551
desc="RefTac TimeSec k2prime : perform MRTM2 kinetic modeling",
566552
)
567553

568-
_ext_xor = ['nii', 'nii_gz']
569-
nii = traits.Bool(argstr='--nii', desc='save outputs as nii', xor=_ext_xor)
570-
nii_gz = traits.Bool(argstr='--nii.gz', desc='save outputs as nii.gz', xor=_ext_xor)
571-
yhat_save = traits.Bool(argstr="--save-yhat", desc="save signal estimate (yhat)")
572-
573-
574-
class MRTM2OutputSpec(GLMFitInputSpec):
575-
bp = File(desc="BP estimates")
576-
yhat = File(desc="Fitted values (yhat) to the TACs")
577-
578554

579555
class MRTM2(GLMFit):
580556
"""Perform MRTM2 kinetic modeling.
@@ -588,21 +564,7 @@ class MRTM2(GLMFit):
588564
'mri_glmfit --glmdir mrtm2 --y tac.nii --mrtm2 ref_tac.dat timing.dat 0.078720'
589565
"""
590566

591-
_cmd = "mri_glmfit"
592567
input_spec = MRTM2InputSpec
593-
output_spec = MRTM2OutputSpec
594-
595-
def _list_outputs(self):
596-
outputs = self.output_spec().get()
597-
if isdefined(self.inputs.nii_gz):
598-
ext = '.nii.gz'
599-
if isdefined(self.inputs.nii):
600-
ext = '.nii'
601-
else:
602-
ext = '.mgh'
603-
outputs['bp'] = os.path.join(self.inputs.glm_dir, 'bp', ext)
604-
outputs['yhat'] = os.path.join(self.inputs.glm_dir, 'yhat', ext)
605-
return outputs
606568

607569

608570
class LoganRefInputSpec(GLMFitInputSpec):
@@ -613,14 +575,6 @@ class LoganRefInputSpec(GLMFitInputSpec):
613575
desc="RefTac TimeSec tstar : perform Logan kinetic modeling",
614576
)
615577

616-
_ext_xor = ['nii', 'nii_gz']
617-
nii = traits.Bool(argstr='--nii', desc='save outputs as nii', xor=_ext_xor)
618-
nii_gz = traits.Bool(argstr='--nii.gz', desc='save outputs as nii.gz', xor=_ext_xor)
619-
620-
621-
class LoganRefOutputSpec(GLMFitInputSpec):
622-
bp_file = File(desc="BP estimates")
623-
624578

625579
class LoganRef(GLMFit):
626580
"""Perform Logan reference kinetic modeling.
@@ -634,17 +588,4 @@ class LoganRef(GLMFit):
634588
'mri_glmfit --glmdir logan --y tac.nii --logan ref_tac.dat timing.dat 2600'
635589
"""
636590

637-
_cmd = "mri_glmfit"
638591
input_spec = LoganRefInputSpec
639-
output_spec = LoganRefOutputSpec
640-
641-
def _list_outputs(self):
642-
outputs = self.output_spec().get()
643-
if isdefined(self.inputs.nii_gz):
644-
ext = '.nii.gz'
645-
if isdefined(self.inputs.nii):
646-
ext = '.nii'
647-
else:
648-
ext = '.mgh'
649-
outputs['bp'] = os.path.join(self.inputs.glm_dir, 'bp', ext)
650-
return outputs

0 commit comments

Comments
 (0)