Skip to content

Commit 4f38947

Browse files
committed
refg
1 parent 6df7295 commit 4f38947

File tree

3 files changed

+129
-84
lines changed

3 files changed

+129
-84
lines changed

demos/MoAE/moae_03_slice_display.m

Lines changed: 118 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
this_dir = fileparts(mfilename('fullpath'));
2020

21-
subLabel = '01';
22-
2321
opt.pipeline.type = 'stats';
2422

2523
opt.dir.raw = fullfile(this_dir, 'inputs', 'raw');
@@ -31,85 +29,128 @@
3129

3230
opt.model.file = fullfile(this_dir, 'models', 'model-MoAE_smdl.json');
3331

34-
opt.subjects = [subLabel];
32+
opt.subjects = {'01'};
3533

3634
% read the model
3735
opt = checkOptions(opt);
3836

39-
iRes = 1;
40-
41-
opt.results = opt.model.bm.Nodes{iRes}.Model.Software.bidspm.Results{1};
42-
43-
node = opt.model.bm.Nodes{iRes};
44-
[opt, BIDS] = checkMontage(opt, iRes, node, struct([]), subLabel);
45-
46-
opt = checkOptions(opt);
47-
48-
opt.results(iRes).montage = setMontage(opt.results(iRes));
49-
50-
opt.results(iRes).sdConfig
37+
% TODO loop over noce and subjects
5138

52-
% we get the con image to extract data
53-
ffxDir = getFFXdir(subLabel, opt);
54-
55-
maskImage = spm_select('FPList', ffxDir, '^.*_mask.nii$');
56-
bf = bids.File(spm_file(maskImage, 'filename'));
57-
58-
59-
%% Layers to put on the figure
60-
layers = sd_config_layers('init', {'truecolor', 'dual', 'contour'});
61-
62-
% Layer 1: Anatomical map
6339
overwrite = true;
64-
layers(1) = setFields(layers(1), opt.results(iRes).sdConfig.layers{1}, overwrite);
65-
66-
% layers(1).color.file = opt.results(iRes).montage.background{1};
67-
%
68-
% hdr = spm_vol(layers(1).color.file);
69-
% [max_val, min_val] = slover('volmaxmin', hdr);
70-
% layers(1).color.range = [0 max_val];
71-
72-
73-
%% Layer 2: Dual-coded layer
74-
%
75-
% - contrast estimates color-coded;
76-
layers(2) = setFields(layers(2), opt.results(iRes).sdConfig.layers{2}, overwrite);
77-
78-
conImage = spm_select('FPList', ffxDir, ['^con_' bf.entities.label '.nii$']);
79-
layers(2).color.file = conImage;
80-
81-
color_map_folder = fullfile(fileparts(which('map_luminance')), '..', 'mat_maps');
82-
load(fullfile(color_map_folder, layers(2).color.map));
83-
layers(2).color.map = diverging_bwr;
84-
85-
% layers(2).color.range = [-4 4];
86-
% layers(2).color.label = '\beta_{listening} - \beta_{baseline} (a.u.)';
87-
88-
89-
% - t-statistics opacity-coded
90-
spmTImage = spm_select('FPList', ffxDir, ['^spmT_' bf.entities.label '.nii$']);
91-
layers(2).opacity.file = spmTImage;
92-
93-
% layers(2).opacity.range = [0 3];
94-
% layers(2).opacity.label = '| t |';
95-
96-
%% Layer 3 and 4: Contour of ROI
97-
layers(3) = setFields(layers(3), opt.results(iRes).sdConfig.layers{3}, overwrite);
98-
99-
contour = spm_select('FPList', ffxDir, ['^sub.*' bf.entities.label '.*_mask.nii']);
100-
101-
layers(3).color.file = contour;
102-
% layers(3).color.map = [0 0 0];
103-
% layers(3).color.line_width = 2;
104-
105-
%% Settings
106-
settings = opt.results(iRes).sdConfig.settings;
107-
108-
% we reuse the details for the SPM montage
109-
% settings.slice.disp_slices = opt.results(1).montage.slices;
110-
% settings.slice.orientation = opt.results(1).montage.orientation;
111-
112-
settings.fig_specs.title = opt.results(1).name;
11340

