-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTEplot2D.m
More file actions
executable file
·347 lines (305 loc) · 12.3 KB
/
Copy pathTEplot2D.m
File metadata and controls
executable file
·347 lines (305 loc) · 12.3 KB
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
function TEplot2D(cfg,data)
%
%
%
% You can use the function as following:
% TEplot2D(cfg,Data)
%
% cfg.statstype = 1: corrected; 2:uncorrected; 3: 1-pval; 4:
% rawdistance; 5:results graph correction
% cfg.arrowpos = Position of arrowhead: 1 = end of the line; 2 =
% centre of the line (default = 2)
% cfg.arrowcolorpos = Color of arrows (default = [1 0 0])
% cfg.arrowcolorneg = Color of arrows in case of negative mean distances
% (default = [0 0 1])
% cfg.alinewidth = Linewidth of arrows in case of significance
% (default = 2)
% cfg.electrodes = 'on','off','labels','numbers','highlights'
% (default = 'on')
% cfg.hcolor = Color of head cartoon (default = [0,0,0])
% cfg.hlinewidth = number, Linewidth of the drawn head, nose and ears
% (default = 2)
% cfg.emarker = Marker symbol (default = 'o')
% cfg.ecolor = Marker color (default = [0 0 0] (black))
% cfg.emarkersize = Marker size (default = 2)
% cfg.efontsize = Font size of electrode labels/numbers (default = 8 pt)
% when cfg.electrodes = 'numbers' or 'labels'
% cfg.efontcolor = Font color of electrode labels/numbers when
% cfg.electrodes = 'numbers' or 'labels'
% (default = [0 0 0])
% cfg.hlmarker = Highlight marker symbol (default = 'o')
% cfg.hlcolor = Highlight marker color (default = [1 0 0] (red))
% cfg.hlmarkersize = Highlight marker size (default = 4)
% cfg.layout = specification of the layout which defines how the
% channels are arranged:
%
% The layout defines how the channels are arranged. You can specify the
% layout in two ways:
% - you can provide a pre-computed layout structure (see prepare_layout)
% - you can give the name of an ascii layout file with extension *.lay
%
%
% 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;
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY;
%
% Version 2.0 by Michael Lindner, Raul Vicente, Michael Wibral
% Frankfurt 2012
%
% CHANGELOG
% 18/12/2014 PW: new statstype 5 for plotting of the graph analysis output
% 18/12/2014 PW: new option to switch offf/on plotting of head contour
% 01/19/2015 PW: removed cfg option 'alpha', wasn't used anymore
if cfg.statstype == 3
if ~isfield(cfg,'alpha'); cfg.alpha = 2; end;
end
if ~isfield(cfg,'arrowpos'); cfg.arrowpos = 2; end;
if ~isfield(cfg,'arrowcolorpos'); cfg.arrowcolorpos = [1 0 0]; end;
if ~isfield(cfg,'arrowcolorneg'); cfg.arrowcolorneg = [0 0 1]; end;
if ~isfield(cfg,'alinewidth'); cfg.alinewidth = 2; end;
if ~isfield(cfg,'electrodes'); cfg.electrodes = 'on'; end; % on,off,label,numbers or highlights
if ~isfield(cfg,'showlabels'); % for compatibility with OLDSTYLE
cfg.showlabels = '';
%else
% cfg.electrodes = '';
end;
if ~isfield(cfg,'emarker'); cfg.emarker = 'o'; end;
if ~isfield(cfg,'ecolor'); cfg.ecolor = [0 0 0]; end;
if ~isfield(cfg,'emarkersize'); cfg.emarkersize = 2; end;
if ~isfield(cfg,'efontsize'); cfg.efontsize = get(0,'DefaultAxesFontSize');end;
if ~isfield(cfg,'efontcolor'); cfg.efontcolor = [0 0 0]; end;
if ~isfield(cfg,'plothead'); cfg.plothead = 1; end;
if ~isfield(cfg,'hlmarker'); cfg.hlmarker = 'o'; end;
if ~isfield(cfg,'hlcolor'); cfg.hlcolor = [1 0 0]; end;
if ~isfield(cfg,'hlmarkersize'); cfg.hlmarkersize = 4; end;
if ~isfield(cfg, 'hcolor'); cfg.hcolor = [0 0 0]; end;
if ~isfield(cfg, 'hlinewidth'); cfg.hlinewidth = 2; end;
if ~isfield(cfg,'layout')
error('TRENTOOL ERROR: Specify at least the field or key "layout".');
end;
if isfield(cfg,'electrod')
cfg.electrodes = lower(cfg.electrod);
cfg = rmfield(cfg,'electrod');
end;
if isfield(cfg,'electcolor')
cfg.ecolor = cfg.electcolor;
cfg = rmfield(cfg,'electcolor');
end;
if isfield(cfg,'emsize')
cfg.emarkersize = cfg.emsize;
cfg = rmfield(cfg,'emsize');
end;
if isfield(cfg,'headcolor')
cfg.hcolor = cfg.headcolor;
cfg = rmfield(cfg,'headcolor');
end;
if isfield(cfg,'efontsize')
cfg.efsize = cfg.efontsize;
cfg = rmfield(cfg,'efontsize');
end;
if isfield(cfg,'efontcolor')
cfg.efcolor = cfg.efontcolor;
cfg = rmfield(cfg,'efontcolor');
end;
if cfg.statstype == 1; sl='corrected';
elseif cfg.statstype == 2; sl='uncorrected';
elseif cfg.statstype == 3; sl='1-pvalue';
elseif cfg.statstype == 4; sl='raw effect';
elseif cfg.statstype == 5; sl='graph correction';
end
widthmultiplier = 5; % for arrowlines in case of 1-pvalue
% check whether the entry in cfg.layout is a structure (if not assume ascii
% file)
if isstruct(cfg.layout) && all(isfield(cfg.layout, {'pos';'label'}))
lay = cfg.layout;
xcoord = lay.pos(:,1);
ycoord = lay.pos(:,2);
allchannels = lay.label;
index = 1:size(xcoord,1);
else
% read .lay file
filename = strcat(cfg.layout,'.lay');
[index,xcoord,ycoord,zcoord,v5,allchannels] = textread(filename,'%d %f %f %f %f %s',-1);
end;
% Scale the data to a circle with x-axis and y-axis: -0.45 to 0.45
xcoord = 0.8*((xcoord-min(xcoord))/(max(xcoord)-min(xcoord))-0.5);
ycoord = 0.8*((ycoord-min(ycoord))/(max(ycoord)-min(ycoord))-0.5);
channelcombi=zeros(size(data.sgncmb));
for cc = 1:2
channelcmp=data.sgncmb(:,cc);
usedcounter = 0;
for jj=1:size(allchannels,1)
for kk=1:size(channelcmp,1)
if strcmp(allchannels{jj},channelcmp{kk})
channelcombi(kk,cc)=jj;
usedcounter = usedcounter + 1;
end
end
end
if usedcounter ~= size(channelcombi,1)
error('TRENTOOL ERROR: mismatch between cfg.sgncmb and data.label');
end
end
usedchannels=unique(sort(reshape(channelcombi,size(channelcombi,1)*size(channelcombi,2),1)));
channelxcoords=xcoord(usedchannels);
channelycoords=ycoord(usedchannels);
channelindex=index(usedchannels);
channelnames=allchannels(usedchannels);
flag1=0;flag2=0;
counter=1;
for ii=1:size(data.TEpermvalues,1),
switch lower(cfg.statstype)
case 1,
% corrected
if data.TEpermvalues(ii,3)==1
if flag1==0; flag1=1; end;
X(1,counter)=xcoord(channelcombi(ii,1));
X(2,counter)=xcoord(channelcombi(ii,2));
Y(1,counter)=ycoord(channelcombi(ii,1));
Y(2,counter)=ycoord(channelcombi(ii,2));
if data.TEpermvalues(ii,4)<=0
arrowvalue(counter)=0;
else
arrowvalue(counter)=1;
end
counter=counter+1;
end
case 2,
% uncorrected
if data.TEpermvalues(ii,2)==1
if flag2==0; flag2=1; end;
X(1,counter)=xcoord(channelcombi(ii,1));
X(2,counter)=xcoord(channelcombi(ii,2));
Y(1,counter)=ycoord(channelcombi(ii,1));
Y(2,counter)=ycoord(channelcombi(ii,2));
if data.TEpermvalues(ii,4)<=0
arrowvalue(counter)=0;
else
arrowvalue(counter)=1;
end
counter=counter+1;
end
case 3,
% 1-pvalue
%if data.TEpermvalues(ii,1)<=cfg.alpha
X(1,counter)=xcoord(channelcombi(ii,1));
X(2,counter)=xcoord(channelcombi(ii,2));
Y(1,counter)=ycoord(channelcombi(ii,1));
Y(2,counter)=ycoord(channelcombi(ii,2));
alinewidth(ii) = widthmultiplier*(1.0-data.TEpermvalues(ii,1)+0.0000000001);
if data.TEpermvalues(ii,4)<=0
arrowvalue(counter)=0;
else
arrowvalue(counter)=1;
end
counter=counter+1;
%end
case 4,
% mean dist
X(1,counter)=xcoord(channelcombi(ii,1));
X(2,counter)=xcoord(channelcombi(ii,2));
Y(1,counter)=ycoord(channelcombi(ii,1));
Y(2,counter)=ycoord(channelcombi(ii,2));
alinewidth(ii) = widthmultiplier*(data.TEpermvalues(ii,4));
if data.TEpermvalues(ii,4)<=0
arrowvalue(counter)=0;
else
arrowvalue(counter)=1;
end
counter=counter+1;
case 5,
% results after graph correction
if data.TEpermvalues(ii,2)==1 || data.TEpermvalues(ii,5)>1
X(1,counter)=xcoord(channelcombi(ii,1));
X(2,counter)=xcoord(channelcombi(ii,2));
Y(1,counter)=ycoord(channelcombi(ii,1));
Y(2,counter)=ycoord(channelcombi(ii,2));
alinewidth(ii) = widthmultiplier*(data.TEpermvalues(ii,4));
if data.TEpermvalues(ii,5)<=1
arrowvalue(counter)=0;
else
arrowvalue(counter)=1;
end
counter=counter+1;
end
end
end
if flag1 == 0 && cfg.statstype == 1
error('TRENTOOL error: No corrected significances are found. Try lower cfg.statstype value. (see help)')
elseif flag2 == 0 && cfg.statstype == 2
error('TRENTOOL error: No uncorrected significances are found. Try lower cfg.statstype value. (see help)')
end
% Define the outline of the head, ears and nose:
rmax=.5;
l = 0:2*pi/100:2*pi;
tip = rmax*1.15; base = rmax-.004;
EarX = [.497 .510 .518 .5299 .5419 .54 .547 .532 .510 .489];
EarY = [.0555 .0775 .0783 .0746 .0555 -.0055 -.0932 -.1313 -.1384 -.1199];
hold on
% Plot head, ears, and nose:
if cfg.plothead
plot(cos(l).*rmax, sin(l).*rmax, 'color', cfg.hcolor , 'Linestyle', '-', 'LineWidth', cfg.hlinewidth);
plot([0.18*rmax;0;-0.18*rmax], [base;tip;base], 'Color', cfg.hcolor , 'LineWidth', cfg.hlinewidth);
plot( EarX, EarY, 'color', cfg.hcolor , 'LineWidth', cfg.hlinewidth)
plot(-EarX, EarY, 'color', cfg.hcolor , 'LineWidth', cfg.hlinewidth)
%hold off
end
%hold on
% Plot all electrodes
if strcmp(cfg.electrodes,'on')||strcmp(cfg.showlabels,'markers')
%hold on
for ii = 1:size(xcoord,1)
plot(xcoord(ii),ycoord(ii),cfg.emarker,'Color',cfg.ecolor,'Linewidth',cfg.emarkersize)
end
end
%plot used channels
if strcmp(cfg.electrodes,'on')||strcmp(cfg.electrodes,'highlights')||strcmp(cfg.electrodes,'labels')||strcmp(cfg.electrodes,'numbers')||strcmp(cfg.showlabels,'markers')
%hold on
for jj = 1:size(channelxcoords,1)
plot(channelxcoords(jj),channelycoords(jj),cfg.hlmarker,'Color',cfg.hlcolor,'Linewidth',cfg.hlmarkersize)
end
end
% plot arrows
if cfg.statstype <= 2 || cfg.statstype == 5
for kk = 1:size(X,2)
if arrowvalue(kk)==0
TEarrow(X(1,kk),X(2,kk),Y(1,kk),Y(2,kk),cfg.alinewidth,cfg.arrowcolorneg,cfg.arrowpos);
else
TEarrow(X(1,kk),X(2,kk),Y(1,kk),Y(2,kk),cfg.alinewidth,cfg.arrowcolorpos,cfg.arrowpos);
end
end
else
for kk = 1:size(X,2)
if arrowvalue(kk)==0
TEarrow(X(1,kk),X(2,kk),Y(1,kk),Y(2,kk),cfg.alinewidth,cfg.arrowcolorneg,cfg.arrowpos);
TEarrow(0.58,0.58,-0.2,0.2,widthmultiplier,cfg.arrowcolorneg,cfg.arrowpos);
else
TEarrow(X(1,kk),X(2,kk),Y(1,kk),Y(2,kk),cfg.alinewidth,cfg.arrowcolorpos,cfg.arrowpos);
TEarrow(0.58,0.58,-0.2,0.2,widthmultiplier,cfg.arrowcolorpos,cfg.arrowpos);
end
end
end
% Plot labels of used channels
if strcmp(cfg.electrodes,'labels') || strcmp(cfg.showlabels,'yes')
for ii=1:size(usedchannels,1)
%h=text(channelxcoords(ii)+0.01,channelycoords(ii)+0.01,channelnames(ii));
h=text(channelxcoords(ii)+0.03,channelycoords(ii)+0.03,channelnames(ii));
set(h,'FontSize',cfg.efsize,'Color',cfg.efcolor);
end
elseif strcmp(cfg.electrodes,'numbers') || strcmp(cfg.showlabels,'numbers')
for ii=1:size(usedchannels,1)
h=text(channelxcoords(ii)+0.01,channelycoords(ii)+0.01,num2str(channelindex(ii)));
set(h,'FontSize',cfg.efsize,'Color',cfg.efcolor);
end
end
hold off
axis off;
set(gca, 'YLim', [-0.5 .6],...
'XLim', [-0.6 .6],...
'Visible', 'off',...
'Box','off');
title(gca,strcat(['Connectivity arrows: ',sl]),'FontSize',20);
end