58
58
59
59
mlab .MatlabCommand .set_default_matlab_cmd ("matlab -nodisplay" )
60
60
# If SPM is not in your MATLAB path you should add it here
61
- # mlab.MatlabCommand.set_default_paths('/path/to/your/spm8 ')
61
+ mlab .MatlabCommand .set_default_paths ('/cm/shared/openmind/spm/spm12b/spm12b_r5918/ ' )
62
62
63
63
from nipype .algorithms .rapidart import ArtifactDetect
64
- from nipype .interfaces .utility import Rename
64
+ from nipype .interfaces .utility import Rename , Merge
65
65
from nipype .utils .filemanip import filename_to_list
66
66
from nipype .interfaces .io import DataSink
67
67
@@ -366,29 +366,34 @@ def create_workflow(files,
366
366
(smooth , art , [('smoothed_files' , 'realigned_files' )]),
367
367
])
368
368
369
+ def selectN (files , N = 1 ):
370
+ from nipype .utils .filemanip import filename_to_list , list_to_filename
371
+ return list_to_filename (filename_to_list (files )[:N ])
372
+
373
+ mask = Node (fsl .BET (), name = 'getmask' )
374
+ mask .inputs .mask = True
375
+ wf .connect (normalize_func , ('normalized_files' , selectN , 1 ), mask , 'in_file' )
369
376
# get segmentation in normalized functional space
370
377
371
378
segment .inputs .wm_output_type = [False , False , True ]
372
379
segment .inputs .csf_output_type = [False , False , True ]
380
+ segment .inputs .gm_output_type = [False , False , True ]
373
381
374
382
def merge_files (in1 , in2 ):
375
383
out_files = filename_to_list (in1 )
376
384
out_files .extend (filename_to_list (in2 ))
377
385
return out_files
378
386
379
- merge = Node (Function (input_names = ['in1' , 'in2' ],
380
- output_names = ['out_file' ],
381
- function = merge_files ,
382
- imports = imports ),
383
- name = 'merge' )
387
+ merge = Node (Merge (3 ), name = 'merge' )
384
388
wf .connect (segment , 'native_wm_image' , merge , 'in1' )
385
389
wf .connect (segment , 'native_csf_image' , merge , 'in2' )
390
+ wf .connect (segment , 'native_gm_image' , merge , 'in3' )
386
391
387
392
normalize_segs = Node (interface = spm .Normalize (), name = "normalize_segs" )
388
393
normalize_segs .inputs .jobtype = "write"
389
394
normalize_segs .inputs .write_voxel_sizes = [2. , 2. , 2. ]
390
395
391
- wf .connect (merge , 'out_file ' , normalize_segs , 'apply_to_files' )
396
+ wf .connect (merge , 'out ' , normalize_segs , 'apply_to_files' )
392
397
wf .connect (segment , 'transformation_mat' , normalize_segs , 'parameter_file' )
393
398
394
399
# binarize and erode
@@ -448,7 +453,7 @@ def merge_files(in1, in2):
448
453
createfilter2 .inputs .num_components = num_components
449
454
wf .connect (createfilter1 , 'out_files' , createfilter2 , 'extra_regressors' )
450
455
wf .connect (filter1 , 'out_res' , createfilter2 , 'realigned_file' )
451
- wf .connect (bin_and_erode , 'out_file' , createfilter2 , 'mask_file' )
456
+ wf .connect (bin_and_erode , ( 'out_file' , selectN , 2 ) , createfilter2 , 'mask_file' )
452
457
453
458
# Filter noise components from unsmoothed data
454
459
filter2 = MapNode (fsl .GLM (out_f_name = 'F.nii' ,
@@ -460,7 +465,7 @@ def merge_files(in1, in2):
460
465
wf .connect (normalize_func , ('normalized_files' , rename , '_unsmooth_cleaned' ),
461
466
filter2 , 'out_res_name' )
462
467
wf .connect (createfilter2 , 'out_files' , filter2 , 'design' )
463
- # wf.connect(masktransform , 'transformed_file ', filter2, 'mask')
468
+ wf .connect (mask , 'mask_file ' , filter2 , 'mask' )
464
469
465
470
# Filter noise components from smoothed data
466
471
filter3 = MapNode (fsl .GLM (out_f_name = 'F.nii' ,
@@ -472,7 +477,7 @@ def merge_files(in1, in2):
472
477
filter3 , 'out_res_name' )
473
478
wf .connect (smooth , 'smoothed_files' , filter3 , 'in_file' )
474
479
wf .connect (createfilter2 , 'out_files' , filter3 , 'design' )
475
- # wf.connect(masktransform , 'transformed_file ', filter3, 'mask')
480
+ wf .connect (mask , 'mask_file ' , filter3 , 'mask' )
476
481
477
482
# Bandpass filter the data
478
483
bandpass1 = Node (Function (input_names = ['files' , 'lowpass_freq' ,
@@ -504,12 +509,13 @@ def merge_files(in1, in2):
504
509
datasink .inputs .container = subject_id
505
510
#datasink.inputs.substitutions = [('_target_subject_', '')]
506
511
#datasink.inputs.regexp_substitutions = (r'(/_.*(\d+/))', r'/run\2')
507
- wf .connect (realign , 'par_file ' , datasink , 'resting.qa.motion' )
512
+ wf .connect (realign , 'realignment_parameters ' , datasink , 'resting.qa.motion' )
508
513
wf .connect (art , 'norm_files' , datasink , 'resting.qa.art.@norm' )
509
514
wf .connect (art , 'intensity_files' , datasink , 'resting.qa.art.@intensity' )
510
515
wf .connect (art , 'outlier_files' , datasink , 'resting.qa.art.@outlier_files' )
511
- wf .connect (smooth , 'out_file ' , datasink , 'resting.timeseries.fullpass' )
516
+ wf .connect (smooth , 'smoothed_files ' , datasink , 'resting.timeseries.fullpass' )
512
517
wf .connect (bin_and_erode , 'out_file' , datasink , 'resting.mask_files' )
518
+ wf .connect (mask , 'mask_file' , datasink , 'resting.mask_files.@brainmask' )
513
519
wf .connect (filter1 , 'out_f' , datasink , 'resting.qa.compmaps.@mc_F' )
514
520
wf .connect (filter1 , 'out_pf' , datasink , 'resting.qa.compmaps.@mc_pF' )
515
521
wf .connect (filter2 , 'out_f' , datasink , 'resting.qa.compmaps' )
0 commit comments