-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathfetch_data.py
66 lines (50 loc) · 2.34 KB
/
fetch_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (C) 2017 Sarah Parisot <[email protected]>, , Sofia Ira Ktena <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from nilearn import datasets
import ABIDEParser as Reader
import os
import shutil
# Selected pipeline
pipeline = 'cpac'
# Input data variables
num_subjects = 871 # Number of subjects
root_folder = '/path/to/data/'
data_folder = os.path.join(root_folder, 'ABIDE_pcp/cpac/filt_noglobal')
# Files to fetch
files = ['rois_ho']
filemapping = {'func_preproc': 'func_preproc.nii.gz',
'rois_ho': 'rois_ho.1D'}
if not os.path.exists(data_folder): os.makedirs(data_folder)
shutil.copyfile('./subject_IDs.txt', os.path.join(data_folder, 'subject_IDs.txt'))
# Download database files
abide = datasets.fetch_abide_pcp(data_dir=root_folder, n_subjects=num_subjects, pipeline=pipeline,
band_pass_filtering=True, global_signal_regression=False, derivatives=files)
subject_IDs = Reader.get_ids(num_subjects)
subject_IDs = subject_IDs.tolist()
# Create a folder for each subject
for s, fname in zip(subject_IDs, Reader.fetch_filenames(subject_IDs, files[0])):
subject_folder = os.path.join(data_folder, s)
if not os.path.exists(subject_folder):
os.mkdir(subject_folder)
# Get the base filename for each subject
base = fname.split(files[0])[0]
# Move each subject file to the subject folder
for fl in files:
if not os.path.exists(os.path.join(subject_folder, base + filemapping[fl])):
shutil.move(base + filemapping[fl], subject_folder)
time_series = Reader.get_timeseries(subject_IDs, 'ho')
# Compute and save connectivity matrices
for i in range(len(subject_IDs)):
Reader.subject_connectivity(time_series[i], subject_IDs[i], 'ho', 'correlation')