Skip to content

Commit 7959d40

Browse files
author
David Ellis
committed
ENH: Makes mris_make_surfaces compatable with the 5.3 recon-all.
1 parent ce8a0df commit 7959d40

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

nipype/interfaces/freesurfer/utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,8 @@ class MakeSurfacesInputSpec(FSTraitedSpec):
19021902
argstr="-max %.1f", desc="No documentation (used for longitudinal processing)")
19031903
longitudinal = traits.Bool(
19041904
argstr="-long", desc="No documentation (used for longitudinal processing)")
1905+
white = traits.String(argstr="-white %s",
1906+
desc="White surface name")
19051907
copy_inputs = traits.Bool(mandatory=False,
19061908
desc="If running as a node, set this to True." +
19071909
"This will copy the input files to the node " +
@@ -1958,13 +1960,11 @@ def run(self, **inputs):
19581960
folder='mri', basename='filled.mgz')
19591961
for originalfile in [self.inputs.in_aseg,
19601962
self.inputs.in_T1]:
1961-
if isdefined(originalfile):
1962-
copy2subjdir(self, originalfile, folder='mri')
1963+
copy2subjdir(self, originalfile, folder='mri')
19631964
for originalfile in [self.inputs.orig_white,
19641965
self.inputs.orig_pial,
19651966
self.inputs.in_orig]:
1966-
if isdefined(originalfile):
1967-
copy2subjdir(self, originalfile, folder='surf')
1967+
copy2subjdir(self, originalfile, folder='surf')
19681968
if isdefined(self.inputs.in_label):
19691969
copy2subjdir(self, self.inputs.in_label, 'label',
19701970
'{0}.aparc.annot'.format(self.inputs.hemisphere))
@@ -1981,9 +1981,11 @@ def _format_arg(self, name, spec, value):
19811981
basename = os.path.basename(value)
19821982
# whent the -mgz flag is specified, it assumes the mgz extension
19831983
if self.inputs.mgz:
1984-
prefix = basename.rstrip('.mgz')
1984+
prefix = value.rstrip('.mgz')
19851985
else:
19861986
prefix = basename
1987+
if prefix == 'aseg':
1988+
return # aseg is already the default
19871989
return spec.argstr % prefix
19881990
elif name in ['orig_white', 'orig_pial']:
19891991
# these inputs do take full file paths or even basenames
@@ -2038,7 +2040,7 @@ def _list_outputs(self):
20382040

20392041
class CurvatureInputSpec(FSTraitedSpec):
20402042
in_file = File(argstr="%s", position=-2, mandatory=True, exists=True,
2041-
desc="Input file for Curvature")
2043+
copyfile=True, desc="Input file for Curvature")
20422044
# optional
20432045
threshold = traits.Float(
20442046
argstr="-thresh %.3f", mandatory=False, desc="Undocumented input threshold")
@@ -2082,7 +2084,6 @@ def _format_arg(self, name, spec, value):
20822084
if self.inputs.copy_input:
20832085
if name == 'in_file':
20842086
basename = os.path.basename(value)
2085-
shutil.copy(value, basename)
20862087
return spec.argstr % basename
20872088
return super(Curvature, self)._format_arg(name, spec, value)
20882089

nipype/workflows/smri/freesurfer/autorecon2.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,14 @@ def create_AutoRecon2(name="AutoRecon2", longitudinal=False,
156156
else:
157157
ca_register.inputs.levels = 2
158158
ca_register.inputs.A = 1
159-
ar2_wf.connect([(ar1_inputs, ca_register, [('template_talairach_m3z', 'l_files')])])
159+
ar2_wf.connect([(inputspec, ca_register, [('template_talairach_m3z', 'l_files')])])
160160

161+
162+
if fsvernum < 6:
163+
# 5.3 runs two ca_register steps
164+
ca_register2 = pe.Node(CARegister(), name='CA_Register2')
165+
ca_register2.inputs.invert_and_save = True
166+
ar2_wf.connect(ca_register, 'out_file', ca_register2, '')
161167
# Remove Neck
162168
"""
163169
The neck region is removed from the NU-corrected volume mri/nu.mgz. Makes use
@@ -248,7 +254,10 @@ def create_AutoRecon2(name="AutoRecon2", longitudinal=False,
248254
['out_file'],
249255
copy_file),
250256
name='Copy_CCSegmentation')
251-
copy_cc.inputs.out_file = 'aseg.presurf.mgz'
257+
if fsvernum > 6:
258+
copy_cc.inputs.out_file = 'aseg.presurf.mgz'
259+
else:
260+
copy_cc.inputs.out_file = 'aseg.mgz'
252261

253262
ar2_wf.connect([(segment_cc, copy_cc, [('out_file', 'in_file')])
254263
])

nipype/workflows/smri/freesurfer/autorecon3.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,19 @@ def create_AutoRecon3(name="AutoRecon3", qcache=False, plugin_args=None,
166166
# Pial Surface
167167

168168
ar3_pial = pe.Node(MakeSurfaces(), name="Make_Pial_Surface")
169-
ar3_pial.inputs.no_white = True
170169
ar3_pial.inputs.mgz = True
171170
ar3_pial.inputs.hemisphere = hemisphere
172171
ar3_pial.inputs.copy_inputs = True
173172

173+
174+
if fsvernum < 6:
175+
hemi_wf.connect(hemi_inputspec1, 'white', ar3_pial, 'in_white')
176+
ar3_pial.inputs.white = 'NOWRITE'
177+
else:
178+
ar3_pial.inputs.no_white = True
179+
hemi_wf.connect([(hemi_inputspec1, ar3_pial, [('white', 'orig_pial'),
180+
('white', 'orig_white')])])
181+
174182
hemi_wf.connect([(hemi_inputspec1, ar3_pial, [('wm', 'in_wm'),
175183
('orig', 'in_orig'),
176184
('filled', 'in_filled'),
@@ -603,13 +611,17 @@ def create_AutoRecon3(name="AutoRecon3", qcache=False, plugin_args=None,
603611

604612
if fsvernum > 6:
605613
apas_2_aseg = pe.Node(Apas2Aseg(), name="Apas_2_Aseg")
614+
ar3_wf.connect([(aparc_2_aseg, apas_2_aseg, [('out_file', 'in_file')])])
606615
else:
607-
apas_2_aseg = pe.Node(Function(['in_file', 'out_file'],
616+
# aseg.mgz gets edited in place, so we'll copy and pass it to the
617+
# outputspec once aparc_2_aseg has completed
618+
def out_aseg(in_aparcaseg, in_aseg, out_file):
619+
out_file = copy_file(in_aseg, out_file)
620+
return out_file
621+
apas_2_aseg = pe.Node(Function(['in_aparcaseg', 'in_aseg', 'out_file'],
608622
['out_file'],
609-
copy_file),
610-
name="Copy2Aseg")
611-
612-
ar3_wf.connect([(aparc_2_aseg, apas_2_aseg, [('out_file', 'in_file')])])
623+
out_aseg),
624+
name="Aseg")
613625
apas_2_aseg.inputs.out_file = "aseg.mgz"
614626

615627

0 commit comments

Comments
 (0)