114-
%% Display the layers
115-
[settings, p] = sd_display(layers, settings);
41+
color_map_folder = fullfile(returnRootDir(), 'lib', 'brain_colours', 'mat_maps');
42+
43+
node = opt.model.bm.Nodes{1};
44+
45+
if any(strcmp(node.Level, {'Run', 'Subject'}))
46+
47+
for iSub = 1:numel(opt.subjects)
48+
49+
subLabel = opt.subjects{iSub};
50+
51+
ffxDir = getFFXdir(subLabel, opt);
52+
load(fullfile(ffxDir, 'SPM.mat'))
53+
54+
for iRes = 1:numel(node.Model.Software.bidspm.Results)
55+
56+
opt.results = node.Model.Software.bidspm.Results{iRes};
57+
58+
if ~isfield(opt.results, 'montage') || ~opt.results.montage.do
59+
continue
60+
end
61+
62+
% set defaults
63+
[opt, ~] = checkMontage(opt, iRes, node, struct([]), subLabel);
64+
opt = checkOptions(opt);
65+
opt.results(iRes).montage = setMontage(opt.results(iRes));
66+
67+
for i_name =1:numel(opt.results.name)
68+
69+
if opt.results(iRes).binary
70+
layers = sd_config_layers('init', {'truecolor', 'dual', 'contour'});
71+
else
72+
layers = sd_config_layers('init', {'truecolor', 'dual'});
73+
end
74+
75+
%% Layer 1: Anatomical map
76+
layers(1) = setFields(layers(1), opt.results(iRes).sdConfig.layers{1}, overwrite);
77+
78+
layers(1).color.file = opt.results(iRes).montage.background{1};
79+
80+
hdr = spm_vol(layers(1).color.file);
81+
[max_val, min_val] = slover('volmaxmin', hdr);
82+
layers(1).color.range = [0 max_val];
83+
84+
%% Layer 2: Dual-coded layer
85+
86+
% - contrast estimates color-coded;
87+
layers(2) = setFields(layers(2), opt.results(iRes).sdConfig.layers{2}, overwrite);
88+
89+
name = opt.results.name{i_name};
90+
tmp = struct('name', name);
91+
contrastNb = getContrastNb(tmp, opt, SPM);
92+
93+
% keep track if this is a t test or F test
94+
stat = SPM.xCon(contrastNb).STAT;
95+
96+
contrastNb = sprintf('%04.0f', contrastNb);
97+
98+
if strcmp(stat, 'T')
99+
colorFile = spm_select('FPList', ffxDir, ['^con_' contrastNb '.nii$']);
100+
else
101+
colorFile = spm_select('FPList', ffxDir, ['^ess_' contrastNb '.nii$']);
102+
end
103+
layers(2).color.file = colorFile;
104+
105+
title = strrep(name, '_', ' ');
106+
layers(2).color.label = [title ' (a.u.)'];
107+
108+
% - statistics opacity-coded
109+
if strcmp(stat, 'T')
110+
opacityFile = spm_select('FPList', ffxDir, ['^spmT_' contrastNb '.nii$']);
111+
112+
layers(2).opacity.label = '| t |';
113+
114+
load(fullfile(color_map_folder, 'diverging_bwr_iso.mat'));
115+
layers(2).color.map = diverging_bwr;
116+
else
117+
opacityFile = spm_select('FPList', ffxDir, ['^spmF_' contrastNb '.nii$']);
118+
119+
layers(2).opacity.label = 'F';
120+
121+
load(fullfile(color_map_folder, '1hot_iso.mat'));
122+
layers(2).color.map = hot;
123+
124+
hdr = spm_vol(opacityFile);
125+
[max_val, min_val] = slover('volmaxmin', hdr);
126+
layers(2).color.range = [0 max_val];
127+
128+
layers(2).opacity.range = [0 5];
129+
end
130+
layers(2).opacity.file = opacityFile;
131+
132+
%% Contour
133+
if opt.results(iRes).binary
134+
layers(3) = setFields(layers(3), opt.results(iRes).sdConfig.layers{3}, overwrite);
135+
contour = spm_select('FPList', ffxDir, ['^sub.*' contrastNb '.*_mask.nii']);
136+
layers(3).color.file = contour;
137+
end
138+
139+
%% Settings
140+
settings = opt.results(iRes).sdConfig.settings;
141+
142+
% we reuse the details for the SPM montage
143+
settings.slice.disp_slices = opt.results(1).montage.slices;
144+
settings.slice.orientation = opt.results(1).montage.orientation;
145+
146+
settings.fig_specs.title = title;
147+
148+
%% Display the layers
149+
[settings, p] = sd_display(layers, settings);
150+
151+
end
152+
153+
end
154+
155+
end
156+
end

src/defaults/defaultResultsStructure.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@
3232
% load(fullfile(color_map_folder, 'diverging_bwr_iso.mat'));
3333

3434
layers{2} = struct('color', struct('file', [], ... % con image
35-
'map', 'diverging_bwr_iso', ...
3635
'range', [-4 4], ...
37-
'label', '\beta_{listening} - \beta_{baseline} (a.u.)'), ...
38-
'opacity', struct('file', [], ... % spmT image
36+
'label', ''), ...
37+
'opacity', struct('file', [], ... % assume spmT image
3938
'range', [2 3], ...
40-
'label', '| t |'), ...
39+
'label', ''), ...
4140
'type', 'dual');
4241

4342
layers{3} = struct('color', struct('file', [], ... % spmT mask thresholded at 0.05 FWD
44-
'map', [0 0 0], ...
45-
'line_width', 2));
43+
'map', 'w', ...
44+
'line_width', 1));
4645

4746
result.sdConfig.layers = layers;
4847

src/stats/results/renameSpmT.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ function renameSpmT(result)
88
%
99

1010
% (C) Copyright 2023 bidspm developers
11-
outputFiles = spm_select('FPList', result.dir, '^spmT_[0-9].*_sub-.*nii$');
11+
prefixes = {'spmT', 'spmF'};
12+
for i_prefix = 1:numel(prefixes)
13+
14+
outputFiles = spm_select('FPList', result.dir, ['^' prefixes{i_prefix} '_[0-9].*_sub-.*nii$']);
1215

1316
for iFile = 1:size(outputFiles, 1)
1417

@@ -22,4 +25,6 @@ function renameSpmT(result)
2225

2326
movefile(source, target);
2427
end
28+
29+
end
2530
end

0 commit comments

Comments
 (0)