-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhumanfmri_r1_make_directories.m
executable file
·150 lines (140 loc) · 5.29 KB
/
humanfmri_r1_make_directories.m
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function PREPROC = humanfmri_r1_make_directories(subject_code, study_imaging_dir, func_tasks, varargin)
% The function creates directories for dicom files.
%
%
% :Usage:
% ::
% PREPROC = humanfmri_r1_make_directories(subject_code, study_imaging_dir, varargin)
%
%
% :Input:
% ::
% - subject_code the subject code (e.g., 'sub-caps001').
% - study_imaging_dir the directory information for the study imaging data
% (e.g., '/Volumes/habenula/hbmnas/data/CAPS2/Imaging').
% - func_tasks task names corresponding each data.
% (e.g., func_tasks = {'CAPS', 'QUIN', 'ODOR'})
% if some data are missing, just fill in blanks.
% (e.g., func_tasks = {'', 'QUIN', ''} <- only data 2!)
%
%
% :Optional Input:
% ::
% - T2 make in-plane T2 folder
% - no_sbref do not make SBRef folder
% - no_fmap do not make fieldmap folder
% - fmap_enc_dir fieldmap encoding directions
% default: {'ap', 'pa'}
% - no_update do not update PREPROC.mat file
% - func_sess session names corresponding each data.
% (e.g., func_sess = {'visit1', 'visit2', 'visit3'})
% runs without a specified func_task will be ignored.
% (default: [])
% - func_runs run number corresponding each data.
% (e.g., func_runs = [1 2 3], or [1 1 2 2])
% runs without a specified func_task will be ignored.
% (default: 1 .. #func_tasks)
%
%
% :Output:
% ::
% PREPROC.study_imaging_dir
% PREPROC.study_rawdata_dir
% PREPROC.subject_code
% PREPROC.subject_dir
% PREPROC.dicom_anat_dir
% PREPROC.dicom_func_bold_dir
% PREPROC.dicom_func_sbref_dir
% PREPROC.dicom_fmap_dir (if selected)
%
%
% :Example:
% ::
%
%
% ..
% Author and copyright information:
%
% Copyright (C) Jan 2019 Choong-Wan Woo & Jae-Joong Lee
%
% 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/>.
% ..
fprintf('\n\n\n');
make_T2 = false;
make_sbref = true;
make_fmap = true;
fmap_enc_dir = {'ap', 'pa'};
do_update = true;
func_sess = [];
func_runs = 1:numel(func_tasks);
for i = 1:length(varargin)
if ischar(varargin{i})
switch varargin{i}
case {'T2'}
make_T2 = true;
case {'no_sbref'}
make_sbref = false;
case {'no_fmap'}
make_fmap = false;
case {'fmap_enc_dir'}
fmap_enc_dir = varargin{i+1};
case {'no_update'}
do_update = false;
case {'func_sess'}
func_sess = varargin{i+1};
case {'func_runs'}
func_runs = varargin{i+1};
end
end
end
subject_dir = fullfile(study_imaging_dir, 'raw', subject_code);
if do_update && exist(fullfile(subject_dir, 'PREPROC.mat')) == 2 % do update & mat file exist
fprintf('Load existing PREPROC.mat and update it.\n');
PREPROC = save_load_PREPROC(subject_dir, 'load'); % load PREPROC
end
PREPROC.study_imaging_dir = study_imaging_dir;
PREPROC.study_rawdata_dir = fullfile(study_imaging_dir, 'raw');
PREPROC.subject_code = subject_code;
PREPROC.subject_dir = subject_dir;
print_header('Make directories for containing DICOM images', PREPROC.subject_code);
PREPROC.dicom_anat_dir{1, 1} = fullfile(PREPROC.subject_dir, 'dicom', 'anat', 'T1w');
system(['mkdir -p ' PREPROC.dicom_anat_dir{1}]);
if make_T2
PREPROC.dicom_anat_dir{2, 1} = fullfile(PREPROC.subject_dir, 'dicom', 'anat', 'inplaneT2');
system(['mkdir -p ' PREPROC.dicom_anat_dir{2}]);
end
for i = 1:numel(func_tasks)
if ~isempty(func_tasks{i})
if ~isempty(func_sess)
funcprefix = sprintf('ses-%s_task-%s_run-%02d', func_sess{i}, func_tasks{i}, func_runs(i));
else
funcprefix = sprintf('task-%s_run-%02d', func_tasks{i}, func_runs(i));
end
PREPROC.dicom_func_bold_dir{i, 1} = fullfile(PREPROC.subject_dir, 'dicom', 'func', sprintf('%s_bold', funcprefix));
system(['mkdir -p ' PREPROC.dicom_func_bold_dir{i}]);
if make_sbref
PREPROC.dicom_func_sbref_dir{i, 1} = fullfile(PREPROC.subject_dir, 'dicom', 'func', sprintf('%s_sbref', funcprefix));
system(['mkdir -p ' PREPROC.dicom_func_sbref_dir{i}]);
end
end
end
if make_fmap
for i = 1:numel(fmap_enc_dir)
PREPROC.dicom_fmap_dir{i, 1} = fullfile(PREPROC.subject_dir, 'dicom', 'fmap', sprintf('dir-%s_epi', fmap_enc_dir{i}));
system(['mkdir -p ' PREPROC.dicom_fmap_dir{i}]);
end
end
save_load_PREPROC(PREPROC.subject_dir, 'save', PREPROC); % save PREPROC
fprintf('\n\n\n');
end