Skip to content

Commit 3e05a16

Browse files
committed
Connects checking of inputs
1 parent f838f64 commit 3e05a16

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

nipype/interfaces/freesurfer/longitudinal.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ class RobustTemplateInputSpec(FSTraitedSpec):
3737
'less sensitivity.')
3838
# optional
3939
transform_outputs = InputMultiPath(File(exists=False),
40-
argstr='--lta %s', desc='output xforms to template (for each input)')
41-
intensity_scaling = traits.Bool(
42-
default_value=False, argstr='--iscale', desc='allow also intensity scaling (default off)')
40+
argstr='--lta %s',
41+
desc='output xforms to template (for each input)')
42+
intensity_scaling = traits.Bool(default_value=False,
43+
argstr='--iscale',
44+
desc='allow also intensity scaling (default off)')
4345
scaled_intensity_outputs = InputMultiPath(File(exists=False),
4446
argstr='--iscaleout %s',
4547
desc='final intensity scales (will activate --iscale)')
46-
subsample_threshold = traits.Int(
47-
argstr='--subsample %d', desc='subsample if dim > # on all axes (default no subs.)')
48+
subsample_threshold = traits.Int(argstr='--subsample %d',
49+
desc='subsample if dim > # on all axes (default no subs.)')
4850
average_metric = traits.Enum('median', 'mean', argstr='--average %d',
4951
desc='construct template from: 0 Mean, 1 Median (default)')
50-
initial_timepoint = traits.Int(
51-
argstr='--inittp %d', desc='use TP# for spacial init (default random), 0: no init')
52+
initial_timepoint = traits.Int(argstr='--inittp %d',
53+
desc='use TP# for spacial init (default random), 0: no init')
5254
fixed_timepoint = traits.Bool(default_value=False, argstr='--fixtp',
5355
desc='map everthing to init TP# (init TP is not resampled)')
5456
no_iteration = traits.Bool(default_value=False, argstr='--noit',

nipype/workflows/smri/freesurfer/autorecon1.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def checkT1s(T1_files, cw256=False):
1111
print("Verifying input T1 size")
1212
import SimpleITK as sitk
1313
import os
14+
import sys
1415
if len(T1_files) == 0:
1516
print("ERROR: No T1's Given")
1617
sys.exit(-1)
@@ -36,8 +37,9 @@ def checkT1s(T1_files, cw256=False):
3637
for dim in size:
3738
if dim > 256:
3839
print("Setting MRI Convert to crop images to 256 FOV")
39-
40-
return T1_files, cw256
40+
cw256 = True
41+
origvols, iscaleout, ltaout = create_preproc_filenames(T1_files)
42+
return T1_files, cw256, origvol_names,
4143

4244
def create_preproc_filenames(in_T1s):
4345
# Create output filenames
@@ -61,6 +63,7 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
6163
inputspec.T1_files : T1 files (mandatory)
6264
inputspec.T2_file : T2 file (optional)
6365
inputspec.FLAIR_file : FLAIR file (optional)
66+
inputspec.cw256 : Conform inputs to 256 FOV (optional)
6467
6568
Outpus::
6669
@@ -69,18 +72,19 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
6972

7073
if not longitudinal:
7174
# single session processing
72-
inputSpec = pe.Node(interface=IdentityInterface(
73-
fields=['T1_files', 'T2_file', 'in_flair']),
75+
inputspec = pe.Node(interface=IdentityInterface(
76+
fields=['T1_files', 'T2_file', 'in_flair', 'cw256']),
7477
run_without_submitting=True,
7578
name='inputspec')
7679

77-
verify_inputs = pe.Node(Function(infields=["T1_files"],
78-
outfields=["T1_files"],
80+
verify_inputs = pe.Node(Function(infields=["T1_files", "cw256"],
81+
outfields=["T1_files", "cw256"],
7982
checkT1s)
8083
name="Check_T1s"),
81-
84+
ar1_wf.conncet([(inputspec, verify_inputs, [('T1_files', 'T1_files'),
85+
('cw256', 'cw256')])])
86+
8287

83-
origvols, iscaleout, ltaout = create_preproc_filenames(config['in_T1s'])
8488

8589
# T1 image preparation
8690
# For all T1's mri_convert ${InputVol} ${out_file}
@@ -89,33 +93,33 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
8993
name="T1_prep")
9094
T1_image_preparation.inputs.out_file = origvols
9195

92-
ar1_wf.connect([(inputSpec, T1_image_preparation, [('T1_files', 'in_file')]),
96+
ar1_wf.connect([(inputspec, T1_image_preparation, [('T1_files', 'in_file')]),
9397
])
9498

9599
# T2 image preparation
96100
if use_T2:
97101
# Create T2raw.mgz
98102
# mri_convert
99-
inputSpec.inputs.T2_file = config['in_T2']
103+
inputspec.inputs.T2_file = config['in_T2']
100104
T2_convert = pe.Node(MRIConvert(), name="T2_convert")
101105
T2_convert.inputs.out_file = 'T2raw.mgz'
102106
T2_convert.inputs.no_scale = True
103-
ar1_wf.connect([(inputSpec, T2_convert, [('T2_file', 'in_file')]),
107+
ar1_wf.connect([(inputspec, T2_convert, [('T2_file', 'in_file')]),
104108
])
105109

106110
# FLAIR image preparation
107111
if use_FLAIR:
108112
# Create FLAIRraw.mgz
109113
# mri_convert
110-
inputSpec.inputs.in_flair = config['in_FLAIR']
114+
inputspec.inputs.in_flair = config['in_FLAIR']
111115
FLAIR_convert = pe.Node(MRIConvert(), name="FLAIR_convert")
112116
FLAIR_convert.inputs.out_file = 'FLAIRraw.mgz'
113117
FLAIR_convert.inputs.no_scale = True
114-
ar1_wf.connect([(inputSpec, FLAIR_convert, [('in_flair', 'in_file')]),
118+
ar1_wf.connect([(inputspec, FLAIR_convert, [('in_flair', 'in_file')]),
115119
])
116120
else:
117121
# longitudinal inputs
118-
inputSpec = pe.Node(interface=IdentityInterface(
122+
inputspec = pe.Node(interface=IdentityInterface(
119123
fields=['T1_files',
120124
'iscales',
121125
'ltas',
@@ -132,21 +136,21 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
132136
copy_file),
133137
iterfield=['in_file', 'out_file'],
134138
name='Copy_ltas')
135-
ar1_wf.connect([(inputSpec, copy_ltas, [('ltas', 'in_file')])])
139+
ar1_wf.connect([(inputspec, copy_ltas, [('ltas', 'in_file')])])
136140
copy_ltas.inputs.out_file = in_ltas
137141

138142
copy_iscales = pe.MapNode(Function(['in_file', 'out_file'],
139143
['out_file'],
140144
copy_file),
141145
iterfield=['in_file', 'out_file'],
142146
name='Copy_iscales')
143-
ar1_wf.connect([(inputSpec, copy_iscales, [('iscales', 'in_file')])])
147+
ar1_wf.connect([(inputspec, copy_iscales, [('iscales', 'in_file')])])
144148
copy_iscales.inputs.out_file = in_iscales
145149

146150
concatenate_lta = pe.MapNode(ConcatenateLTA(), iterfield=['in_file'],
147151
name="Concatenate_ltas")
148152
ar1_wf.connect([(copy_ltas, concatenate_lta, [('out_file', 'in_file')]),
149-
(inputSpec, concatenate_lta, [('subj_to_template_lta', 'subj_to_base')])])
153+
(inputspec, concatenate_lta, [('subj_to_template_lta', 'subj_to_base')])])
150154

151155

152156
# Motion Correction
@@ -182,7 +186,7 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
182186
if config['longitudinal']:
183187
# if running longitudinally
184188
ar1_wf.connect([(concatenate_lta, create_template, [('out_file', 'initial_transforms')]),
185-
(inputSpec, create_template, [('T1_files', 'in_files')]),
189+
(inputspec, create_template, [('T1_files', 'in_files')]),
186190
(copy_iscales, create_template, [('out_file','in_intensity_scales')]),
187191
])
188192
else:
@@ -221,7 +225,7 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
221225
bias_correction = pe.Node(MNIBiasCorrection(), name="Bias_correction")
222226
bias_correction.inputs.iterations = 1
223227
bias_correction.inputs.protocol_iterations = 1000
224-
if config['field_strength'] == '3T':
228+
if field_strength == '3T':
225229
# 3T params from Zheng, Chee, Zagorodnov 2009 NeuroImage paper
226230
# "Improvement of brain segmentation accuracy by optimizing
227231
# non-uniformity correction using N3"
@@ -252,7 +256,7 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
252256
name='Copy_Template_Transform')
253257
talairach_avi.inputs.out_file = 'talairach.auto.xfm'
254258

255-
ar1_wf.connect([(inputSpec, talairach_avi, [('template_talairach_xfm', 'in_file')])])
259+
ar1_wf.connect([(inputspec, talairach_avi, [('template_talairach_xfm', 'in_file')])])
256260
else:
257261
# single session processing
258262
talairach_avi = pe.Node(TalairachAVI(), name="Compute_Transform")
@@ -349,7 +353,7 @@ def create_AutoRecon1(name="AutoRecon1", longitudinal=False, use_T2=False, use_F
349353
name='Copy_Template_Brainmask')
350354
copy_template_brainmask.inputs.out_file = 'brainmask_{0}.mgz'.format(config['long_template'])
351355

352-
ar1_wf.connect([(inputSpec, copy_template_brainmask, [('template_brainmask', 'in_file')])])
356+
ar1_wf.connect([(inputspec, copy_template_brainmask, [('template_brainmask', 'in_file')])])
353357

354358
mask1 = pe.Node(ApplyMask(), name="ApplyMask1")
355359
mask1.inputs.keep_mask_deletion_edits = True

0 commit comments

Comments
 (0)