Skip to content

Commit 1941987

Browse files
committed
Accept expert options as a dictionary
1 parent 1ca2e1a commit 1941987

File tree

3 files changed

+10
-114
lines changed

3 files changed

+10
-114
lines changed

nipype/interfaces/freesurfer/preprocess.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Directory, InputMultiPath,
2929
OutputMultiPath, CommandLine,
3030
CommandLineInputSpec, isdefined)
31+
from ..traits_extension import DictStrStr
3132
from .base import (FSCommand, FSTraitedSpec,
3233
FSTraitedSpecOpenMP,
3334
FSCommandOpenMP, Info)
@@ -634,7 +635,7 @@ class ReconAllInputSpec(CommandLineInputSpec):
634635
desc="Enable parallel execution")
635636
hires = traits.Bool(argstr="-hires", min_ver='6.0.0',
636637
desc="Conform to minimum voxel size (for voxels < 1mm)")
637-
expert = File(exists=True, argstr='-expert %s',
638+
expert = traits.Either(File, DictStrStr, argstr='-expert %s',
638639
desc="Set parameters using expert file")
639640
subjects_dir = Directory(exists=True, argstr='-sd %s', hash_files=False,
640641
desc='path to subjects directory', genfile=True)
@@ -899,6 +900,12 @@ def _format_arg(self, name, trait_spec, value):
899900
if name == 'T1_files':
900901
if self._is_resuming():
901902
return ''
903+
if name == 'expert' and isinstance(value, dict):
904+
expert_fname = os.path.abspath('expert.opts')
905+
expert = ['{} {}\n'.format(key, val) for key, val in value.items()]
906+
with open(expert_fname, 'w') as fobj:
907+
fobj.write(''.join(expert))
908+
value = expert_fname
902909
return super(ReconAll, self)._format_arg(name, trait_spec, value)
903910

904911
@property

nipype/interfaces/freesurfer/tests/test_auto_ExpertOptions.py

-50
This file was deleted.

nipype/interfaces/freesurfer/utils.py

+2-63
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import shutil
1919

2020
from ...utils.filemanip import fname_presuffix, split_filename
21-
from ..base import (TraitedSpec, BaseInterface, File, traits, OutputMultiPath,
22-
isdefined, CommandLine, CommandLineInputSpec)
21+
from ..base import (TraitedSpec, File, traits, OutputMultiPath, isdefined,
22+
CommandLine, CommandLineInputSpec)
2323
from .base import (FSCommand, FSTraitedSpec,
2424
FSScriptCommand, FSScriptOutputSpec,
2525
FSTraitedSpecOpenMP, FSCommandOpenMP)
@@ -2879,64 +2879,3 @@ def _list_outputs(self):
28792879
outputs = self._outputs().get()
28802880
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
28812881
return outputs
2882-
2883-
2884-
class ExpertOptionsInputSpec(TraitedSpec):
2885-
talairach = traits.String(desc="Flags to pass to talairach commands")
2886-
mri_normalize = traits.String(desc="Flags to pass to mri_normalize commands")
2887-
mri_watershed = traits.String(desc="Flags to pass to mri_watershed commands")
2888-
mri_em_register = traits.String(desc="Flags to pass to mri_em_register commands")
2889-
mri_ca_normalize = traits.String(desc="Flags to pass to mri_ca_normalize commands")
2890-
mri_ca_register = traits.String(desc="Flags to pass to mri_ca_register commands")
2891-
mri_remove_neck = traits.String(desc="Flags to pass to mri_remove_neck commands")
2892-
mri_ca_label = traits.String(desc="Flags to pass to mri_ca_label commands")
2893-
mri_segstats = traits.String(desc="Flags to pass to mri_segstats commands")
2894-
mri_mask = traits.String(desc="Flags to pass to mri_mask commands")
2895-
mri_segment = traits.String(desc="Flags to pass to mri_segment commands")
2896-
mri_edit_wm_with_aseg = traits.String(desc="Flags to pass to mri_edit_wm_with_aseg commands")
2897-
mri_pretess = traits.String(desc="Flags to pass to mri_pretess commands")
2898-
mri_fill = traits.String(desc="Flags to pass to mri_fill commands")
2899-
mri_tessellate = traits.String(desc="Flags to pass to mri_tessellate commands")
2900-
mris_smooth = traits.String(desc="Flags to pass to mri_smooth commands")
2901-
mris_inflate = traits.String(desc="Flags to pass to mri_inflate commands")
2902-
mris_sphere = traits.String(desc="Flags to pass to mris_sphere commands")
2903-
mris_fix_topology = traits.String(desc="Flags to pass to mris_fix_topology commands")
2904-
mris_make_surfaces = traits.String(desc="Flags to pass to mris_make_surfaces commands")
2905-
mris_surf2vol = traits.String(desc="Flags to pass to mris_surf2vol commands")
2906-
mris_register = traits.String(desc="Flags to pass to mris_register commands")
2907-
mrisp_paint = traits.String(desc="Flags to pass to mrisp_paint commands")
2908-
mris_ca_label = traits.String(desc="Flags to pass to mris_ca_label commands")
2909-
mris_anatomical_stats = traits.String(desc="Flags to pass to mris_anatomical_stats commands")
2910-
mri_aparc2aseg = traits.String(desc="Flags to pass to mri_aparc2aseg commands")
2911-
out_file = File("expert.opts", usedefault=True, desc="Output expert options file")
2912-
2913-
2914-
class ExpertOptionsOutputSpec(TraitedSpec):
2915-
out_file = File(exists=False, desc="Output expert options file")
2916-
2917-
2918-
class ExpertOptions(BaseInterface):
2919-
"""
2920-
Creates expert options file
2921-
https://surfer.nmr.mgh.harvard.edu/fswiki/recon-all#ExpertOptionsFile
2922-
"""
2923-
input_spec = ExpertOptionsInputSpec
2924-
output_spec = ExpertOptionsOutputSpec
2925-
2926-
def _list_outputs(self):
2927-
outputs = self._outputs().get()
2928-
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
2929-
return outputs
2930-
2931-
def _run_interface(self, runtime):
2932-
out_file = self.inputs.out_file
2933-
2934-
lines = []
2935-
for binary, args in self.inputs.get().items():
2936-
if binary == 'out_file' or not isdefined(args):
2937-
continue
2938-
lines.append('{} {}\n'.format(binary, args))
2939-
2940-
with open(out_file, 'w') as fobj:
2941-
fobj.write(''.join(lines))
2942-
return runtime

0 commit comments

Comments
 (0)