-
Notifications
You must be signed in to change notification settings - Fork 158
/
tutorial_frontiers2018_copy.m
191 lines (175 loc) · 7.63 KB
/
tutorial_frontiers2018_copy.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 tutorial_frontiers2018_copy(ProtocolNameSingle, ProtocolNameGroup, reports_dir)
% TUTORIAL_FRONTIERS2018_COPY: Copy the subject averages for the Brainstorm/SPM group tutorial into a new protocol - FRONTIERS ARTICLE VERSION
%
% ONLINE TUTORIALS:
% - https://neuroimage.usc.edu/brainstorm/Tutorials/VisualSingle
% - https://neuroimage.usc.edu/brainstorm/Tutorials/VisualGroup
%
% INPUTS:
% - ProtocolNameSingle : Name of the protocol created with all the data imported (Frontiers2018Single)
% - ProtocolNameGroup : Name of the protocol with just the averages, downsampled to 275Hz (Frontiers2018Group)
% - reports_dir : If defined, exports all the reports as HTML to this folder
% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
%
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
%
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Author: Francois Tadel, Elizabeth Bock, 2016-2018
% ===== CHECK PROTOCOLS =====
% Start brainstorm without the GUI
if ~brainstorm('status')
brainstorm nogui
end
% Output folder for reports
if (nargin < 3) || isempty(reports_dir) || ~isdir(reports_dir)
reports_dir = [];
end
% You have to specify the folder in which the tutorial dataset is unzipped
if (nargin < 2) || isempty(ProtocolNameSingle) || isempty(ProtocolNameGroup)
ProtocolNameSingle = 'Frontiers2018Single';
ProtocolNameGroup = 'Frontiers2018Group';
end
% Output protocol: Delete existing protocol
gui_brainstorm('DeleteProtocol', ProtocolNameGroup);
% Output protocol: Create new protocol
iProtocolGroup = gui_brainstorm('CreateProtocol', ProtocolNameGroup, 0, 0);
% Output protocol: Get protocol information
ProtocolInfoGroup = bst_get('ProtocolInfo');
% Input protocol: Check that it exists
iProtocolSingle = bst_get('Protocol', ProtocolNameSingle);
if isempty(iProtocolSingle)
error(['Unknown protocol: ' ProtocolNameSingle]);
end
% Select input protocol
gui_brainstorm('SetCurrentProtocol', iProtocolSingle);
% Input protocol: Get protocol information
ProtocolInfoSingle = bst_get('ProtocolInfo');
% ===== COPY ONLY GOOD SUBJECTS =====
% Start a new report (one report per subject)
bst_report('Start');
% Loop on subjects
for iSubj = 1:16
% Subject folders
SubjectName = sprintf('sub-%02d', iSubj);
AnatSrc = bst_fullfile(ProtocolInfoSingle.SUBJECTS, SubjectName);
DataSrc = bst_fullfile(ProtocolInfoSingle.STUDIES, SubjectName);
AnatDest = bst_fullfile(ProtocolInfoGroup.SUBJECTS, SubjectName);
DataDest = bst_fullfile(ProtocolInfoGroup.STUDIES, SubjectName);
% If subject folder doesn't exist: skip
if ~file_exist(AnatSrc) || ~file_exist(DataSrc)
disp(['Subject "' SubjectName '" does not exist or is incomplete.']);
continue;
end
% Copy anatomy files
mkdir(AnatDest);
disp(['Copying: ' AnatSrc ' to ' AnatDest '...']);
file_copy(bst_fullfile(AnatSrc, '*.mat'), AnatDest);
% Copy analysis folders
mkdir(bst_fullfile(DataDest, '@default_study'));
mkdir(bst_fullfile(DataDest, '@intra'));
disp(['Copying: ' DataSrc ' to ' DataDest '...']);
file_copy(bst_fullfile(DataSrc, '@default_study', '*.mat'), bst_fullfile(DataDest, '@default_study'));
file_copy(bst_fullfile(DataSrc, '@intra', '*.mat'), bst_fullfile(DataDest, '@intra'));
% Loop on runs
for iRun = 1:6
% Run folders
RunName = sprintf('sub-%02d_ses-meg_task-facerecognition_run-%02d_proc-sss_meg', iSubj, iRun);
RunSrc = bst_fullfile(DataSrc, RunName);
RunDest = bst_fullfile(DataDest, RunName);
% If run folder doesn't exist: skip
if ~file_exist(RunSrc)
disp(['Run "' SubjectName '/' RunName '" does not exist or is incomplete.']);
continue;
end
% Copy files
mkdir(RunDest);
disp(['Copying: ' RunSrc ' to ' RunDest '...']);
file_copy(bst_fullfile(RunSrc, 'brainstormstudy.mat'), RunDest);
file_copy(bst_fullfile(RunSrc, 'channel_*.mat'), RunDest);
file_copy(bst_fullfile(RunSrc, '*_average_*.mat'), RunDest);
if ~isempty(dir(bst_fullfile(RunSrc, 'headmodel_*.mat')))
file_copy(bst_fullfile(RunSrc, 'headmodel_*.mat'), RunDest);
end
if ~isempty(dir(bst_fullfile(RunSrc, 'noisecov_full.mat')))
file_copy(bst_fullfile(RunSrc, 'noisecov_full.mat'), RunDest);
end
if ~isempty(dir(bst_fullfile(RunSrc, 'results_*.mat')))
file_copy(bst_fullfile(RunSrc, 'results_*.mat'), RunDest);
end
% if ~isempty(dir(bst_fullfile(RunSrc, 'timefreq_*.mat')))
% file_copy(bst_fullfile(RunSrc, 'timefreq_*.mat'), RunDest);
% end
end
end
% ===== RELOAD =====
% Reload output protocol
db_reload_database(iProtocolGroup);
% Select output protocol
gui_brainstorm('SetCurrentProtocol', iProtocolGroup);
% ===== DOWNSAMPLE TO 275HZ =====
% Process: Select data files in: */*
sDataAll = bst_process('CallProcess', 'process_select_files_data', [], []);
% Process: Resample: 275Hz
sDataAll = bst_process('CallProcess', 'process_resample', sDataAll, [], ...
'freq', 275, ...
'overwrite', 1);
% Process: Select time-frequency files in: */*
sTimefreqAll = bst_process('CallProcess', 'process_select_files_timefreq', [], []);
% Process: Resample: 275Hz
if ~isempty(sTimefreqAll)
sTimefreqAll = bst_process('CallProcess', 'process_resample', sTimefreqAll, [], ...
'freq', 275, ...
'overwrite', 1);
end
% ===== RENAME: DATA =====
% Process: Select data files in: */*
sDataAll = bst_process('CallProcess', 'process_select_files_data', [], []);
% Rename data files
for i = 1:length(sDataAll)
% Remove all the processing tags
iTag = strfind(sDataAll(i).Comment, ' |');
if isempty(iTag)
continue;
end
newComment = sDataAll(i).Comment(1:iTag-1);
% Process: Set comment
bst_process('CallProcess', 'process_set_comment', sDataAll(i), [], ...
'tag', newComment, ...
'isindex', 0);
end
% % ===== RENAME: TIME-FREQ =====
% % Process: Select time-frequency files in: */*
% sTimefreqAll = bst_process('CallProcess', 'process_select_files_timefreq', [], []);
% % Rename timefreq files
% %AllConditions = {'Famous', 'Scrambled', 'Unfamiliar'};
% for i = 1:length(sTimefreqAll)
% % Remove all the processing tags
% iTag = strfind(sTimefreqAll(i).Comment, ' |');
% if isempty(iTag)
% continue;
% end
% newComment = sTimefreqAll(i).Comment(1:iTag-1);
% %newComment = ['Avg: ', AllConditions{sTimefreqAll(i).iItem}, ', Power, 6-60Hz'];
% % Process: Set comment
% bst_process('CallProcess', 'process_set_comment', sTimefreqAll(i), [], ...
% 'tag', newComment, ...
% 'isindex', 0);
% end
% Save report
ReportFile = bst_report('Save', []);
if ~isempty(reports_dir) && ~isempty(ReportFile)
bst_report('Export', ReportFile, bst_fullfile(reports_dir, ['report_' ProtocolNameGroup '_copy.html']));
end