1
1
#!/usr/bin/env python
2
2
"""
3
+ ================================================================
4
+ rsfMRI: AFNI, ANTS, DicomStack, FreeSurfer, FSL, Nipy, aCompCorr
5
+ ================================================================
6
+
7
+
3
8
A preprocessing workflow for Siemens resting state data.
4
9
5
10
This workflow makes use of:
12
17
- FSL
13
18
- NiPy
14
19
15
- For example:
20
+ For example::
16
21
17
- python rsfmri_preprocessing.py -d /data/12345-34-1.dcm -f /data/Resting.nii
22
+ python rsfmri_preprocessing.py -d /data/12345-34-1.dcm -f /data/Resting.nii
18
23
-s subj001 -n 2 --despike -o output
19
24
-p PBS --plugin_args "dict(qsub_args='-q many')"
25
+
26
+ This workflow takes resting timeseries and a Siemens dicom file corresponding
27
+ to it and preprocesses it to produce timeseries coordinates or grayordinates.
28
+
29
+ This workflow also requires 2mm subcortical atlas and templates that are
30
+ available from:
31
+
32
+ http://mindboggle.info/data.html
33
+
34
+ specifically the 2mm versions of:
35
+
36
+ - `Joint Fusion Atlas <http://mindboggle.info/data/atlases/jointfusion/OASIS-TRT-20_DKT31_CMA_jointfusion_labels_in_MNI152_2mm.nii.gz>`_
37
+ - `MNI template <http://mindboggle.info/data/templates/ants/OASIS-TRT-20_template_in_MNI152_2mm.nii.gz>`_
38
+
39
+ The 2mm version was generated with::
40
+
41
+ >>> from nipype import freesurfer as fs
42
+ >>> rs = fs.Resample()
43
+ >>> rs.inputs.in_file = 'OASIS-TRT-20_DKT31_CMA_jointfusion_labels_in_MNI152.nii.gz'
44
+ >>> rs.inputs.resampled_file = 'OASIS-TRT-20_DKT31_CMA_jointfusion_labels_in_MNI152_2mm.nii.gz'
45
+ >>> rs.inputs.voxel_size = (2., 2., 2.)
46
+ >>> rs.inputs.args = '-rt nearest -ns 1'
47
+ >>> res = rs.run()
48
+
20
49
"""
21
50
22
51
import os
23
52
53
+ from nipype .interfaces .base import CommandLine
54
+ CommandLine .set_default_terminal_output ('file' )
55
+
24
56
from nipype import (ants , afni , fsl , freesurfer , nipy , Function , DataSink )
25
57
from nipype import Workflow , Node , MapNode
26
58
@@ -75,7 +107,6 @@ def median(in_files):
75
107
76
108
out_file: a 3D Nifti file
77
109
"""
78
-
79
110
average = None
80
111
for idx , filename in enumerate (filename_to_list (in_files )):
81
112
img = nb .load (filename )
@@ -138,7 +169,6 @@ def build_filter1(motion_params, comp_norm, outliers):
138
169
Returns
139
170
-------
140
171
components_file: a text file containing all the regressors
141
-
142
172
"""
143
173
out_files = []
144
174
for idx , filename in enumerate (filename_to_list (motion_params )):
@@ -191,8 +221,7 @@ def extract_subrois(timeseries_file, label_file, indices):
191
221
192
222
timeseries_file: a 4D Nifti file
193
223
label_file: a 3D file containing rois in the same space/size of the 4D file
194
- indices: a list of indices for ROIs to extract. Currently a dictionary
195
- mapping freesurfer indices to CMA/Label Fusion indices are being used
224
+ indices: a list of indices for ROIs to extract.
196
225
197
226
Returns
198
227
-------
@@ -206,8 +235,8 @@ def extract_subrois(timeseries_file, label_file, indices):
206
235
rois = roiimg .get_data ()
207
236
out_ts_file = os .path .join (os .getcwd (), 'subcortical_timeseries.txt' )
208
237
with open (out_ts_file , 'wt' ) as fp :
209
- for fsindex , cmaindex in sorted ( indices . items ()) :
210
- ijk = np .nonzero (rois == cmaindex )
238
+ for fsindex in indices :
239
+ ijk = np .nonzero (rois == fsindex )
211
240
ts = data [ijk ]
212
241
for i0 , row in enumerate (ts ):
213
242
fp .write ('%d,%d,%d,%d,' % (fsindex , ijk [0 ][i0 ],
@@ -557,7 +586,6 @@ def create_workflow(files,
557
586
reg .inputs .fixed_image = \
558
587
os .path .abspath ('OASIS-TRT-20_template_to_MNI152_2mm.nii.gz' )
559
588
reg .inputs .num_threads = 4
560
- reg .inputs .terminal_output = 'file'
561
589
reg .plugin_args = {'qsub_args' : '-l nodes=1:ppn=4' }
562
590
563
591
# Convert T1.mgz to nifti for using with ANTS
@@ -610,10 +638,8 @@ def create_workflow(files,
610
638
imports = imports ),
611
639
iterfield = ['timeseries_file' ],
612
640
name = 'getsubcortts' )
613
- ts2txt .inputs .indices = dict (zip ([8 ] + range (10 , 14 ) + [17 , 18 , 26 , 47 ] +
614
- range (49 , 55 ) + [58 ],
615
- [39 , 60 , 37 , 58 , 56 , 48 , 32 , 30 ,
616
- 38 , 59 , 36 , 57 , 55 , 47 , 31 , 23 ]))
641
+ ts2txt .inputs .indices = [8 ] + range (10 , 14 ) + [17 , 18 , 26 , 47 ] + \
642
+ range (49 , 55 ) + [58 ]
617
643
ts2txt .inputs .label_file = \
618
644
os .path .abspath (('OASIS-TRT-20_DKT31_CMA_jointfusion_labels_in_MNI152'
619
645
'_2mm.nii.gz' ))
0 commit comments