Skip to content

FIX: Correctly detect completed ReconAll steps #1824

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

Merged
merged 5 commits into from
Feb 21, 2017
Merged
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
47 changes: 37 additions & 10 deletions nipype/interfaces/freesurfer/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ class ReconAll(CommandLine):
input_spec = ReconAllInputSpec
output_spec = ReconAllOutputSpec
_can_resume = True
force_run = False

# Steps are based off of the recon-all tables [0,1] describing, inputs,
# commands, and outputs of each step of the recon-all process,
Expand All @@ -687,7 +688,7 @@ class ReconAll(CommandLine):
], []),
('nuintensitycor', ['mri/nu.mgz'], []),
('normalization', ['mri/T1.mgz'], []),
('skullstrip', ['mri/talairach_with_skull.lta',
('skullstrip', ['mri/transforms/talairach_with_skull.lta',
'mri/brainmask.auto.mgz',
'mri/brainmask.mgz'], []),
]
Expand Down Expand Up @@ -730,6 +731,8 @@ class ReconAll(CommandLine):
'surf/lh.sulc', 'surf/rh.sulc',
'surf/lh.inflated.H', 'surf/rh.inflated.H',
'surf/lh.inflated.K', 'surf/rh.inflated.K'], []),
# Undocumented in ReconAllTableStableV5.3
('curvstats', ['stats/lh.curv.stats', 'stats/rh.curv.stats'], []),
]
_autorecon3_steps = [
('sphere', ['surf/lh.sphere', 'surf/rh.sphere'], []),
Expand All @@ -742,18 +745,29 @@ class ReconAll(CommandLine):
'surf/lh.curv.pial', 'surf/rh.curv.pial',
'surf/lh.area.pial', 'surf/rh.area.pial',
'surf/lh.thickness', 'surf/rh.thickness'], []),
# Misnamed outputs in ReconAllTableStableV5.3: ?h.w-c.pct.mgz
('pctsurfcon', ['surf/lh.w-g.pct.mgh', 'surf/rh.w-g.pct.mgh'], []),
('parcstats', ['stats/lh.aparc.stats', 'stats/rh.aparc.stats',
'label/aparc.annot.a2009s.ctab'], []),
('cortparc2', ['label/lh.aparc.a2009s.annot',
'label/rh.aparc.a2009s.annot'], []),
('parcstats2', ['stats/lh.aparc.a2009s.stats',
'stats/rh.aparc.a2009s.stats',
'stats/aparc.annot.a2009s.ctab'], []),
'label/aparc.annot.a2009s.ctab'], []),
# Undocumented in ReconAllTableStableV5.3
('cortparc3', ['label/lh.aparc.DKTatlas40.annot',
'label/rh.aparc.DKTatlas40.annot'], []),
# Undocumented in ReconAllTableStableV5.3
('parcstats3', ['stats/lh.aparc.a2009s.stats',
'stats/rh.aparc.a2009s.stats',
'label/aparc.annot.a2009s.ctab'], []),
('cortribbon', ['mri/lh.ribbon.mgz', 'mri/rh.ribbon.mgz',
'mri/ribbon.mgz'], []),
('segstats', ['stats/aseg.stats'], []),
('aparc2aseg', ['mri/aparc+aseg.mgz',
'mri/aparc.a2009s+aseg.mgz'], []),
('wmparc', ['mri/wmparc.mgz', 'stats/wmparc.stats'], []),
('balabels', ['BA.ctab', 'BA.thresh.ctab'], []),
('balabels', ['label/BA.ctab', 'label/BA.thresh.ctab'], []),
('label-exvivo-ec', ['label/lh.entorhinal_exvivo.label',
'label/rh.entorhinal_exvivo.label'], []),
]
Expand Down Expand Up @@ -807,18 +821,18 @@ class ReconAll(CommandLine):
'surf/lh.thickness', 'surf/rh.thickness'], []),
('cortribbon', ['mri/lh.ribbon.mgz', 'mri/rh.ribbon.mgz',
'mri/ribbon.mgz'], []),
('parcstats', ['stats/lh.aparc.astats', 'stats/rh.aparc.stats',
'stats/aparc.annot.ctab'], []),
('parcstats', ['stats/lh.aparc.stats', 'stats/rh.aparc.stats',
'label/aparc.annot.ctab'], []),
('cortparc2', ['label/lh.aparc.a2009s.annot',
'label/rh.aparc.a2009s.annot'], []),
('parcstats2', ['stats/lh.aparc.a2009s.stats',
'stats/rh.aparc.a2009s.stats',
'stats/aparc.annot.a2009s.ctab'], []),
'label/aparc.annot.a2009s.ctab'], []),
('cortparc3', ['label/lh.aparc.DKTatlas.annot',
'label/rh.aparc.DKTatlas.annot'], []),
('parcstats3', ['stats/lh.aparc.DKTatlas.stats',
'stats/rh.aparc.DKTatlas.stats',
'stats/aparc.annot.DKTatlas.ctab'], []),
'label/aparc.annot.DKTatlas.ctab'], []),
('pctsurfcon', ['surf/lh.w-g.pct.mgh', 'surf/rh.w-g.pct.mgh'], []),
('hyporelabel', ['mri/aseg.presurf.hypos.mgz'], []),
('aparc2aseg', ['mri/aparc+aseg.mgz',
Expand All @@ -827,7 +841,10 @@ class ReconAll(CommandLine):
('apas2aseg', ['mri/aseg.mgz'], ['mri/aparc+aseg.mgz']),
('segstats', ['stats/aseg.stats'], []),
('wmparc', ['mri/wmparc.mgz', 'stats/wmparc.stats'], []),
('balabels', ['BA.ctab', 'BA.thresh.ctab',
# Note that this is a very incomplete list; however the ctab
# files are last to be touched, so this should be reasonable
('balabels', ['label/BA_exvivo.ctab',
'label/BA_exvivo.thresh.ctab',
'label/lh.entorhinal_exvivo.label',
'label/rh.entorhinal_exvivo.label'], []),
]
Expand Down Expand Up @@ -889,20 +906,30 @@ def cmdline(self):
if not isdefined(subjects_dir):
subjects_dir = self._gen_subjects_dir()

no_run = True
flags = []
for idx, step in enumerate(self._steps):
step, outfiles, infiles = step
flag = '-{}'.format(step)
noflag = '-no{}'.format(step)
if flag in cmd or noflag in cmd:
if noflag in cmd:
continue
elif flag in cmd:
no_run = False
continue

subj_dir = os.path.join(subjects_dir, self.inputs.subject_id)
if check_depends([os.path.join(subj_dir, f) for f in outfiles],
[os.path.join(subj_dir, f) for f in infiles]):
flags.append(noflag)
cmd += ' ' + ' '.join(flags)
else:
no_run = False

if no_run and not self.force_run:
iflogger.info('recon-all complete : Not running')
return "echo recon-all: nothing to do"

cmd += ' ' + ' '.join(flags)
iflogger.info('resume recon-all : %s' % cmd)
return cmd

Expand Down