Skip to content

Commit 1eef448

Browse files
committed
ENH: Handle expert options more gracefully
Set default behavior to refrain from creating/passing a new expert options file if an existing one has the same contents. Also, give access to -xopts-{use,clean,overwrite} options, if users want to override this default.
1 parent 39b05a2 commit 1eef448

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ class ReconAllInputSpec(CommandLineInputSpec):
632632
desc="Conform to minimum voxel size (for voxels < 1mm)")
633633
expert = File(exists=True, argstr='-expert %s',
634634
desc="Set parameters using expert file")
635+
xopts = traits.Enum("use", "clean", "overwrite", argstr='-xopts-%s',
636+
desc="Use, delete or overwrite existing expert options file")
635637
subjects_dir = Directory(exists=True, argstr='-sd %s', hash_files=False,
636638
desc='path to subjects directory', genfile=True)
637639
flags = traits.Str(argstr='%s', desc='additional parameters')
@@ -1001,11 +1003,30 @@ def _prep_expert_file(self):
10011003
if lines == []:
10021004
return ''
10031005

1006+
contents = ''.join(lines)
1007+
if not isdefined(self.inputs.xopts) and \
1008+
self.get_expert_file() == contents:
1009+
return ' -xopts-use'
1010+
10041011
expert_fname = os.path.abspath('expert.opts')
10051012
with open(expert_fname, 'w') as fobj:
1006-
fobj.write(''.join(lines))
1013+
fobj.write(contents)
10071014
return ' -expert {}'.format(expert_fname)
10081015

1016+
def _get_expert_file(self):
1017+
# Read pre-existing options file, if it exists
1018+
if isdefined(self.inputs.subjects_dir):
1019+
subjects_dir = self.inputs.subjects_dir
1020+
else:
1021+
subjects_dir = self._gen_subjects_dir()
1022+
1023+
xopts_file = os.path.join(subjects_dir, self.inputs.subject_id,
1024+
'scripts', 'expert-options')
1025+
if not os.path.exists(xopts_file):
1026+
return ''
1027+
with open(xopts_file, 'r') as fobj:
1028+
return fobj.read()
1029+
10091030

10101031
class BBRegisterInputSpec(FSTraitedSpec):
10111032
subject_id = traits.Str(argstr='--s %s',

nipype/interfaces/freesurfer/tests/test_auto_ReconAll.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def test_ReconAll_inputs():
9898
use_T2=dict(argstr='-T2pial',
9999
min_ver='5.3.0',
100100
),
101+
xopts=dict(argstr='-xopts-%s',
102+
),
101103
)
102104
inputs = ReconAll.input_spec()
103105

0 commit comments

Comments
 (0)