Skip to content

Commit e869474

Browse files
committed
simple FS example
1 parent bbebae6 commit e869474

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

examples/amri_freesurfer.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import nipype.pipeline.engine as pe
2+
import nipype.interfaces.io as nio
3+
import nipype.interfaces.utility as util
4+
import os
5+
from nipype.interfaces.freesurfer.preprocess import ReconAll
6+
7+
subject_list = ['s1', 's3']
8+
data_dir = os.path.abspath('data')
9+
subjects_dir = os.path.abspath('amri_freesurfer_tutorial/subjects_dir')
10+
11+
wf = pe.Workflow(name="l1workflow")
12+
wf.base_dir = os.path.abspath('amri_freesurfer_tutorial/workdir')
13+
14+
datasource = pe.MapNode(interface=nio.DataGrabber(infields=['subject_id'],
15+
outfields=['struct']),
16+
name='datasource',
17+
iterfield=['subject_id'])
18+
datasource.inputs.base_directory = data_dir
19+
datasource.inputs.template = '%s/%s.nii'
20+
datasource.inputs.template_args = dict(struct=[['subject_id', 'struct']])
21+
datasource.inputs.subject_id = subject_list
22+
23+
recon_all = pe.MapNode(interface=ReconAll(), name='recon_all',
24+
iterfield=['subject_id'])
25+
recon_all.inputs.subject_id = subject_list
26+
27+
wf.connect(datasource, 'struct', recon_all, 'T1_files')
28+
29+
30+
def MakeAverageSubject(subjects_dir, subjects_list, out_name):
31+
from nipype.interfaces.base import CommandLine
32+
mas = CommandLine(command='make_average_subject')
33+
mas.inputs.args = "--sdir %s --subjects %s --out %s"%(subjects_dir, " "%subject_list, out_name)
34+
mas.run()
35+
return subjects_dir, out_name
36+
37+
average = pe.Node(interface=util.Function(input_names=['subjects_dir',
38+
'subjects_list',
39+
'out_name'],
40+
output_names=['subjects_dir',
41+
'out_name'],
42+
function=MakeAverageSubject),
43+
name="average")
44+
45+
average.inputs.out_name = "average"
46+
47+
wf.connect(recon_all, 'subjects_dir', average, 'subjects_dir')
48+
wf.connect(recon_all, 'subject_id', average, 'subjects_list')
49+
50+
wf.run("MultiProc", plugin_args={'n_procs': 4})

0 commit comments

Comments
 (0)