@@ -113,7 +113,7 @@ class FSLXCommandInputSpec(FSLCommandInputSpec):
113
113
logdir = Directory ('.' , argstr = '--logdir=%s' , usedefault = True )
114
114
n_fibres = traits .Range (
115
115
usedefault = True , low = 1 , default = 2 , argstr = '--nfibres=%d' ,
116
- desc = ('Maximum number of fibres to fit in each voxel' ))
116
+ desc = ('Maximum number of fibres to fit in each voxel' ), mandatory = True )
117
117
model = traits .Enum (1 , 2 , argstr = '--model=%d' ,
118
118
desc = ('use monoexponential (1, default, required for '
119
119
'single-shell) or multiexponential (2, multi-'
@@ -167,22 +167,19 @@ class FSLXCommandInputSpec(FSLCommandInputSpec):
167
167
168
168
169
169
class FSLXCommandOutputSpec (TraitedSpec ):
170
- dsamples = File (desc = ('Samples from the distribution on diffusivity d' ))
171
- d_stdsamples = File (desc = ('Std of samples from the distribution d' ))
172
- dyads = OutputMultiPath (File (), desc = ('Mean of PDD distribution'
170
+ dyads = OutputMultiPath (File (exists = True ), desc = ('Mean of PDD distribution'
173
171
' in vector form.' ))
174
- fsamples = OutputMultiPath (File (), desc = ('Samples from the '
172
+ fsamples = OutputMultiPath (File (exists = True ), desc = ('Samples from the '
175
173
'distribution on f anisotropy' ))
176
- mean_dsamples = File (desc = 'Mean of distribution on diffusivity d' )
177
- mean_d_stdsamples = File (desc = 'Mean of distribution on diffusivity d' )
178
- mean_fsamples = OutputMultiPath (File (), desc = ('Mean of '
174
+ mean_dsamples = File (exists = True , desc = 'Mean of distribution on diffusivity d' )
175
+ mean_fsamples = OutputMultiPath (File (exists = True ), desc = ('Mean of '
179
176
'distribution on f anisotropy' ))
180
- mean_S0samples = File (desc = ('Mean of distribution on T2w'
177
+ mean_S0samples = File (exists = True , desc = ('Mean of distribution on T2w'
181
178
'baseline signal intensity S0' ))
182
- mean_tausamples = File (desc = ('Mean of distribution on '
179
+ mean_tausamples = File (exists = True , desc = ('Mean of distribution on '
183
180
'tau samples (only with rician noise)' ))
184
- phsamples = OutputMultiPath (File (), desc = ('phi samples, per fiber' ))
185
- thsamples = OutputMultiPath (File (), desc = ('theta samples, per fiber' ))
181
+ phsamples = OutputMultiPath (File (exists = True ), desc = ('phi samples, per fiber' ))
182
+ thsamples = OutputMultiPath (File (exists = True ), desc = ('theta samples, per fiber' ))
186
183
187
184
188
185
class FSLXCommand (FSLCommand ):
@@ -199,21 +196,18 @@ def _run_interface(self, runtime):
199
196
self .raise_exception (runtime )
200
197
return runtime
201
198
202
- def _list_outputs (self ):
199
+ def _list_outputs (self , out_dir = None ):
203
200
outputs = self .output_spec ().get ()
204
- n_fibres = 2
205
- if isdefined (self .inputs .n_fibres ):
206
- n_fibres = self .inputs .n_fibres
207
-
208
- if isdefined (self .inputs .logdir ):
209
- out_dir = os .path .abspath (self .inputs .logdir )
210
- else :
211
- out_dir = os .path .abspath ('logdir' )
201
+ n_fibres = self .inputs .n_fibres
202
+ if not out_dir :
203
+ if isdefined (self .inputs .logdir ):
204
+ out_dir = os .path .abspath (self .inputs .logdir )
205
+ else :
206
+ out_dir = os .path .abspath ('logdir' )
212
207
213
208
multi_out = ['dyads' , 'fsamples' , 'mean_fsamples' ,
214
209
'phsamples' , 'thsamples' ]
215
- single_out = ['dsamples' , 'd_stdsamples' , 'mean_dsamples' ,
216
- 'mean_S0samples' , 'mean_d_stdsamples' ]
210
+ single_out = ['mean_dsamples' , 'mean_S0samples' ]
217
211
218
212
for k in single_out :
219
213
outputs [k ] = self ._gen_fname (k , cwd = out_dir )
@@ -243,28 +237,55 @@ def _list_outputs(self):
243
237
244
238
245
239
class BEDPOSTX5InputSpec (FSLXCommandInputSpec ):
246
- out_dir = Directory ('.' , mandatory = True , desc = 'output directory' ,
240
+ dwi = File (exists = True , desc = 'diffusion weighted image data file' ,
241
+ mandatory = True )
242
+ mask = File (exists = True , desc = 'bet binary mask file' , mandatory = True )
243
+ bvecs = File (exists = True , desc = 'b vectors file' , mandatory = True )
244
+ bvals = File (exists = True , desc = 'b values file' , mandatory = True )
245
+ logdir = Directory (argstr = '--logdir=%s' )
246
+ n_fibres = traits .Range (
247
+ usedefault = True , low = 1 , default = 2 , argstr = '-n %d' ,
248
+ desc = ('Maximum number of fibres to fit in each voxel' ), mandatory = True )
249
+ model = traits .Enum (1 , 2 , argstr = '-model %d' ,
250
+ desc = ('use monoexponential (1, default, required for '
251
+ 'single-shell) or multiexponential (2, multi-'
252
+ 'shell) model' ))
253
+ fudge = traits .Int (argstr = '-w %d' ,
254
+ desc = 'ARD fudge factor' )
255
+ n_jumps = traits .Int (5000 , argstr = '-j %d' ,
256
+ desc = 'Num of jumps to be made by MCMC' )
257
+ burn_in = traits .Range (low = 0 , default = 0 , argstr = '-b %d' ,
258
+ desc = ('Total num of jumps at start of MCMC to be '
259
+ 'discarded' ))
260
+ sample_every = traits .Range (low = 0 , default = 1 , argstr = '-s %d' ,
261
+ desc = 'Num of jumps for each sample (MCMC)' )
262
+ out_dir = Directory ('bedpostx' , mandatory = True , desc = 'output directory' ,
247
263
usedefault = True , position = 1 , argstr = '%s' )
248
264
gradnonlin = traits .Bool (False , argstr = '-g' , desc = ('consider gradient '
249
265
'nonlinearities, default off' ))
250
266
use_gpu = traits .Bool (False , desc = 'Use the GPU version of bedpostx' )
251
267
252
268
253
- class BEDPOSTX5OutputSpec (FSLXCommandOutputSpec ):
254
- mean_thsamples = OutputMultiPath (File (), desc = ('Mean of '
255
- 'distribution on theta' ))
256
- mean_phsamples = OutputMultiPath (File (), desc = ('Mean of '
257
- 'distribution on phi' ))
258
-
259
- merged_thsamples = OutputMultiPath (File (), desc = ('Samples from '
269
+ class BEDPOSTX5OutputSpec (TraitedSpec ):
270
+ mean_dsamples = File (exists = True , desc = 'Mean of distribution on diffusivity d' )
271
+ mean_fsamples = OutputMultiPath (File (exists = True ), desc = ('Mean of '
272
+ 'distribution on f anisotropy' ))
273
+ mean_S0samples = File (exists = True ,desc = ('Mean of distribution on T2w'
274
+ 'baseline signal intensity S0' ))
275
+ mean_phsamples = OutputMultiPath (File (exists = True ), desc = ('Mean of '
276
+ 'distribution on phi' ))
277
+ mean_thsamples = OutputMultiPath (File (exists = True ), desc = ('Mean of '
278
+ 'distribution on theta' ))
279
+ merged_thsamples = OutputMultiPath (File (exists = True ), desc = ('Samples from '
260
280
'the distribution on theta' ))
261
- merged_phsamples = OutputMultiPath (File (), desc = ('Samples from '
281
+ merged_phsamples = OutputMultiPath (File (exists = True ), desc = ('Samples from '
262
282
'the distribution on phi' ))
263
- merged_fsamples = OutputMultiPath (File (),
283
+ merged_fsamples = OutputMultiPath (File (exists = True ),
264
284
desc = ('Samples from the distribution on '
265
- 'anisotropic volume fraction.' ))
266
- dyads_disp = OutputMultiPath (File (), desc = ('Uncertainty on the '
267
- ' estimated fiber orientation' ))
285
+ 'anisotropic volume fraction' ))
286
+ dyads = OutputMultiPath (File (exists = True ), desc = ('Mean of PDD distribution'
287
+ ' in vector form.' ))
288
+ dyads_dispersion = OutputMultiPath (File (exists = True ), desc = ('Dispersion' ))
268
289
269
290
270
291
class BEDPOSTX5 (FSLXCommand ):
@@ -311,16 +332,10 @@ def _cuda_update(self):
311
332
self ._cmd = self ._default_cmd
312
333
313
334
def _run_interface (self , runtime ):
335
+
314
336
subjectdir = os .path .abspath (self .inputs .out_dir )
315
- out_dir = subjectdir + '.bedpostX'
316
-
317
- if isdefined (self .inputs .force_dir ) and self .inputs .force_dir :
318
- out_dir = os .path .abspath (self .inputs .out_dir )
319
- self ._out_dir = out_dir
320
-
321
- if not os .path .exists (out_dir ):
322
- os .makedirs (out_dir )
323
-
337
+ if not os .path .exists (subjectdir ):
338
+ os .makedirs (subjectdir )
324
339
_ , _ , ext = split_filename (self .inputs .mask )
325
340
copyfile (self .inputs .mask ,
326
341
os .path .join (subjectdir ,
@@ -333,41 +348,47 @@ def _run_interface(self, runtime):
333
348
copyfile (self .inputs .bvecs ,
334
349
os .path .join (subjectdir , 'bvecs' ))
335
350
336
- return super (BEDPOSTX5 , self )._run_interface (runtime )
351
+ retval = super (BEDPOSTX5 , self )._run_interface (runtime )
352
+
353
+ self ._out_dir = subjectdir + '.bedpostX'
354
+ return retval
337
355
338
356
def _list_outputs (self ):
339
357
outputs = self .output_spec ().get ()
340
- out_dir = self ._out_dir
358
+ n_fibres = self .inputs .n_fibres
359
+
360
+ multi_out = ['merged_thsamples' , 'merged_fsamples' ,
361
+ 'merged_phsamples' , 'mean_phsamples' ,
362
+ 'mean_thsamples' , 'mean_fsamples' ,
363
+ 'dyads_dispersion' , 'dyads' ]
364
+
365
+ single_out = ['mean_dsamples' , 'mean_S0samples' ]
366
+
367
+ for k in single_out :
368
+ outputs [k ] = self ._gen_fname (k , cwd = self ._out_dir )
341
369
342
- post_fields = ['merged_thsamples' , 'merged_phsamples' ,
343
- 'merged_fsamples' , 'dyads_disp' ]
344
- for k in post_fields :
345
- outputs [k ] = []
346
370
347
- for i in xrange (1 , self .inputs .n_fibres + 1 ):
348
- outputs ['merged_thsamples' ].append (self ._gen_fname (('merged_th%d'
349
- 'samples' ) % i ,
350
- cwd = out_dir ))
351
- outputs ['merged_phsamples' ].append (self ._gen_fname (('merged_ph%d'
352
- 'samples' ) % i ,
353
- cwd = out_dir ))
354
- outputs ['merged_fsamples' ].append (self ._gen_fname (('merged_f%d'
355
- 'samples' ) % i ,
356
- cwd = out_dir ))
357
- outputs ['mean_thsamples' ].append (self ._gen_fname (('mean_th%d'
358
- 'samples' ) % i ,
359
- cwd = out_dir ))
360
- outputs ['mean_phsamples' ].append (self ._gen_fname (('mean_ph%d'
361
- 'samples' ) % i ,
362
- cwd = out_dir ))
363
- outputs ['dyads_disp' ].append (self ._gen_fname (('dyads%d'
364
- '_dispersion' ) % i , cwd = out_dir ))
365
-
366
- super_out = super (BEDPOSTX5 , self )._list_outputs ()
367
-
368
- for k , v in super_out .iteritems ():
369
- outputs [k ] = v
371
+ for k in multi_out :
372
+ outputs [k ] = []
370
373
374
+ for i in xrange (1 , n_fibres + 1 ):
375
+ outputs ['merged_thsamples' ].append (self ._gen_fname ('merged_th%dsamples' % i ,
376
+ cwd = self ._out_dir ))
377
+ outputs ['merged_fsamples' ].append (self ._gen_fname ('merged_f%dsamples' % i ,
378
+ cwd = self ._out_dir ))
379
+ outputs ['merged_phsamples' ].append (self ._gen_fname ('merged_ph%dsamples' % i ,
380
+ cwd = self ._out_dir ))
381
+
382
+ outputs ['mean_thsamples' ].append (self ._gen_fname ('mean_th%dsamples' % i ,
383
+ cwd = self ._out_dir ))
384
+ outputs ['mean_phsamples' ].append (self ._gen_fname ('mean_ph%dsamples' % i ,
385
+ cwd = self ._out_dir ))
386
+ outputs ['mean_fsamples' ].append (self ._gen_fname ('mean_f%dsamples' % i ,
387
+ cwd = self ._out_dir ))
388
+ outputs ['dyads' ].append (self ._gen_fname ('dyads%d' % i ,
389
+ cwd = self ._out_dir ))
390
+ outputs ['dyads_dispersion' ].append (self ._gen_fname ('dyads%d_dispersion' % i ,
391
+ cwd = self ._out_dir ))
371
392
return outputs
372
393
373
394
0 commit comments