Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nipy#3653 and nipy#3654 in the CAT12 Interface #3683

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 77 additions & 30 deletions nipype/interfaces/cat12/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
isdefined,
File,
Str,
ImageFile,
)
from nipype.interfaces.cat12.base import Cell

Expand All @@ -24,7 +25,7 @@

class CAT12SegmentInputSpec(SPMCommandInputSpec):
in_files = InputMultiPath(
ImageFileSPM(exists=True),
ImageFile(exists=True),
field="data",
desc="file to segment",
mandatory=True,
Expand Down Expand Up @@ -112,9 +113,9 @@
'rhe "Optimized Shooting - superlarge ventricles" option for "Spatial registration" is ! '
"required Values: \nnone: 0;\nlight: 1;\nfull: 2;\ndefault: 1070."
)
initial_segmentation = traits.Int(
0, field="extopts.spm_kamap", desc=_help_initial_seg, usedefault=True
)
# initial_segmentation = traits.Int(
# 0, field="extopts.spm_kamap", desc=_help_initial_seg, usedefault=True
# )

_help_las = (
"Additionally to WM-inhomogeneities, GM intensity can vary across different regions such as the motor"
Expand Down Expand Up @@ -226,7 +227,7 @@
" are not available as batch dependencies objects. "
)
surface_and_thickness_estimation = traits.Int(
1, field="surface", desc=_help_surf, usedefault=True
1, field="output.surface", desc=_help_surf, usedefault=True
)
surface_measures = traits.Int(
1,
Expand All @@ -239,33 +240,71 @@
neuromorphometrics = traits.Bool(
True,
field="output.ROImenu.atlases.neuromorphometrics",
usedefault=True,
# usedefault=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change the interface like this. The reason to have defaults expliciltly added is so that when tools change their defaults, old workflows that depended on those defaults would continue using the old settings.

If the changes are this extensive, new interfaces will be needed.

desc="Extract brain measures for Neuromorphometrics template",
xor=["noROI"]
)
lpba40 = traits.Bool(
True,
field="output.ROImenu.atlases.lpba40",
usedefault=True,
# usedefault=True,
desc="Extract brain measures for LPBA40 template",
xor=["noROI"]
)
cobra = traits.Bool(
True,
field="output.ROImenu.atlases.hammers",
usedefault=True,
# usedefault=True,
desc="Extract brain measures for COBRA template",
xor=["noROI"]
)
hammers = traits.Bool(
True,
False,
field="output.ROImenu.atlases.cobra",
usedefault=True,
# usedefault=True,
desc="Extract brain measures for Hammers template",
xor=["noROI"]
)
thalamus = traits.Bool(
True,
field="output.ROImenu.atlases.thalamus",
# usedefault=True,
desc="Extract brain measures for Thalamus template",
xor=["noROI"]
)
thalamic_nuclei = traits.Bool(
True,
field="output.ROImenu.atlases.thalamic_nuclei",
# usedefault=True,
desc="Extract brain measures for Thalamic Nuclei template",
xor=["noROI"]
)
suit = traits.Bool(
True,
field="output.ROImenu.atlases.suit",
# usedefault=True,
desc="Extract brain measures for Suit template",
xor=["noROI"]
)
ibsr = traits.Bool(
False,
field="output.ROImenu.atlases.ibsr",
# usedefault=True,
desc="Extract brain measures for IBSR template",
xor=["noROI"]
)
own_atlas = InputMultiPath(
ImageFileSPM(exists=True),
field="output.ROImenu.atlases.ownatlas",
desc="Extract brain measures for a given template",
mandatory=False,
copyfile=False,
xor=["noROI"]
)
noROI = traits.Bool(
field="output.ROImenu.noROI",
desc="Select if no ROI analysis needed",
xor=["neuromorphometrics", "lpba40", "cobra", "hammers", "thalamus", "thalamic_nuclei", "suit", "ibsr"],
)

# Grey matter
Expand Down Expand Up @@ -520,6 +559,8 @@
"""Convert input to appropriate format for spm"""
if opt == "in_files":
if isinstance(val, list):
if '.nii.gz' in val[0]:
return scans_for_fnames(val, keep4d=True)

Check warning on line 563 in nipype/interfaces/cat12/preprocess.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cat12/preprocess.py#L563

Added line #L563 was not covered by tests
return scans_for_fnames(val)
else:
return scans_for_fname(val)
Expand All @@ -531,6 +572,8 @@
def _list_outputs(self):
outputs = self._outputs().get()
f = self.inputs.in_files[0]
if '.nii.gz' in f:
f = f[:-3]

Check warning on line 576 in nipype/interfaces/cat12/preprocess.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cat12/preprocess.py#L576

Added line #L576 was not covered by tests
pth, base, ext = split_filename(f)

outputs["mri_images"] = [
Expand All @@ -554,22 +597,22 @@

if self.inputs.save_bias_corrected:
outputs["bias_corrected_image"] = fname_presuffix(
f, prefix=os.path.join("mri", "wmi")
f, prefix=os.path.join("mri", "wm")
)

outputs["surface_files"] = [
str(surf) for surf in Path(pth).glob("surf/*") if surf.is_file()
]

for hemisphere in ["rh", "lh"]:
for suffix in ["central", "sphere"]:
outfield = f"{hemisphere}_{suffix}_surface"
outputs[outfield] = fname_presuffix(
f,
prefix=os.path.join("surf", f"{hemisphere}.{suffix}."),
suffix=".gii",
use_ext=False,
)
if self.inputs.surface_and_thickness_estimation:
outputs["surface_files"] = [
str(surf) for surf in Path(pth).glob("surf/*") if surf.is_file()
]
for hemisphere in ["rh", "lh"]:
for suffix in ["central", "sphere"]:
outfield = f"{hemisphere}_{suffix}_surface"
outputs[outfield] = fname_presuffix(

Check warning on line 610 in nipype/interfaces/cat12/preprocess.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cat12/preprocess.py#L609-L610

Added lines #L609 - L610 were not covered by tests
f,
prefix=os.path.join("surf", f"{hemisphere}.{suffix}."),
suffix=".gii",
use_ext=False,
)

outputs["report_files"] = outputs["report_files"] = [
str(report) for report in Path(pth).glob("report/*") if report.is_file()
Expand All @@ -582,13 +625,17 @@
outputs["label_files"] = [
str(label) for label in Path(pth).glob("label/*") if label.is_file()
]

if self.inputs.neuromorphometrics or self.inputs.lpba40 or self.inputs.cobra or self.inputs.hammers or self.inputs.thalamus or self.inputs.thalamic_nuclei or self.inputs.suit or self.inputs.ibsr:
outputs["label_roi"] = fname_presuffix(

Check warning on line 630 in nipype/interfaces/cat12/preprocess.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cat12/preprocess.py#L630

Added line #L630 was not covered by tests
f, prefix=os.path.join("label", "catROI_"), suffix=".xml", use_ext=False
)

outputs["label_rois"] = fname_presuffix(
f, prefix=os.path.join("label", "catROIs_"), suffix=".xml", use_ext=False
)
outputs["label_roi"] = fname_presuffix(
f, prefix=os.path.join("label", "catROI_"), suffix=".xml", use_ext=False
)
if self.inputs.surface_and_thickness_estimation:
outputs["label_rois"] = fname_presuffix(

Check warning on line 635 in nipype/interfaces/cat12/preprocess.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cat12/preprocess.py#L635

Added line #L635 was not covered by tests
f, prefix=os.path.join("label", "catROIs_"), suffix=".xml", use_ext=False
)


return outputs

Expand Down
Loading