-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_measureplotting.m
287 lines (269 loc) · 14.6 KB
/
gui_measureplotting.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
function gui_measureplotting(BNCT,siglevel,savefigs,vstime,vstask,vsfreq,showfigs,fileinfo)
foldersuffix = fileinfo.foldersuffix;
filenamesuffix = fileinfo.filenamesuffix;
filenameappend = fileinfo.filenameappend;
temptime = str2mat(BNCT.config.batch_timerange);
temptime = str2num(temptime);
medtimes = mean(temptime')';
%medtimes = [3/75:3/75:3]; %CONTINUOUS TIME
timephrase = ' 1000ms intervals';%' - 250ms overlap';
%% Order data vs time/freq/task and calculate significance
try
for task = 1:1:size(BNCT.config.tasklistraw,1)
for freq = 1:1:size(BNCT.config.freqrangelistraw,1)
for t = 1:1:size(BNCT.alldata,3)%size(BNCT.config.batch_timerange,1)
for meas = 1:1:size(BNCT.graph_features,1)
meas_temp = [];
for pheno = 1:1:size(BNCT.config.phenotypelistraw,1)
numsubjects = size(BNCT.allmeasures.(BNCT.config.phenotypelistraw{pheno}).(BNCT.config.tasklist{task}),2);
subjectdata = BNCT.allmeasures.(BNCT.config.phenotypelistraw{pheno}).(BNCT.config.tasklist{task});
%Get mean values and organize
for sub = 1:1:numsubjects
meas_temp(sub,pheno) = subjectdata{1,sub}(freq,t).(BNCT.graph_features{meas,3});
end
meas_temp2 = sum(meas_temp(:,pheno)) / numsubjects;
avg_measures_single_task_and_freq_vs_time.(BNCT.config.tasklist{task}).(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{meas,3}).(BNCT.config.phenotypelistraw{pheno})(t)= meas_temp2;
avg_measures_single_time_and_task_vs_freq{t}.(BNCT.config.tasklist{task}).(BNCT.graph_features{meas,3}).(BNCT.config.phenotypelistraw{pheno})(freq)= meas_temp2;
avg_measures_single_time_and_freq_vs_task{t}.(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{meas,3}).(BNCT.config.phenotypelistraw{pheno})(task)= meas_temp2;
end
%Need to change if > 2 groups, significance between all
%pairs - how to mark later?
if size(BNCT.config.phenotypelistraw,1)==2
%Remove zeros (for diff # subjects) from ttest arrays
data1 = meas_temp(:,1);
data2 = meas_temp(:,2);
data1 = data1(data1~=0);
data2 = data2(data2~=0);
%Test & store significance
[h,signif] = ttest2(data1,data2);
avg_measures_single_task_and_freq_vs_time.(BNCT.config.tasklist{task}).(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{meas,3}).significance(t) = signif;
avg_measures_single_time_and_task_vs_freq{t}.(BNCT.config.tasklist{task}).(BNCT.graph_features{meas,3}).significance(freq)= signif;
avg_measures_single_time_and_freq_vs_task{t}.(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{meas,3}).significance(task)= signif;
end
end
end
end
end
catch
x=1;
end
%% Measures in single task and freq vs time
if vstime==1
a = waitbar(0,'Plotting measures vs time...');
count = 1;
for freq = 1:1:size(BNCT.config.freqrangelistraw,1)
for task = 1:1:size(BNCT.config.tasklist,1)
h1 = figure('Name',horzcat('Graph Measures vs Time for ',BNCT.config.freqlabellistraw{freq},', ',BNCT.config.tasklistraw{task},timephrase),'units','normalized','outerposition',[0 0 1 1]);
set(gcf, 'Color', 'w');
for i = 1:1:size(BNCT.graph_features,1)
data = [];
for pheno = 1:1:size(BNCT.config.phenotypelistraw,1)
data(:,pheno) = avg_measures_single_task_and_freq_vs_time.(BNCT.config.tasklist{task}).(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{i,3}).(BNCT.config.phenotypelistraw{pheno})';
% data(2,pheno) = avg_measures_single_task_and_freq_vs_time.(BNCT.config.tasklist{task}).(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{i,3}).(BNCT.config.phenotypelistraw{pheno})';
pheno_names{1,pheno} = BNCT.config.phenotypelistraw{pheno};
end
%Plot data
subplot(3,3,i)
h2 = subplot(3,3,i);
%plot(medtimes,data(:,1),'color','red'); %CONTINUOUS TIME
%hold on
%plot(medtimes,data(:,2),'color','blue');
%
%
% bar(1,data(1,1),.05,'facecolor','red');
hold on
% bar(1,data(1,2),.025,'facecolor','blue');
bar_handle = bar(data);%(1:end,:)); %end=16
%Change these colors based on which group is affected, etc,
%also multiple groups?
if str2num(BNCT.config.condpositive) == 1
set(bar_handle(1),'FaceColor',[1,0,0]);
set(bar_handle(2),'FaceColor',[0,0,1]);
else
set(bar_handle(2),'FaceColor',[1,0,0]);
set(bar_handle(1),'FaceColor',[0,0,1]);
end
%}
if size(BNCT.alldata,3) > 15
set(h2,'XTick',1:1:size(BNCT.alldata,3));
end
% set(h2,'XTickLabel',BNCT.config.batch_timerange','fontsize',6);
set(h2,'XTickLabel',medtimes,'fontsize',6);
% rotateXLabels(h2,45)
%Set axis limits based on range of values
title(BNCT.graph_features{i,2})
try
ylim([min(min(data))-0.1*mean(mean(data)), max(max(data))+0.1*mean(mean(data))]);
catch
ylim([min(min(data))-0.1, max(max(data))+0.1]);
end
%
%Mark significant data with *
for t = 1:size(BNCT.alldata,3);%size(BNCT.config.batch_timerange,1)
yt = get(gca, 'YTick');
xt = linspace(1,size(BNCT.alldata,3),size(BNCT.alldata,3));
%xt = get(gca, 'XTick');
hold on
if avg_measures_single_task_and_freq_vs_time.(BNCT.config.tasklist{task}).(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{i,3}).significance(t) < siglevel
try
plot(xt([t t]), [1 1]*max(data(t,:))*1.05, '-k', mean(xt([t t])), max(data(t,:))*1.03, '*k')
catch
x=1;
end
% plot(medtimes([t t]), [1 1]*max(data(t,:))*1.05, '-k', mean(medtimes([t t])), max(data(t,:))*1.03, '*k') %CONTINUOUS TIME
end
hold off
end
%}
end
legend(pheno_names)
subtitle(horzcat('Graph Measures vs Time for ',BNCT.config.freqlabellistraw{freq},', ',BNCT.config.tasklistraw{task},' (p < ',num2str(siglevel),' marked with *)',timephrase));
%Save plots
if savefigs == 1
filename=horzcat(foldersuffix,filenamesuffix,'_',(BNCT.config.tasklistraw{task}),'_',BNCT.config.freqlabellistraw{freq},'_vs_time_',filenameappend,'.png');
%print(filename,'-dpng');
%saveas(gcf,filename,'png')
export_fig(filename,'-nocrop','-zbuffer')
end
if showfigs ~= 1
close(h1)
end
waitbar(count/(size(BNCT.config.freqrangelistraw,1)*size(BNCT.config.tasklist,1)),a);
count = count+1;
end
end
close(a)
end
%% Measures in single time and freq vs task
%
if vstask == 1
a = waitbar(0,'Plotting measures vs task...');
count = 1;
for time = 1:1:size(BNCT.config.batch_timerange,1)
for freq = 1:1:size(BNCT.config.freqrangelistraw,1)
h1 = figure('Name',horzcat('Graph Measures vs Task for ',BNCT.config.freqlabellistraw{freq},', for Time = ',BNCT.config.batch_timerange{time}),'units','normalized','outerposition',[0 0 1 1]);
set(gcf, 'Color', 'w');
%set(gcf, 'Renderer', 'painters');
for i = 1:1:size(BNCT.graph_features,1)
data = [];
for pheno = 1:1:size(BNCT.config.phenotypelistraw,1)
data(:,pheno) = avg_measures_single_time_and_freq_vs_task{1,time}.(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{i,3}).(BNCT.config.phenotypelistraw{pheno})';
pheno_names{1,pheno} = BNCT.config.phenotypelistraw{pheno};
end
subplot(3,3,i)
h2 = subplot(3,3,i);
bar_handle = bar(data);
if str2num(BNCT.config.condpositive) == 1
set(bar_handle(1),'FaceColor',[1,0,0]);
set(bar_handle(2),'FaceColor',[0,0,1]);
else
set(bar_handle(2),'FaceColor',[1,0,0]);
set(bar_handle(1),'FaceColor',[0,0,1]);
end
title(BNCT.graph_features{i,2})
set(h2,'XTickLabel',BNCT.config.tasklistraw,'fontsize',7);
rotateXLabels(h2,45)
try
ylim([min(min(data))-0.1*mean(mean(data)), max(max(data))+0.1*mean(mean(data))]);
catch
ylim([min(min(data))-0.1, max(max(data))+0.1]);
end
%
%Mark significant data with *
for task = 1:size(BNCT.config.tasklistraw,1)
yt = get(gca, 'YTick');
xt = get(gca, 'XTick');
hold on
if avg_measures_single_time_and_freq_vs_task{time}.(BNCT.config.freqlabellistraw{freq}).(BNCT.graph_features{i,3}).significance(task) < siglevel
plot(xt([task task]), [1 1]*max(data(task,:))*1.05, '-k', mean(xt([task task])), max(data(task,:))*1.03, '*k')
end
hold off
end
%}
end
%descr = horzcat('(p < ',siglevel,' marked with *)');
%axes(h1);
%ylims=get(gca,'YLim');
%xlims=get(gca,'XLim');
%text(5,0.1,'Outside top right corner',...
%'VerticalAlignment','bottom',...
%'HorizontalAlignment','left')
%text(0.25,0.6,descr);
legend(pheno_names)
subtitle(horzcat('Graph Measures vs Task for ',BNCT.config.freqlabellistraw{freq},', for Time = ',BNCT.config.batch_timerange{time},' (p < ',num2str(siglevel),' marked with *)'));
%Save plots
if savefigs == 1
filename=horzcat(foldersuffix,filenamesuffix,'_',(BNCT.config.batch_timerange{time}),'_',BNCT.config.freqlabellistraw{freq},'_vs_task_',filenameappend,'.png');
export_fig(filename,'-nocrop','-zbuffer')
end
if showfigs ~= 1
close(h1)
end
waitbar(count/(size(BNCT.config.freqrangelistraw,1)*size(BNCT.config.batch_timerange,1)),a);
count = count+1;
end
end
close(a)
end
%% Measures in single time and task vs freq
if vsfreq == 1
a = waitbar(0,'Plotting measures vs frequency...');
count = 1;
for time = 1:1:size(BNCT.config.batch_timerange,1)
for task = 1:1:size(BNCT.config.tasklist,1)
h1 = figure('Name',horzcat('Graph Measures vs Frequency for ',BNCT.config.tasklistraw{task},', for Time = ',BNCT.config.batch_timerange{time}),'units','normalized','outerposition',[0 0 1 1]);
set(gcf, 'Color', 'w');
for i = 1:1:size(BNCT.graph_features,1)
data = [];
for pheno = 1:1:size(BNCT.config.phenotypelistraw,1)
data(:,pheno) = avg_measures_single_time_and_task_vs_freq{1,time}.(BNCT.config.tasklist{task}).(BNCT.graph_features{i,3}).(BNCT.config.phenotypelistraw{pheno})';
pheno_names{1,pheno} = BNCT.config.phenotypelistraw{pheno};
end
subplot(3,3,i)
h2 = subplot(3,3,i);
bar_handle = bar(data);
if str2num(BNCT.config.condpositive) == 1
set(bar_handle(1),'FaceColor',[1,0,0]);
set(bar_handle(2),'FaceColor',[0,0,1]);
else
set(bar_handle(2),'FaceColor',[1,0,0]);
set(bar_handle(1),'FaceColor',[0,0,1]);
end
title(BNCT.graph_features{i,2})
set(h2,'XTickLabel',BNCT.config.freqlabellistraw,'fontsize',7);
rotateXLabels(h2,45)
try
ylim([min(min(data))-0.1*mean(mean(data)), max(max(data))+0.1*mean(mean(data))]);
catch
ylim([ max(max(data))+0.1*mean(mean(data)), min(min(data))-0.1*mean(mean(data))])
% x=1;
end
%
%Mark significant data with *
for freq = 1:size(BNCT.config.freqlabellistraw,1)
yt = get(gca, 'YTick');
xt = get(gca, 'XTick');
hold on
if avg_measures_single_time_and_task_vs_freq{time}.(BNCT.config.tasklist{task}).(BNCT.graph_features{i,3}).significance(freq) < siglevel
plot(xt([freq freq]), [1 1]*max(data(freq,:))*1.05, '-k', mean(xt([freq freq])), max(data(freq,:))*1.03, '*k')
end
hold off
end
%}
end
legend(pheno_names)
subtitle(horzcat('Graph Measures vs Frequency for ',BNCT.config.tasklistraw{task},', for Time = ',BNCT.config.batch_timerange{time},' (p < ',num2str(siglevel),' marked with *)'));
%Save plots
if savefigs == 1
filename=horzcat(foldersuffix,filenamesuffix,'_',(BNCT.config.batch_timerange{time}),'_',BNCT.config.tasklistraw{task},'_vs_freq_',filenameappend,'.png');
export_fig(filename,'-nocrop','-zbuffer')
end
if showfigs ~= 1
close(h1)
end
waitbar(count/(size(BNCT.config.tasklist,1)*size(BNCT.config.batch_timerange,1)),a);
count = count+1;
end
end
close(a)
end