forked from srivaschennu/MOHAWK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotbands.m
153 lines (131 loc) · 4.88 KB
/
plotbands.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
function plotbands(basename,measure,varargin)
% Copyright (C) 2018 Srivas Chennu, University of Kent and University of Cambrige,
% srivas@gmail.com
%
%
% Plots grouped scatter plot of selected EEG measure of an individual in delta,
% theta and alpha bands alongside grouped data. Requires
% previously prepared grouped connectivity dataset, to be specified in listname.
%
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
listname = 'allsubj';
bandidx = [1 2 3];
loadpaths
param = finputcheck(varargin, {
'legend', 'string', {'on','off'}, 'on'; ...
'title', 'string', {}, measure; ...
'legendposition', 'string', {}, 'best'; ...
});
fontname = 'Helvetica';
fontsize = 24;
colorlist = [
0 0.0 0.5
0 0.5 0
0.5 0.0 0
0 0.5 0.5
0.5 0 0.5
0.5 0.5 0
0.25 0.25 0.75
];
facecolorlist = [
0.75 0.75 1
0.25 1 0.25
1 0.75 0.75
0.75 1 1
1 0.75 1
1 1 0.5
0.5 0.5 1
];
load(sprintf('%s/%s_mohawk.mat',filepath,basename));
load(sprintf('%s/groupdata_%s.mat',filepath,listname));
weiorbin = 2;
groups = [0 1 5];
groupnames = {
'UWS'
'MCS'
'CTRL'
};
bands = {
'Delta'
'Theta'
'Alpha'
'Beta'
'Gamma'
};
trange = [0.9 0.1];
trange = (tvals <= trange(1) & tvals >= trange(2));
m = find(strcmpi(measure,graph(:,1)));
barvals = zeros(3,length(groups));
errvals = zeros(3,length(groups));
selpatidx = ismember(grp,groups);
if strcmp(measure,'modules')
groupvals = squeeze(mean(max(graph{m,weiorbin}(selpatidx,bandidx,trange,:),[],4),3));
patvals = squeeze(mean(max(graphdata{m,weiorbin}(bandidx,:,:),[],3),2));
elseif strcmp(measure,'mutual information')
groupvals = squeeze(mean(mean(graph{m,weiorbin}(selpatidx,grp == groups(g),bandidx,trange),4),2));
patvals = squeeze(mean(mean(graphdata{m,weiorbin}(grp == groups(g),bandidx,trange),4),2));
elseif strcmp(measure,'participation coefficient')
groupvals = squeeze(mean(std(graph{m,weiorbin}(selpatidx,bandidx,trange,:),[],4),3));
patvals = squeeze(mean(std(graphdata{m,weiorbin}(bandidx,trange,:),[],3),2));
elseif strcmp(measure,'median')
groupvals = nanmedian(allcoh(selpatidx,bandidx,:),3);
patvals = nanmedian(matrix(bandidx,:),2);
elseif strcmp(measure,'power')
load(sprintf('%s/%s_mohawk.mat',filepath,basename),'freqs');
groupvals = mean(bandpower(:,bandidx,:),3);
for f = 1:size(freqlist,1)
%collate spectral info
[~, bstart] = min(abs(freqs-freqlist(f,1)));
[~, bstop] = min(abs(freqs-freqlist(f,2)));
patvals(f,:) = mean(spectra(:,bstart:bstop),2);
end
for c = 1:size(patvals,2)
patvals(:,c) = patvals(:,c)./sum(patvals(:,c));
end
patvals = mean(patvals(bandidx,:),2);
else
groupvals = squeeze(mean(mean(graph{m,weiorbin}(selpatidx,bandidx,trange,:),4),3));
patvals = squeeze(mean(mean(graphdata{m,weiorbin}(bandidx,trange,:),3),2));
end
plotvals = cat(1,groupvals,patvals');
groupnames = cat(1,groupnames,{'Patient'});
plotgroups = [grp(selpatidx); max(grp(selpatidx))+1];
uniqgroups = unique(plotgroups);
figure('Color','white','Name',basename);
for g = 1:length(uniqgroups)
meanvals = mean(plotvals(plotgroups == uniqgroups(g),:),1);
if size(plotvals(plotgroups == uniqgroups(g),:),1) > 1
semvals = std(plotvals(plotgroups == uniqgroups(g),:),[],1) ./ ...
sqrt(size(plotvals(plotgroups == uniqgroups(g),:),1));
else
xlimits = xlim; ylimits = ylim; zlimits = zlim;
semvals = 0.05 * [xlimits(2)-xlimits(1) ylimits(2) - ylimits(1) zlimits(2) - zlimits(1)];
end
[x,y,z] = sphere;
surf((x * semvals(1)) + meanvals(1),...
(y * semvals(2)) + meanvals(2),...
(z * semvals(3)) + meanvals(3),...
'EdgeColor',colorlist(g,:),'FaceColor',facecolorlist(g,:),...
'EdgeAlpha',0.5,'FaceAlpha',0.5);
hold all
end
xlabel(sprintf('%s',bands{bandidx(1)}),'FontName',fontname,'FontSize',fontsize);
ylabel(sprintf('%s',bands{bandidx(2)}),'FontName',fontname,'FontSize',fontsize);
zlabel(sprintf('%s',bands{bandidx(3)}),'FontName',fontname,'FontSize',fontsize);
set(gca,'FontName',fontname,'FontSize',fontsize);
legend(groupnames,'Location',param.legendposition);
title(param.title,'FontName',fontname,'FontSize',fontsize);
print(gcf,sprintf('%s/figures/%s_%s.tif',filepath,basename,measure),'-dtiff','-r150');
close(gcf);