Skip to content

Commit cd7dc15

Browse files
ellisdgDavid Ellis
authored andcommitted
ENH: Allows for implicit aseg input in ribbon masking.
1 parent a6850ce commit cd7dc15

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

nipype/interfaces/freesurfer/utils.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,30 @@
3535

3636

3737
def copy2subjdir(cls, in_file, folder=None, basename=None, subject_id=None):
38+
"""Method to copy an input to the subjects directory"""
39+
# check that the input is defined
40+
if not isdefined(in_file):
41+
return in_file
42+
# check that subjects_dir is defined
3843
if isdefined(cls.inputs.subjects_dir):
3944
subjects_dir = cls.inputs.subjects_dir
4045
else:
41-
subjects_dir = os.getcwd()
46+
subjects_dir = os.getcwd() #if not use cwd
47+
# check for subject_id
4248
if not subject_id:
4349
if isdefined(cls.inputs.subject_id):
4450
subject_id = cls.inputs.subject_id
4551
else:
46-
subject_id = 'subject_id'
52+
subject_id = 'subject_id' #default
53+
# check for basename
4754
if basename == None:
4855
basename = os.path.basename(in_file)
56+
# check which folder to put the file in
4957
if folder != None:
5058
out_dir = os.path.join(subjects_dir, subject_id, folder)
5159
else:
5260
out_dir = os.path.join(subjects_dir, subject_id)
61+
# make the output folder if it does not exist
5362
if not os.path.isdir(out_dir):
5463
os.makedirs(out_dir)
5564
out_file = os.path.join(out_dir, basename)
@@ -58,7 +67,7 @@ def copy2subjdir(cls, in_file, folder=None, basename=None, subject_id=None):
5867
return out_file
5968

6069
def createoutputdirs(outputs):
61-
"""create an output directories. If not created, some freesurfer interfaces fail"""
70+
"""create all output directories. If not created, some freesurfer interfaces fail"""
6271
for output in outputs.itervalues():
6372
dirname = os.path.dirname(output)
6473
if not os.path.isdir(dirname):
@@ -2301,11 +2310,16 @@ class VolumeMaskInputSpec(FSTraitedSpec):
23012310
desc="Implicit input left white matter surface")
23022311
rh_white = File(mandatory=True, exists=True,
23032312
desc="Implicit input right white matter surface")
2313+
aseg = File(mandatory=True, exists=True,
2314+
xor=['in_aseg'],
2315+
desc="Implicit aseg.mgz segmentation. " +
2316+
"Specify a different aseg by using the 'in_aseg' input.")
23042317
subject_id = traits.String('subject_id', usedefault=True,
23052318
position=-1, argstr="%s", mandatory=True,
23062319
desc="Subject being processed")
23072320
# optional
2308-
in_aseg = File(argstr="--aseg_name %s", mandatory=False, exists=True,
2321+
in_aseg = File(argstr="--aseg_name %s", mandatory=False,
2322+
exists=True, xor=['aseg'],
23092323
desc="Input aseg file for VolumeMask")
23102324
save_ribbon = traits.Bool(argstr="--save_ribbon", mandatory=False,
23112325
desc="option to save just the ribbon for the " +
@@ -2363,8 +2377,9 @@ def run(self, **inputs):
23632377
copy2subjdir(self, self.inputs.rh_pial, 'surf', 'rh.pial')
23642378
copy2subjdir(self, self.inputs.lh_white, 'surf', 'lh.white')
23652379
copy2subjdir(self, self.inputs.rh_white, 'surf', 'rh.white')
2366-
if isdefined(self.inputs.in_aseg):
2367-
copy2subjdir(self, self.inputs.in_aseg, 'mri')
2380+
copy2subjdir(self, self.inputs.in_aseg, 'mri')
2381+
copy2subjdir(self, self.inputs.aseg, 'mri', 'aseg.mgz')
2382+
23682383
return super(VolumeMask, self).run(**inputs)
23692384

23702385
def _format_arg(self, name, spec, value):

nipype/workflows/smri/freesurfer/autorecon3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ def create_AutoRecon3(name="AutoRecon3", qcache=False, plugin_args=None,
282282

283283
if fsvernum > 6:
284284
ar3_wf.connect([(inputpsec, volume_mask, [('aseg_presurf', 'in_aseg')])])
285+
else:
286+
ar3_wf.connect([(inputpsec, volume_mask, [('aseg_presurf', 'aseg')])])
285287

286288
ar3_lh_wf2 = pe.Workflow(name="AutoRecon3_Left_2")
287289
ar3_rh_wf2 = pe.Workflow(name="AutoRecon3_Right_2")

0 commit comments

Comments
 (0)