Skip to content

Commit 2cba32a

Browse files
committed
fix: freesurfer resume does not set any inputs
1 parent ebbb9bf commit 2cba32a

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

nipype/interfaces/freesurfer/preprocess.py

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,22 @@ def _gen_filename(self, name):
591591

592592

593593
class ReconAllInputSpec(CommandLineInputSpec):
594-
subject_id = traits.Str("recon_all", argstr='-subjid %s', desc='subject name',
595-
usedefault=True)
594+
subject_id = traits.Str("recon_all", argstr='-subjid %s',
595+
desc='subject name', usedefault=True)
596596
directive = traits.Enum('all', 'autorecon1', 'autorecon2', 'autorecon2-cp',
597-
'autorecon2-wm', 'autorecon2-inflate1', 'autorecon2-perhemi',
598-
'autorecon3', 'localGI', 'qcache', argstr='-%s',
599-
desc='process directive', usedefault=True,
600-
position=0)
601-
hemi = traits.Enum('lh', 'rh', desc='hemisphere to process', argstr="-hemi %s")
597+
'autorecon2-wm', 'autorecon2-inflate1',
598+
'autorecon2-perhemi', 'autorecon3', 'localGI',
599+
'qcache', argstr='-%s', desc='process directive',
600+
usedefault=True, position=0)
601+
hemi = traits.Enum('lh', 'rh', desc='hemisphere to process',
602+
argstr="-hemi %s")
602603
T1_files = InputMultiPath(File(exists=True), argstr='-i %s...',
603604
desc='name of T1 file to process')
604-
subjects_dir = Directory(exists=True, argstr='-sd %s',
605+
T2_file = File(exists=True, argstr="-T2 %s", min_ver='5.3.0',
606+
desc='Use a T2 image to refine the cortical surface')
607+
openmp = traits.Int(argstr="-openmp %d",
608+
desc="Number of processors to use in parallel")
609+
subjects_dir = Directory(exists=True, argstr='-sd %s', hash_files=False,
605610
desc='path to subjects directory', genfile=True)
606611
flags = traits.Str(argstr='%s', desc='additional parameters')
607612

@@ -742,44 +747,59 @@ def _list_outputs(self):
742747
outputs = self._outputs().get()
743748

744749
outputs.update(FreeSurferSource(subject_id=self.inputs.subject_id,
745-
subjects_dir=subjects_dir, hemi=hemi)._list_outputs())
750+
subjects_dir=subjects_dir,
751+
hemi=hemi)._list_outputs())
746752
outputs['subject_id'] = self.inputs.subject_id
747753
outputs['subjects_dir'] = subjects_dir
748754
return outputs
749755

750-
@property
751-
def cmdline(self):
756+
def _is_resuming(self):
752757
subjects_dir = self.inputs.subjects_dir
753758
if not isdefined(subjects_dir):
754759
subjects_dir = self._gen_subjects_dir()
755-
if not os.path.isdir(
756-
os.path.join(subjects_dir,self.inputs.subject_id,'mri')):
757-
return super(ReconAll, self).cmdline
758-
self._check_mandatory_inputs()
759-
skip = ['T1_files']
760+
if os.path.isdir(os.path.join(subjects_dir, self.inputs.subject_id,
761+
'mri')):
762+
return True
763+
return False
764+
765+
def _format_arg(self, name, trait_spec, value):
766+
if name == 'T1_files':
767+
if self._is_resuming():
768+
return ''
769+
return super(ReconAll, self)._format_arg(name, trait_spec, value)
770+
771+
@property
772+
def cmdline(self):
773+
cmd = super(ReconAll, self).cmdline
774+
if not self._is_resuming():
775+
return cmd
760776
subjects_dir = self.inputs.subjects_dir
761777
if not isdefined(subjects_dir):
762778
subjects_dir = self._gen_subjects_dir()
779+
#cmd = cmd.replace(' -all ', ' -make all ')
780+
iflogger.info('Overriding recon-all directive')
763781
flags = []
764782
directive = 'all'
765783
for idx, step in enumerate(self._steps):
766784
step, outfiles = step
767-
if all([os.path.exists(os.path.join(subjects_dir,self.inputs.subject_id,f)) for f in outfiles]):
785+
if all([os.path.exists(os.path.join(subjects_dir,
786+
self.inputs.subject_id,f)) for
787+
f in outfiles]):
768788
flags.append('-no%s'%step)
769789
if idx > 4:
770790
directive = 'autorecon2'
771791
elif idx > 23:
772792
directive = 'autorecon3'
773793
else:
774794
flags.append('-%s'%step)
775-
self.inputs.args = ' '.join([self.inputs.args] + flags)
776-
self.inputs.directive = directive
777-
allargs = self._parse_inputs(skip=skip)
778-
allargs.insert(0, self.cmd)
779-
cmd = ' '.join(allargs)
780-
iflogger.info('resume recon-all : %s'%cmd)
795+
cmd = cmd.replace(' -%s ' % self.inputs.directive, ' -%s ' % directive)
796+
cmd += ' ' + ' '.join(flags)
797+
iflogger.info('resume recon-all : %s' % cmd)
781798
return cmd
782799

800+
def _run_interface(self, runtime, correct_return_codes=[0]):
801+
runtime.returncode = 0
802+
return runtime
783803

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

0 commit comments

Comments
 (0)