Skip to content

Commit 3ec3ae2

Browse files
author
David Ellis
committed
ENH: Starting to add workflows to nipype.
1 parent fd224fb commit 3ec3ae2

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

examples/smri_fsreconall.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
"""
3+
================
4+
sMRI: FreeSurfer
5+
================
6+
7+
This script, smri_fsreconall.py, demonstrates the ability to use the
8+
reconall nipype workflow with a set of subjects and then make an average
9+
subject::
10+
11+
python smri_fsreconall.py
12+
13+
Import necessary modules from nipype.
14+
"""
15+
16+
import os
17+
18+
import nipype.pipeline.engine as pe
19+
import nipype.interfaces.io as nio
20+
from nipype.workflows.smri.freesurfer import create_reconall_workflow
21+
from nipype.interfaces.freesurfer.utils import MakeAverageSubject
22+
23+
24+
subject_list = ['s1', 's3']
25+
data_dir = os.path.abspath('data')
26+
subjects_dir = os.path.abspath('amri_freesurfer_tutorial/subjects_dir')
27+
28+
wf = pe.Workflow(name="l1workflow")
29+
wf.base_dir = os.path.abspath('amri_freesurfer_tutorial/workdir')
30+
31+
"""
32+
Grab data
33+
"""
34+
35+
datasource = pe.MapNode(interface=nio.DataGrabber(infields=['subject_id'],
36+
outfields=['struct']),
37+
name='datasource',
38+
iterfield=['subject_id'])
39+
datasource.inputs.base_directory = data_dir
40+
datasource.inputs.template = '%s/%s.nii'
41+
datasource.inputs.template_args = dict(struct=[['subject_id', 'struct']])
42+
datasource.inputs.subject_id = subject_list
43+
datasource.inputs.sort_filelist = True
44+
45+
"""
46+
Run recon-all
47+
"""
48+
49+
recon_all = create_reconall_workflow(subjects_dir=subjects_dir)
50+
pe.MapNode(interface=ReconAllWF(), name='recon_all',
51+
iterfield=['subject_id', 'T1_files'])
52+
recon_all.inputs.subject_id = subject_list
53+
if not os.path.exists(subjects_dir):
54+
os.mkdir(subjects_dir)
55+
recon_all.inputs.subjects_dir = subjects_dir
56+
57+
wf.connect(datasource, 'struct', recon_all, 'T1_files')
58+
59+
"""
60+
Make average subject
61+
"""
62+
63+
average = pe.Node(interface=MakeAverageSubject(), name="average")
64+
average.inputs.subjects_dir = subjects_dir
65+
66+
wf.connect(recon_all, 'subject_id', average, 'subjects_ids')
67+
68+
wf.run("MultiProc", plugin_args={'n_procs': 4})

0 commit comments

Comments
 (0)