Skip to content

Commit 2896bd0

Browse files
authored
Merge pull request #1824 from effigies/bug/recon_all_continue
FIX: Correctly detect completed ReconAll steps
2 parents 7d96581 + cc5d9c9 commit 2896bd0

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

nipype/interfaces/freesurfer/preprocess.py

+37-10
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ class ReconAll(CommandLine):
665665
input_spec = ReconAllInputSpec
666666
output_spec = ReconAllOutputSpec
667667
_can_resume = True
668+
force_run = False
668669

669670
# Steps are based off of the recon-all tables [0,1] describing, inputs,
670671
# commands, and outputs of each step of the recon-all process,
@@ -687,7 +688,7 @@ class ReconAll(CommandLine):
687688
], []),
688689
('nuintensitycor', ['mri/nu.mgz'], []),
689690
('normalization', ['mri/T1.mgz'], []),
690-
('skullstrip', ['mri/talairach_with_skull.lta',
691+
('skullstrip', ['mri/transforms/talairach_with_skull.lta',
691692
'mri/brainmask.auto.mgz',
692693
'mri/brainmask.mgz'], []),
693694
]
@@ -730,6 +731,8 @@ class ReconAll(CommandLine):
730731
'surf/lh.sulc', 'surf/rh.sulc',
731732
'surf/lh.inflated.H', 'surf/rh.inflated.H',
732733
'surf/lh.inflated.K', 'surf/rh.inflated.K'], []),
734+
# Undocumented in ReconAllTableStableV5.3
735+
('curvstats', ['stats/lh.curv.stats', 'stats/rh.curv.stats'], []),
733736
]
734737
_autorecon3_steps = [
735738
('sphere', ['surf/lh.sphere', 'surf/rh.sphere'], []),
@@ -742,18 +745,29 @@ class ReconAll(CommandLine):
742745
'surf/lh.curv.pial', 'surf/rh.curv.pial',
743746
'surf/lh.area.pial', 'surf/rh.area.pial',
744747
'surf/lh.thickness', 'surf/rh.thickness'], []),
748+
# Misnamed outputs in ReconAllTableStableV5.3: ?h.w-c.pct.mgz
749+
('pctsurfcon', ['surf/lh.w-g.pct.mgh', 'surf/rh.w-g.pct.mgh'], []),
750+
('parcstats', ['stats/lh.aparc.stats', 'stats/rh.aparc.stats',
751+
'label/aparc.annot.a2009s.ctab'], []),
745752
('cortparc2', ['label/lh.aparc.a2009s.annot',
746753
'label/rh.aparc.a2009s.annot'], []),
747754
('parcstats2', ['stats/lh.aparc.a2009s.stats',
748755
'stats/rh.aparc.a2009s.stats',
749-
'stats/aparc.annot.a2009s.ctab'], []),
756+
'label/aparc.annot.a2009s.ctab'], []),
757+
# Undocumented in ReconAllTableStableV5.3
758+
('cortparc3', ['label/lh.aparc.DKTatlas40.annot',
759+
'label/rh.aparc.DKTatlas40.annot'], []),
760+
# Undocumented in ReconAllTableStableV5.3
761+
('parcstats3', ['stats/lh.aparc.a2009s.stats',
762+
'stats/rh.aparc.a2009s.stats',
763+
'label/aparc.annot.a2009s.ctab'], []),
750764
('cortribbon', ['mri/lh.ribbon.mgz', 'mri/rh.ribbon.mgz',
751765
'mri/ribbon.mgz'], []),
752766
('segstats', ['stats/aseg.stats'], []),
753767
('aparc2aseg', ['mri/aparc+aseg.mgz',
754768
'mri/aparc.a2009s+aseg.mgz'], []),
755769
('wmparc', ['mri/wmparc.mgz', 'stats/wmparc.stats'], []),
756-
('balabels', ['BA.ctab', 'BA.thresh.ctab'], []),
770+
('balabels', ['label/BA.ctab', 'label/BA.thresh.ctab'], []),
757771
('label-exvivo-ec', ['label/lh.entorhinal_exvivo.label',
758772
'label/rh.entorhinal_exvivo.label'], []),
759773
]
@@ -807,18 +821,18 @@ class ReconAll(CommandLine):
807821
'surf/lh.thickness', 'surf/rh.thickness'], []),
808822
('cortribbon', ['mri/lh.ribbon.mgz', 'mri/rh.ribbon.mgz',
809823
'mri/ribbon.mgz'], []),
810-
('parcstats', ['stats/lh.aparc.astats', 'stats/rh.aparc.stats',
811-
'stats/aparc.annot.ctab'], []),
824+
('parcstats', ['stats/lh.aparc.stats', 'stats/rh.aparc.stats',
825+
'label/aparc.annot.ctab'], []),
812826
('cortparc2', ['label/lh.aparc.a2009s.annot',
813827
'label/rh.aparc.a2009s.annot'], []),
814828
('parcstats2', ['stats/lh.aparc.a2009s.stats',
815829
'stats/rh.aparc.a2009s.stats',
816-
'stats/aparc.annot.a2009s.ctab'], []),
830+
'label/aparc.annot.a2009s.ctab'], []),
817831
('cortparc3', ['label/lh.aparc.DKTatlas.annot',
818832
'label/rh.aparc.DKTatlas.annot'], []),
819833
('parcstats3', ['stats/lh.aparc.DKTatlas.stats',
820834
'stats/rh.aparc.DKTatlas.stats',
821-
'stats/aparc.annot.DKTatlas.ctab'], []),
835+
'label/aparc.annot.DKTatlas.ctab'], []),
822836
('pctsurfcon', ['surf/lh.w-g.pct.mgh', 'surf/rh.w-g.pct.mgh'], []),
823837
('hyporelabel', ['mri/aseg.presurf.hypos.mgz'], []),
824838
('aparc2aseg', ['mri/aparc+aseg.mgz',
@@ -827,7 +841,10 @@ class ReconAll(CommandLine):
827841
('apas2aseg', ['mri/aseg.mgz'], ['mri/aparc+aseg.mgz']),
828842
('segstats', ['stats/aseg.stats'], []),
829843
('wmparc', ['mri/wmparc.mgz', 'stats/wmparc.stats'], []),
830-
('balabels', ['BA.ctab', 'BA.thresh.ctab',
844+
# Note that this is a very incomplete list; however the ctab
845+
# files are last to be touched, so this should be reasonable
846+
('balabels', ['label/BA_exvivo.ctab',
847+
'label/BA_exvivo.thresh.ctab',
831848
'label/lh.entorhinal_exvivo.label',
832849
'label/rh.entorhinal_exvivo.label'], []),
833850
]
@@ -889,20 +906,30 @@ def cmdline(self):
889906
if not isdefined(subjects_dir):
890907
subjects_dir = self._gen_subjects_dir()
891908

909+
no_run = True
892910
flags = []
893911
for idx, step in enumerate(self._steps):
894912
step, outfiles, infiles = step
895913
flag = '-{}'.format(step)
896914
noflag = '-no{}'.format(step)
897-
if flag in cmd or noflag in cmd:
915+
if noflag in cmd:
916+
continue
917+
elif flag in cmd:
918+
no_run = False
898919
continue
899920

900921
subj_dir = os.path.join(subjects_dir, self.inputs.subject_id)
901922
if check_depends([os.path.join(subj_dir, f) for f in outfiles],
902923
[os.path.join(subj_dir, f) for f in infiles]):
903924
flags.append(noflag)
904-
cmd += ' ' + ' '.join(flags)
925+
else:
926+
no_run = False
905927

928+
if no_run and not self.force_run:
929+
iflogger.info('recon-all complete : Not running')
930+
return "echo recon-all: nothing to do"
931+
932+
cmd += ' ' + ' '.join(flags)
906933
iflogger.info('resume recon-all : %s' % cmd)
907934
return cmd
908935

0 commit comments

Comments
 (0)