-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathosl_stats_multiplotTFR.m
158 lines (125 loc) · 4.43 KB
/
osl_stats_multiplotTFR.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
function [cfg, data, fig_handle]=osl_stats_multiplotTFR( S )
% [cfg, dats, fig_handle]=osl_stats_multiplotTFR(S)
%
% calls ft_multiplotTFR passing on S.cfg settings to display the tstats for contrast S.contrast for
% OAT S.stats
%
% Input:
% S.oat
% S.stats_fname
% S.modality, e.g. 'MEGPLANAR'
% S.first_level_contrast. Specify single first level contrast index
% S.group_level_contrast. Specify single group contrast index (if group level stats)
% S.cfg
% S.view_cope. Binary flag, if 0 (default) then tstats are viewed
%
% MWW 2012
OSLDIR = getenv('OSLDIR');
try, oat=S.oat; catch, error('No S.oat supplied'); end;
try, stats_fname=S.stats_fname; catch, error('No S.stats_fname supplied'); end;
try, modality=S.modality; catch, modality='MEGPLANAR'; end;
try, contrast=S.first_level_contrast; catch, error('No S.first_level_contrast supplied'); end; % first level contrast - there can be multiple numbers of these
try, group_contrast=S.group_level_contrast; catch, group_contrast=1; end; % specify group contrast if group level stats
try, view_cope=S.view_cope; catch, view_cope=0; end;
try, cfg=S.cfg; catch, cfg=[]; end;
try, do_plots=S.do_plots; catch, do_plots=1; end;
try, D_tstat=S.D; catch
if isstr(stats_fname)
stats=oat_load_results(oat,stats_fname);
else
stats=stats_fname;
end;
S4=[];
S4.oat=oat;
S4.stats=stats;
S4.write_copes=1;
[D_tstat, D_cope]=oat_save_spm_stats(S4);
if(stats.level==2),
D_tstat=D_tstat{group_contrast};
D_cope=D_cope{group_contrast};
end;
end;
if(length(contrast)>1)
error('Can only specify one first level contrast index');
end;
cope=stats.cope;
stdcope=stats.stdcope;
if(stats.level==2),
cope = cope(:,:,:,:,group_contrast);
stdcope = stdcope(:,:,:,:,group_contrast);
end;
data = [];
data.time = stats.times;
data.freq= stats.frequencies;
data.dimord='chan_freq_time';
if(strcmp(modality,'MEGMAG')),
cfg.layout = [OSLDIR '/layouts/neuromag306mag.lay'];
chanind = strmatch('MEGMAG', D_tstat.chantype);
data.label=D_tstat.chanlabels(chanind);
for ind=1:length(chanind),
if(~view_cope)
data.powspctrm(ind,:,:)=permute(cope(chanind(ind),:,contrast,:)./stdcope(chanind(ind),:,contrast,:),[1 4 2 3]);
else
data.powspctrm(ind,:,:)=permute(cope(chanind(ind),:,contrast,:),[1 4 2 3]);
end;
end;
elseif (strcmp(modality,'MEGPLANAR')),
cfg.layout = [OSLDIR '/layouts/neuromag306cmb.lay'];
chanind = strmatch('MEGCMB', D_tstat.chantype);
data.label=D_tstat.chanlabels(chanind);
for ind=1:length(chanind),
if(~view_cope)
data.powspctrm(ind,:,:)=permute(cope(chanind(ind),:,contrast,:)./stdcope(chanind(ind),:,contrast,:),[1 4 2 3]);
else
data.powspctrm(ind,:,:)=permute(cope(chanind(ind),:,contrast,:),[1 4 2 3]);
end;
end;
elseif (strcmp(modality,'MEG')) || (strcmp(modality,'MEGGRAD')),
cfg.layout = [OSLDIR '/layouts/CTF275.lay'];
chanind = strmatch('MEGGRAD', D_tstat.chantype);
data.label=D_tstat.chanlabels(chanind);
for ind=1:length(chanind),
indp=ind;
if(~view_cope)
data.powspctrm(ind,:,:)=permute(cope(indp,:,contrast,:)./stdcope(indp,:,contrast,:),[1 4 2 3]);
else
data.powspctrm(ind,:,:)=permute(cope(indp,:,contrast,:),[1 4 2 3]);
end;
end;
elseif(strcmp(modality,'EEG')), % added by DM
B=sensors(D_tstat,'EEG');
mat=spm2fieldtrip(D_tstat);
cfgx=[];
cfgx.elec.pnt=B.elecpos;
cfgx.elec.label=B.label;
lay = ft_prepare_layout(cfgx,mat);
cfg.layout =lay;
chanind = strmatch('EEG', D_tstat.chantype);
data.label=D_tstat.chanlabels(chanind);
for ind=1:length(chanind),
indp=ind;
if(view_cope)
data.powspctrm(ind,:,:)=permute(cope(indp,:,contrast,:),[1 4 2 3]);
else
data.powspctrm(ind,:,:)=permute(cope(indp,:,contrast,:)./stdcope(indp,:,contrast,:),[1 4 2 3]);
end;
end;
else
error('Unknown modality');
end;
data.powspctrm=double(data.powspctrm);
if(~isfield(cfg,'interactive')),
cfg.interactive = 'yes';
end;
if(~isfield(cfg,'zlim')),
%cfg.zlim = [-4 4];
end;
if(~isfield(cfg,'xlim')),
cfg.xlim = [stats.times(1) stats.times(end)];
end;
cfg.comment = '';
cfg.colorbar = 'yes';
fig_handle=[];
if do_plots
fig_handle = sfigure; ft_multiplotTFR(cfg,data);
end;