Skip to content

Commit e40fcb6

Browse files
committed
Correct TPM and dartel shooting template format;
Improved code.
1 parent 8a44b46 commit e40fcb6

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

nipype/interfaces/cat12/preprocess.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
)
1919
from nipype.utils.filemanip import split_filename, fname_presuffix
2020

21+
from src.interfaces.cat12.surface import Cell
22+
2123

2224
class CAT12SegmentInputSpec(SPMCommandInputSpec):
2325
in_files = InputMultiPath(
@@ -41,6 +43,27 @@ class CAT12SegmentInputSpec(SPMCommandInputSpec):
4143
copyfile=False,
4244
)
4345

46+
_help_shoots_tpm = (
47+
'Shooting Template %d. The Shooting template must be in multi-volume nifti format and should contain GM,'
48+
' WM, and background segmentations and have to be saved with at least 16 bit. '
49+
)
50+
51+
shooting_tpm = ImageFileSPM(exists=True, field="extopts.registration.shooting.shootingtpm",
52+
desc=_help_shoots_tpm % 0, mandatory=False, copyfile=False)
53+
54+
shooting_tpm_template_1 = ImageFileSPM(
55+
exists=True, desc=_help_shoots_tpm % 1, mandatory=False, copyfile=False
56+
)
57+
shooting_tpm_template_2 = ImageFileSPM(
58+
exists=True, desc=_help_shoots_tpm % 2, mandatory=False, copyfile=False
59+
)
60+
shooting_tpm_template_3 = ImageFileSPM(
61+
exists=True, desc=_help_shoots_tpm % 3, mandatory=False, copyfile=False
62+
)
63+
shooting_tpm_template_4 = ImageFileSPM(
64+
exists=True, desc=_help_shoots_tpm % 4, mandatory=False, copyfile=False
65+
)
66+
4467
n_jobs = traits.Int(
4568
1, usedefault=True, mandatory=True, field="nproc", desc="Number of threads"
4669
)
@@ -239,13 +262,6 @@ class CAT12SegmentInputSpec(SPMCommandInputSpec):
239262
copyfile=False,
240263
)
241264

242-
_dartel_help = (
243-
"This option is to export data into a form that can be used with DARTEL. The SPM default is to "
244-
"only apply rigid body transformation. However, a more appropriate option is to apply affine "
245-
"transformation, because the additional scaling of the images requires less deformations to "
246-
"non-linearly register brains to the template."
247-
)
248-
249265
# Grey matter
250266
gm_output_native = traits.Bool(
251267
False,
@@ -495,11 +511,14 @@ def __init__(self, **inputs):
495511

496512
def _format_arg(self, opt, spec, val):
497513
"""Convert input to appropriate format for spm"""
498-
if opt in ["in_files"]:
514+
if opt == "in_files":
499515
if isinstance(val, list):
500516
return scans_for_fnames(val)
501517
else:
502518
return scans_for_fname(val)
519+
elif opt in ["tpm", "shooting_tpm"]:
520+
return Cell2Str(val)
521+
503522
return super(CAT12Segment, self)._format_arg(opt, spec, val)
504523

505524
def _list_outputs(self):
@@ -513,9 +532,7 @@ def _list_outputs(self):
513532

514533
for tidx, tissue in enumerate(["gm", "wm", "csf"]):
515534

516-
for idx, (image, prefix) in enumerate(
517-
[("modulated", "mw"), ("dartel", "r"), ("native", "")]
518-
):
535+
for image, prefix in [("modulated", "mw"), ("dartel", "r"), ("native", "")]:
519536
outtype = f"{tissue}_output_{image}"
520537
if isdefined(getattr(self.inputs, outtype)) and getattr(
521538
self.inputs, outtype
@@ -552,7 +569,7 @@ def _list_outputs(self):
552569
str(report) for report in Path(pth).glob("report/*") if report.is_file()
553570
]
554571

555-
outputs[f"report"] = fname_presuffix(
572+
outputs["report"] = fname_presuffix(
556573
f, prefix=os.path.join("report", f"cat_"), suffix=".xml", use_ext=False
557574
)
558575

@@ -561,10 +578,18 @@ def _list_outputs(self):
561578
]
562579

563580
outputs["label_rois"] = fname_presuffix(
564-
f, prefix=os.path.join("label", f"catROIs_"), suffix=".xml", use_ext=False
581+
f, prefix=os.path.join("label", "catROIs_"), suffix=".xml", use_ext=False
565582
)
566583
outputs["label_roi"] = fname_presuffix(
567-
f, prefix=os.path.join("label", f"catROI_"), suffix=".xml", use_ext=False
584+
f, prefix=os.path.join("label", "catROI_"), suffix=".xml", use_ext=False
568585
)
569586

570587
return outputs
588+
589+
590+
class Cell2Str(Cell):
591+
592+
def __str__(self):
593+
"""Convert input to appropriate format for cat12
594+
"""
595+
return "{'%s'}" % self.to_string()

nipype/interfaces/cat12/surface.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import os
22
from pathlib import Path
33

4-
from traits.trait_base import _Undefined
5-
6-
from nipype.interfaces.base import File, InputMultiPath, TraitedSpec, traits
4+
from nipype.interfaces.base import File, InputMultiPath, TraitedSpec, traits, isdefined
75
from nipype.interfaces.spm import SPMCommand
86
from nipype.interfaces.spm.base import SPMCommandInputSpec
97
from nipype.utils.filemanip import split_filename
@@ -137,14 +135,14 @@ def _list_outputs(self):
137135
pth, base, ext = split_filename(filename)
138136
# The first part of the filename is rh.central or lh.central
139137
original_filename = base.split(".", 2)[-1]
140-
for i, (extracted_parameter, parameter_name) in enumerate(names_outputs):
138+
for extracted_parameter, parameter_name in names_outputs:
141139
if extracted_parameter:
142140
for hemisphere in ["rh", "lh"]:
143141
all_files_hemisphere = hemisphere + "_extracted_files"
144142
name_hemisphere = hemisphere + "_" + parameter_name
145-
if isinstance(outputs[name_hemisphere], _Undefined):
143+
if not isdefined(outputs[name_hemisphere]):
146144
outputs[name_hemisphere] = []
147-
if isinstance(outputs[all_files_hemisphere], _Undefined):
145+
if not isdefined(outputs[all_files_hemisphere]):
148146
outputs[all_files_hemisphere] = []
149147
generated_filename = ".".join(
150148
[hemisphere, parameter_name, original_filename]

0 commit comments

Comments
 (0)