Skip to content

Commit e17321e

Browse files
committed
Explicitly add extra options to ReconAllInputSpec
1 parent bd4b717 commit e17321e

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,40 @@ class ReconAllInputSpec(CommandLineInputSpec):
635635
desc="Enable parallel execution")
636636
hires = traits.Bool(argstr="-hires", min_ver='6.0.0',
637637
desc="Conform to minimum voxel size (for voxels < 1mm)")
638-
expert = traits.Either(File(exists=True), DictStrStr, argstr='-expert %s',
638+
expert = File(exists=True, argstr='-expert %s',
639639
desc="Set parameters using expert file")
640640
subjects_dir = Directory(exists=True, argstr='-sd %s', hash_files=False,
641641
desc='path to subjects directory', genfile=True)
642642
flags = traits.Str(argstr='%s', desc='additional parameters')
643643

644+
# Expert options
645+
talairach = traits.Str(desc="Flags to pass to talairach commands", xor=['expert'])
646+
mri_normalize = traits.Str(desc="Flags to pass to mri_normalize commands", xor=['expert'])
647+
mri_watershed = traits.Str(desc="Flags to pass to mri_watershed commands", xor=['expert'])
648+
mri_em_register = traits.Str(desc="Flags to pass to mri_em_register commands", xor=['expert'])
649+
mri_ca_normalize = traits.Str(desc="Flags to pass to mri_ca_normalize commands", xor=['expert'])
650+
mri_ca_register = traits.Str(desc="Flags to pass to mri_ca_register commands", xor=['expert'])
651+
mri_remove_neck = traits.Str(desc="Flags to pass to mri_remove_neck commands", xor=['expert'])
652+
mri_ca_label = traits.Str(desc="Flags to pass to mri_ca_label commands", xor=['expert'])
653+
mri_segstats = traits.Str(desc="Flags to pass to mri_segstats commands", xor=['expert'])
654+
mri_mask = traits.Str(desc="Flags to pass to mri_mask commands", xor=['expert'])
655+
mri_segment = traits.Str(desc="Flags to pass to mri_segment commands", xor=['expert'])
656+
mri_edit_wm_with_aseg = traits.Str(desc="Flags to pass to mri_edit_wm_with_aseg commands", xor=['expert'])
657+
mri_pretess = traits.Str(desc="Flags to pass to mri_pretess commands", xor=['expert'])
658+
mri_fill = traits.Str(desc="Flags to pass to mri_fill commands", xor=['expert'])
659+
mri_tessellate = traits.Str(desc="Flags to pass to mri_tessellate commands", xor=['expert'])
660+
mris_smooth = traits.Str(desc="Flags to pass to mri_smooth commands", xor=['expert'])
661+
mris_inflate = traits.Str(desc="Flags to pass to mri_inflate commands", xor=['expert'])
662+
mris_sphere = traits.Str(desc="Flags to pass to mris_sphere commands", xor=['expert'])
663+
mris_fix_topology = traits.Str(desc="Flags to pass to mris_fix_topology commands", xor=['expert'])
664+
mris_make_surfaces = traits.Str(desc="Flags to pass to mris_make_surfaces commands", xor=['expert'])
665+
mris_surf2vol = traits.Str(desc="Flags to pass to mris_surf2vol commands", xor=['expert'])
666+
mris_register = traits.Str(desc="Flags to pass to mris_register commands", xor=['expert'])
667+
mrisp_paint = traits.Str(desc="Flags to pass to mrisp_paint commands", xor=['expert'])
668+
mris_ca_label = traits.Str(desc="Flags to pass to mris_ca_label commands", xor=['expert'])
669+
mris_anatomical_stats = traits.Str(desc="Flags to pass to mris_anatomical_stats commands", xor=['expert'])
670+
mri_aparc2aseg = traits.Str(desc="Flags to pass to mri_aparc2aseg commands", xor=['expert'])
671+
644672

645673
class ReconAllOutputSpec(FreeSurferSource.output_spec):
646674
subjects_dir = Directory(exists=True, desc='Freesurfer subjects directory.')
@@ -856,6 +884,16 @@ class ReconAll(CommandLine):
856884

857885
_steps = _autorecon1_steps + _autorecon2_steps + _autorecon3_steps
858886

887+
_binaries = ['talairach', 'mri_normalize', 'mri_watershed',
888+
'mri_em_register', 'mri_ca_normalize', 'mri_ca_register',
889+
'mri_remove_neck', 'mri_ca_label', 'mri_segstats',
890+
'mri_mask', 'mri_segment', 'mri_edit_wm_with_aseg',
891+
'mri_pretess', 'mri_fill', 'mri_tessellate', 'mris_smooth',
892+
'mris_inflate', 'mris_sphere', 'mris_fix_topology',
893+
'mris_make_surfaces', 'mris_surf2vol', 'mris_register',
894+
'mrisp_paint', 'mris_ca_label', 'mris_anatomical_stats',
895+
'mri_aparc2aseg']
896+
859897
def _gen_subjects_dir(self):
860898
return os.getcwd()
861899

@@ -900,12 +938,6 @@ def _format_arg(self, name, trait_spec, value):
900938
if name == 'T1_files':
901939
if self._is_resuming():
902940
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
909941
return super(ReconAll, self)._format_arg(name, trait_spec, value)
910942

911943
@property
@@ -917,6 +949,10 @@ def cmdline(self):
917949
if not isdefined(subjects_dir):
918950
subjects_dir = self._gen_subjects_dir()
919951

952+
# Adds '-expert' flag if expert flags are passed
953+
# Mutually exclusive with 'expert' input parameter
954+
cmd += self._prep_expert_file()
955+
920956
no_run = True
921957
flags = []
922958
for idx, step in enumerate(self._steps):
@@ -944,6 +980,24 @@ def cmdline(self):
944980
iflogger.info('resume recon-all : %s' % cmd)
945981
return cmd
946982

983+
def _prep_expert_file(self):
984+
if isdefined(self.inputs.extra):
985+
return ''
986+
987+
lines = []
988+
for binary in binaries:
989+
args = getattr(self.inputs, binary)
990+
if isdefined(args):
991+
lines.append('{} {}\n'.format(binary, args))
992+
993+
if lines == []:
994+
return ''
995+
996+
expert_fname = os.path.abspath('expert.opts')
997+
with open(expert_fname, 'w') as fobj:
998+
fobj.write(''.join(lines))
999+
return ' -expert {}'.format(expert_fname)
1000+
9471001

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

0 commit comments

Comments
 (0)