-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_GridSim.m
154 lines (112 loc) · 6.53 KB
/
main_GridSim.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
%
% Run all steps of the grid simulation on a single participant
%
% limit the number of threads to process data (less threads also means less memory)
numClassThreads = 1;
numCylThreads = 3;
% set the path to the BIDS data directory
bids_rootPath = 'Y:\WorkData\BIDS_GridSim';
% set the subject, task and hemisphere to simulate on
bids_sub = '09';
bids_task = 'HandGesture';
hemi = 'lh';
% output path for the simulations
bids_simPath = fullfile(bids_rootPath, 'derivatives', [hemi, '_simulations'], ['sub-' bids_sub]);
if ~exist(bids_simPath, 'dir'), mkdir(bids_simPath); end
bids_simTaskPath = fullfile(bids_simPath, bids_task);
if ~exist(bids_simTaskPath, 'dir'), mkdir(bids_simTaskPath); end
% In order to reproduce the results in the article we start at step 2, and
% set the samples filename to the previously generated sample-set
hullFile = 'lh_ext_hull.gii'; % <--- delete (and perform step 0 below) if working on own dataset
samplesFile_s1_out = 'sampleSet'; % <--- delete (and perform step 1 below) if working on own dataset
load(fullfile(bids_simPath, [samplesFile_s1_out, '.mat'])); % <--- delete (and perform step 1 below) if working on own dataset
% set the classification configuration
classConfig = [];
classConfig.isolateTrials = [];
classConfig.silent = 'yes';
classConfig.hrfMethod = 'new';
classConfig.earlyFeatureSelectionMethod = 'tmaphighest';
classConfig.skipStartVolumes = 5;
classConfig.minFeatures = 2; % the minimum number of features
classConfig.minVoxelMeanForFeature = 15000; % voxels with a signal over time below this minimum will be removed (raw input values, pre-normalization and detrending) - the value under which functional voxel are considered to be outside of the brain
classConfig.timeLockActive = 'search_highestbold_hrfpeaks'; % search_highestbold_hrfpeaks, static
classConfig.timeLockActiveSearchScansBeforePeak = 1;
classConfig.timeLockActiveSearchScansAfterPeak = 1;
classConfig.timeLockActiveVolumeOffsets = [0];
classConfig.normAndDetrend = {'NormVoxelsPercSignal', 'SPMDetrend'};
classConfig.crossValidation = 'LeaveOneOut';
classConfig.lateFeatureSelectionMethod = 'none';
classConfig.featureTimeMethod = 'average'; % how features over time are used, average or serialized
classConfig.classificationMethod = 'svm';
%%
% retrieve the root path and make sure dependencies can be found
%
gridSimRoot = gridSimRootPath;
addpath([gridSimRoot, filesep, 'scripts']);
addpath([gridSimRoot, filesep, 'functions']);
%%
% Step 0 - Create a hull based on freesurfer parcellation areas
%
%{
%
% - skip because each hull was created with different parameters for
% each participant and manually corrected. The subject's hull that
% was used is included with the data on OSF
%gHull = s0_createHull( bids_rootPath, bids_sub, hemi, [hemi, '.aparc.annot'], { 'precentral', 'postcentral' });
gHull = s0_createHull( bids_rootPath, bids_sub, hemi, [hemi, '.aparc.Ext.annot'], ...
{ 'superiorfrontal', 'caudalmiddlefrontal', 'parsopercularis', 'precentral', ...
'postcentral', 'superiorparietal', 'supramarginal', 'inferiorparietal' });
% save hull
hullFile = [hemi, '_ext_hull__.gii'];
save(gHull, fullfile(bids_simPath, hullFile))
%}
%%
% Step 1 - Generate random 3D sample-points on a given hull
%
%{
% - skip because the sample-points are generated at random, and to reproduce the
% output for this subject we need to use exactly the same input data, which
% are the previously generated sample-sets, included in the data on OSF
hullPath = fullfile(bids_simPath, [hemi, '_ext_hull.gii']);
[SS, suffix] = s1_generateSamples(hullPath);
% save results
samplesFile_s1_out = ['sampleSet-', suffix];
save(fullfile(bids_simTaskPath, [samplesFile_s1_out, '.mat']), 'SS');
%}
%%
% Step 2 - Peform searchlight classification on each of the 3D sample-points with a specific radius
%
[SS, suffix] = s2_searchlight( SS, ...
bids_rootPath, bids_sub, bids_task, hemi, ...
7, ... % <-- searchlight radius
classConfig, numClassThreads);
% save results
samplesFile_s2_out = [samplesFile_s1_out, '_', bids_task, '_', suffix];
save(fullfile(bids_simTaskPath, [samplesFile_s2_out, '.mat']), 'SS');
%samplesFile_s2_out = 'sampleSet_HandGesture_search-rad7'; % <-- for debugging or to pick up after this step (make sure to load the file first)
%%
% Step 3 - Select the 3D sample-points with a searchlight classification score above a given threshold
%
[SS, suffix] = s3_sampleSelection(SS);
% save results
samplesFile_s3_out = fullfile(bids_simTaskPath, [samplesFile_s2_out, '_', suffix]);
if ~exist(samplesFile_s3_out, 'dir'), mkdir(samplesFile_s3_out); end
save(fullfile(samplesFile_s3_out, [samplesFile_s2_out, '_', suffix, '.mat']), 'SS');
%samplesFile_s3_out = fullfile(bids_simTaskPath, 'sampleSet_HandGesture_search-rad7_P95nofoc'); % <-- for debugging or to pick up after this step (make sure to load the sample-file first)
%%
% Step 4 - Project all virtual grid-configurations on a hull using the 3D sample-points as the center, with their random rotations
%
samplesFiles_s4_out = s4_projectGrids( SS, ...
fullfile(bids_simPath, [hemi, '_ext_hull.gii']), ...
fullfile(samplesFile_s3_out, [samplesFile_s2_out, '_', suffix, '_proj']));
% \/-- for debugging or to pick up after this step (make sure to load the sample-file first)
%samplesFiles_s4_out = dir(fullfile(bids_simTaskPath, 'sampleSet_HandGesture_search-rad7_P95nofoc', 'sampleSet_HandGesture_search-rad7_P95nofoc_proj', '/**/*.mat'));
%samplesFiles_s4_out = strcat({samplesFiles_s4_out.folder}, filesep, {samplesFiles_s4_out.name});
%%
% Step 5 -
%
samplesFiles_s5_out = s5_gridsClassify( samplesFiles_s4_out, ...
bids_rootPath, bids_sub, bids_task, hemi, ...
fullfile(bids_simPath, hullFile), ...
classConfig, numCylThreads, numClassThreads);
%... more