Skip to content

Commit 8903396

Browse files
committed
fix: removed cma to freesurfer mapping, updated docs and pointed to atlas/template downloads
1 parent e75b621 commit 8903396

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

examples/rsfmri_preprocessing.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env python
22
"""
3+
================================================================
4+
rsfMRI: AFNI, ANTS, DicomStack, FreeSurfer, FSL, Nipy, aCompCorr
5+
================================================================
6+
7+
38
A preprocessing workflow for Siemens resting state data.
49
510
This workflow makes use of:
@@ -12,15 +17,42 @@
1217
- FSL
1318
- NiPy
1419
15-
For example:
20+
For example::
1621
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
1823
-s subj001 -n 2 --despike -o output
1924
-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+
2049
"""
2150

2251
import os
2352

53+
from nipype.interfaces.base import CommandLine
54+
CommandLine.set_default_terminal_output('file')
55+
2456
from nipype import (ants, afni, fsl, freesurfer, nipy, Function, DataSink)
2557
from nipype import Workflow, Node, MapNode
2658

@@ -75,7 +107,6 @@ def median(in_files):
75107
76108
out_file: a 3D Nifti file
77109
"""
78-
79110
average = None
80111
for idx, filename in enumerate(filename_to_list(in_files)):
81112
img = nb.load(filename)
@@ -138,7 +169,6 @@ def build_filter1(motion_params, comp_norm, outliers):
138169
Returns
139170
-------
140171
components_file: a text file containing all the regressors
141-
142172
"""
143173
out_files = []
144174
for idx, filename in enumerate(filename_to_list(motion_params)):
@@ -191,8 +221,7 @@ def extract_subrois(timeseries_file, label_file, indices):
191221
192222
timeseries_file: a 4D Nifti file
193223
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.
196225
197226
Returns
198227
-------
@@ -206,8 +235,8 @@ def extract_subrois(timeseries_file, label_file, indices):
206235
rois = roiimg.get_data()
207236
out_ts_file = os.path.join(os.getcwd(), 'subcortical_timeseries.txt')
208237
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)
211240
ts = data[ijk]
212241
for i0, row in enumerate(ts):
213242
fp.write('%d,%d,%d,%d,' % (fsindex, ijk[0][i0],
@@ -557,7 +586,6 @@ def create_workflow(files,
557586
reg.inputs.fixed_image = \
558587
os.path.abspath('OASIS-TRT-20_template_to_MNI152_2mm.nii.gz')
559588
reg.inputs.num_threads = 4
560-
reg.inputs.terminal_output = 'file'
561589
reg.plugin_args = {'qsub_args': '-l nodes=1:ppn=4'}
562590

563591
# Convert T1.mgz to nifti for using with ANTS
@@ -610,10 +638,8 @@ def create_workflow(files,
610638
imports=imports),
611639
iterfield=['timeseries_file'],
612640
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]
617643
ts2txt.inputs.label_file = \
618644
os.path.abspath(('OASIS-TRT-20_DKT31_CMA_jointfusion_labels_in_MNI152'
619645
'_2mm.nii.gz'))

0 commit comments

Comments
 (0)