2222import nipype .interfaces .spm as spm # spm
2323import nipype .workflows .fmri .spm as spm_wf # spm
2424import nipype .interfaces .fsl as fsl # fsl
25- import nipype .interfaces . utility as util # utility
25+ from nipype .interfaces import utility as niu # Utilities
2626import nipype .pipeline .engine as pe # pypeline engine
2727import nipype .algorithms .rapidart as ra # artifact detection
2828import nipype .algorithms .modelgen as model # model specification
6868and register all images to the mean image.
6969"""
7070
71- realign = pe .Node (interface = spm .Realign (), name = "realign" )
71+ realign = pe .Node (spm .Realign (), name = "realign" )
7272realign .inputs .register_to_mean = True
7373
7474"""Use :class:`nipype.algorithms.rapidart` to determine which of the
7575images in the functional series are outliers based on deviations in
7676intensity or movement.
7777"""
7878
79- art = pe .Node (interface = ra .ArtifactDetect (), name = "art" )
79+ art = pe .Node (ra .ArtifactDetect (), name = "art" )
8080art .inputs .use_differences = [True , False ]
8181art .inputs .use_norm = True
8282art .inputs .norm_threshold = 1
8888:class:`nipype.interfaces.fsl.BET`.
8989"""
9090
91- skullstrip = pe .Node (interface = fsl .BET (), name = "skullstrip" )
91+ skullstrip = pe .Node (fsl .BET (), name = "skullstrip" )
9292skullstrip .inputs .mask = True
9393
9494"""Use :class:`nipype.interfaces.spm.Coregister` to perform a rigid
9595body registration of the functional data to the structural data.
9696"""
9797
98- coregister = pe .Node (interface = spm .Coregister (), name = "coregister" )
98+ coregister = pe .Node (spm .Coregister (), name = "coregister" )
9999coregister .inputs .jobtype = 'estimate'
100100
101101
134134:class:`nipype.interfaces.spm.SpecifyModel`.
135135"""
136136
137- modelspec = pe .Node (interface = model .SpecifySPMModel (), name = "modelspec" )
137+ modelspec = pe .Node (model .SpecifySPMModel (), name = "modelspec" )
138138modelspec .inputs .concatenate_runs = True
139139
140140"""Generate a first level SPM.mat file for analysis
141141:class:`nipype.interfaces.spm.Level1Design`.
142142"""
143143
144- level1design = pe .Node (interface = spm .Level1Design (), name = "level1design" )
144+ level1design = pe .Node (spm .Level1Design (), name = "level1design" )
145145level1design .inputs .bases = {'hrf' : {'derivs' : [0 , 0 ]}}
146146
147147"""Use :class:`nipype.interfaces.spm.EstimateModel` to determine the
148148parameters of the model.
149149"""
150150
151- level1estimate = pe .Node (interface = spm .EstimateModel (), name = "level1estimate" )
151+ level1estimate = pe .Node (spm .EstimateModel (), name = "level1estimate" )
152152level1estimate .inputs .estimation_method = {'Classical' : 1 }
153153
154154"""Use :class:`nipype.interfaces.spm.EstimateContrast` to estimate the
155155first level contrasts specified in a few steps above.
156156"""
157157
158- contrastestimate = pe .Node (interface = spm .EstimateContrast (), name = "contrastestimate" )
158+ contrastestimate = pe .Node (spm .EstimateContrast (), name = "contrastestimate" )
159159
160160"""Use :class: `nipype.interfaces.utility.Select` to select each contrast for
161161reporting.
162162"""
163163
164- selectcontrast = pe .Node (interface = util .Select (), name = "selectcontrast" )
164+ selectcontrast = pe .Node (niu .Select (), name = "selectcontrast" )
165165
166166"""Use :class:`nipype.interfaces.fsl.Overlay` to combine the statistical output of
167167the contrast estimate and a background image into one volume.
168168"""
169169
170- overlaystats = pe .Node (interface = fsl .Overlay (), name = "overlaystats" )
170+ overlaystats = pe .Node (fsl .Overlay (), name = "overlaystats" )
171171overlaystats .inputs .stat_thresh = (3 , 10 )
172172overlaystats .inputs .show_negative_stats = True
173173overlaystats .inputs .auto_thresh_bg = True
176176statistical volumes for a report of the first-level results.
177177"""
178178
179- slicestats = pe .Node (interface = fsl .Slicer (), name = "slicestats" )
179+ slicestats = pe .Node (fsl .Slicer (), name = "slicestats" )
180180slicestats .inputs .all_axial = True
181181slicestats .inputs .image_width = 750
182182
232232"""
233233
234234# Specify the location of the data.
235- data_dir = os .path .abspath ('data' )
235+ # data_dir = os.path.abspath('data')
236236# Specify the subject directories
237237subject_list = ['s1' , 's3' ]
238238# Map field names to individual subject runs.
239239info = dict (func = [['subject_id' , ['f3' , 'f5' , 'f7' , 'f10' ]]],
240240 struct = [['subject_id' , 'struct' ]])
241241
242- infosource = pe .Node (interface = util .IdentityInterface (fields = ['subject_id' ]), name = "infosource" )
242+ infosource = pe .Node (niu .IdentityInterface (fields = ['subject_id' ]), name = "infosource" )
243243
244244"""Here we set up iteration over all the subjects. The following line
245245is a particular example of the flexibility of the system. The
260260functionality.
261261"""
262262
263- datasource = pe .Node (interface = nio .DataGrabber (infields = ['subject_id' ],
263+ inputnode = pe .Node (niu .IdentityInterface (fields = ['in_data' ]), name = 'inputnode' )
264+ datasource = pe .Node (nio .DataGrabber (infields = ['subject_id' ],
264265 outfields = ['func' , 'struct' ]),
265266 name = 'datasource' )
266- datasource .inputs .base_directory = data_dir
267267datasource .inputs .template = '%s/%s.nii'
268268datasource .inputs .template_args = info
269269datasource .inputs .sort_filelist = True
270270
271271"""We need to create a separate workflow to make the DARTEL template
272272"""
273273
274- datasource_dartel = pe .MapNode (interface = nio .DataGrabber (infields = ['subject_id' ],
274+ datasource_dartel = pe .MapNode (nio .DataGrabber (infields = ['subject_id' ],
275275 outfields = ['struct' ]),
276276 name = 'datasource_dartel' ,
277277 iterfield = ['subject_id' ])
278- datasource_dartel .inputs .base_directory = data_dir
279278datasource_dartel .inputs .template = '%s/%s.nii'
280279datasource_dartel .inputs .template_args = dict (struct = [['subject_id' , 'struct' ]])
281280datasource_dartel .inputs .sort_filelist = True
285284This way we will be able to pick the right field flows later.
286285"""
287286
288- rename_dartel = pe .MapNode (util .Rename (format_string = "subject_id_%(subject_id)s_struct" ),
287+ rename_dartel = pe .MapNode (niu .Rename (format_string = "subject_id_%(subject_id)s_struct" ),
289288 iterfield = ['in_file' , 'subject_id' ],
290289 name = 'rename_dartel' )
291290rename_dartel .inputs .subject_id = subject_list
@@ -307,7 +306,7 @@ def pickFieldFlow(dartel_flow_fields, subject_id):
307306
308307 raise Exception
309308
310- pick_flow = pe .Node (util .Function (input_names = ['dartel_flow_fields' ,
309+ pick_flow = pe .Node (niu .Function (input_names = ['dartel_flow_fields' ,
311310 'subject_id' ],
312311 output_names = ['dartel_flow_field' ],
313312 function = pickFieldFlow ),
@@ -399,7 +398,9 @@ def subjectinfo(subject_id):
399398level1 = pe .Workflow (name = "level1" )
400399level1 .base_dir = os .path .abspath ('spm_dartel_tutorial/workingdir' )
401400
402- level1 .connect ([(datasource_dartel , rename_dartel , [('struct' , 'in_file' )]),
401+ level1 .connect ([(inputnode , datasource , [('in_data' , 'base_directory' )]),
402+ (inputnode , datasource_dartel , [('in_data' , 'base_directory' )]),
403+ (datasource_dartel , rename_dartel , [('struct' , 'in_file' )]),
403404 (rename_dartel , dartel_workflow , [('out_file' , 'inputspec.structural_files' )]),
404405
405406 (infosource , datasource , [('subject_id' , 'subject_id' )]),
@@ -437,9 +438,9 @@ def subjectinfo(subject_id):
437438the mean image would be copied to that directory.
438439"""
439440
440- datasink = pe .Node (interface = nio .DataSink (), name = "datasink" )
441+ datasink = pe .Node (nio .DataSink (), name = "datasink" )
441442datasink .inputs .base_directory = os .path .abspath ('spm_dartel_tutorial/l1output' )
442- report = pe .Node (interface = nio .DataSink (), name = 'report' )
443+ report = pe .Node (nio .DataSink (), name = 'report' )
443444report .inputs .base_directory = os .path .abspath ('spm_dartel_tutorial/report' )
444445report .inputs .parameterization = False
445446
@@ -501,10 +502,10 @@ def getstripdir(subject_id):
501502"""
502503
503504# setup a 1-sample t-test node
504- onesamplettestdes = pe .Node (interface = spm .OneSampleTTestDesign (), name = "onesampttestdes" )
505- l2estimate = pe .Node (interface = spm .EstimateModel (), name = "level2estimate" )
505+ onesamplettestdes = pe .Node (spm .OneSampleTTestDesign (), name = "onesampttestdes" )
506+ l2estimate = pe .Node (spm .EstimateModel (), name = "level2estimate" )
506507l2estimate .inputs .estimation_method = {'Classical' : 1 }
507- l2conestimate = pe .Node (interface = spm .EstimateContrast (), name = "level2conestimate" )
508+ l2conestimate = pe .Node (spm .EstimateContrast (), name = "level2conestimate" )
508509cont1 = ('Group' , 'T' , ['mean' ], [1 ])
509510l2conestimate .inputs .contrasts = [cont1 ]
510511l2conestimate .inputs .group_contrast = True
0 commit comments