-
Notifications
You must be signed in to change notification settings - Fork 2
/
ukbb_grabber_40k.m
188 lines (162 loc) · 5.61 KB
/
ukbb_grabber_40k.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
function files = ukbb_grabber(path_data,opt)
% Grab the T1w+fMRI scans in a BIDS dataset
% http://bids.neuroimaging.io
%
% SYNTAX:
% FILES = NIAK_GRAB_BIDS(PATH_DATA,OPT)
%
% _________________________________________________________________________
% INPUTS:
%
% PATH_DATA
% (string, default [pwd filesep], aka './') full path to one site of
% a BIDS dataset
%
% OPT
% (structure) grabber options
%
% FUNC_HINT
% (string) A hint to pick one out of many fmri input for exemple
% if the fmri study includes "sub-XX_task-rest-a_hint_bold.nii.gz"
% and "sub-XX_task-rest-a_thing_bold.nii.gz" and the "hint" flavor
% needs to be selected, opt.func_hint = 'hint', would do the trick.
%
% ANAT_HINT
% (string, defaut = T1w) A hint to pick one out of many anat input.
% If no hint is give the first file to be listed by the OS will be picked.
% If you want to select a different input than T1w, let say
% sub-XX_ses-XX_FLAIR_run-001.nii.gz input the following option:
% opt.anat_hint = "FLAIR"
%
% TASK_TYPE
% (string, default = rest) The type of task, explicitely named in bids
% file name
%
% MAX_SUBJECTS
% (int, default = 0) 0 return all subjects. Used to put an upper limit
% on the number of subjects that are returned (nice an simple
% debugging feature).
%
% SUBJECT_LIST
% (cellarray of int) The only subject to be returned
%
% _________________________________________________________________________
% OUTPUTS:
%
% FILES
% (structure) with the following fields, ready to feed into
% NIAK_PIPELINE_FMRI_PREPROCESS :
%
% <SUBJECT>.FMRI.<SESSION>.<RUN>
% (string) a list of fMRI datasets, acquired in the
% same session (small displacements).
% The field names <SUBJECT> and <SESSION> can be any arbitrary
% strings. The <RUN> input is optional
%
% <SUBJECT>.ANAT
% (string) anatomical volume, from the same subject as in
% FILES_IN.<SUBJECT>.FMRI
% _________________________________________________________________________
% SEE ALSO:
% NIAK_PIPELINE_FMRI_PREPROCESS
%
% _________________________________________________________________________
% COMMENTS:
%
% Copyright (c) P-O Quirion, Pierre Bellec
% Centre de recherche de l'institut de Griatrie de Montral,
% Dpartement d'informatique et de recherche oprationnelle,
% Universit de Montral, 2016-17.
% Maintainer : [email protected]
% See licensing information in the code.
% Keywords : grabber, brain imaging data structure
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
% Prepare the path for the BIDS data
if nargin == 0
path_data = pwd;
end
path_data = niak_full_path(path_data);
fprintf(1,"Reading Bids structure %s\n", path_data)
% If no path given, search local dir
if (nargin < 1)||isempty(path_data)
path_data = [pwd filesep];
elseif nargin < 2
opt = struct;
end
if ~isdir(path_data)
error('Bid directory does not exist: %s', path_data)
end
if ~strcmp(path_data(end),filesep);
path_data = [path_data filesep];
end
if ~isfield(opt,'func_hint')
func_hint = '';
else
func_hint = regexptranslate('escape', opt.func_hint);
end
if ~isfield(opt,'anat_hint')
anat_hint = 'T1w';
else
anat_hint = regexptranslate('escape', opt.anat_hint);
end
if ~isfield(opt,'max_subjects')
max_subjects = 0;
else
max_subjects = opt.max_subjects;
end
if ~isfield(opt,'subject_list')
subject_list = 0;
else
subject_list = opt.subject_list;
end
if ~isfield(opt,'task_type')
task_type = "rest";
else
task_type = opt.task_type;
end
list_dir = dir(path_data);
files = struct;
for num_f = 1:length(list_dir)
if list_dir(num_f).isdir && ~strcmpi(list_dir(num_f).name, '.') ...
&& ~strcmpi(list_dir(num_f).name, '..')
subject_dir = list_dir(num_f).name;
% dir_name = regexpi(subject_dir,"(sub-(.*))", 'tokens');
% if ~isempty(dir_name)
% sub_id = dir_name{1}{1,2};
% % Condition to return only subject in subject list
% if ~isa(subject_list,'numeric') && ~any([subject_list{:}]==str2num(sub_id))
% continue
% end
% else
% continue
% end
sub_str = strsplit(subject_dir,'-'){2};
if opt.batch == sub_str(1)
if(~strcmpi(sub_str,'3921443'))
subject = ['sub' sub_str];
fmri_tmp = glob([path_data subject_dir filesep 'func' filesep '*_task-rest_bold.nii.gz']){1};
anat_tmp = glob([path_data subject_dir filesep 'anat' filesep '*_T1w.nii.gz']){1};
end
if((exist(fmri_tmp) == 2) && (exist(anat_tmp)==2))
files.(subject).fmri.session.run = fmri_tmp;
files.(subject).anat = anat_tmp;
end
end
end
end