-
Notifications
You must be signed in to change notification settings - Fork 1
/
pop_plotIMAcluster.m
127 lines (111 loc) · 5.4 KB
/
pop_plotIMAcluster.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
%
% plots spectral templates, dipole density and scalpmaps for IM clusters
%
%
% pop_plotIMAcluster(STUDY,varargin);
%
%
% Author: Johanna Wagner, Swartz Center for Computational Neuroscience, UC
% San Diego, Feb 2020
% adapted from a function written by Julie Onton
%
% Example plotting cluster numbers 1 and 2 and restricting spectra to 3 60
% Hz and log frequency scale
% >> pop_plotIMAcluster(STUDY, 'clust', [1 2], 'freqlim', [3 60], 'freqscale', 'log')
%
% Example plotting subclusters and scalpmaps
% >> pop_plotIMAcluster(STUDY, 'plotsubclusters', 'on', 'plotscalpmaps', 'on')
%
%
% INPUTS:
% required Inputs:
% STUDY - STUDY structure with information on stored IMA files
%
% optional Inputs:
% plotclust - 'string' 'on' or 'off' - default 'on' - may be turned off
% when wanting to plot only subclusters
% clust - [vector] 'vector of integers' vector of cluster indices to plot
% if empty plot all clusters
% freqscale - 'string' frequency scale to plot spectra 'linear' or 'log'
% default 'log'
% freqlim - [min max] 'integers' provide min - max frequency range; ...
%
% plotsubclusters - 'string' 'on' or 'off' specifies whether to plot
% subclusters - plots only the subclusters previously
% defined in pop_subclusterIMAtemplates - default 'off'
% plottemplates - 'string' 'on' or 'off' specifies whether to plot
% spectral templates - default 'off'
% plotdipsources - 'string' 'on' or 'off' specifies whether to plot
% dipole density plots - default 'off'
% plotscalpmaps - 'string' 'on' or 'off' specifies whether to plot
% scalpmaps - default 'off'
%
% OUTPUTS: plots of diploedensity, spectra and scalpmaps of clusters and subclusters
function pop_plotIMAcluster(STUDY,varargin);
g = finputcheck(varargin, {'freqlim' 'integer' [] []; ...
'clust' 'integer' [] [];...
'plotclust' 'string' {'on' 'off'} 'on';...
'freqscale' 'string' {'linear' 'log'} 'log';...
'plotsubclusters' 'string' {'on' 'off'} 'off';...
'plottemplates' 'string' {'on' 'off'} 'off';...
'plotdipsources' 'string' {'on' 'off'} 'off';...
'plotscalpmaps' 'string' {'on' 'off'} 'off';...
}, 'inputgui');
if isstr(g), error(g); end;
if nargin == 1
onofflabel = {'off' 'on'};
freqscalelabel = {'linear' 'log'};
uilist = {{'style' 'text' 'string' 'IM clusters'} {'style' 'edit' 'string' '' 'tag' 'clustnum'}...
{'style' 'text' 'string' 'Freq. limits (Hz)'} {'style' 'edit' 'string' '' 'tag' 'freqlimits'}...
{'style' 'text' 'string' 'Freq. scale'} {'style' 'popupmenu' 'string' {'linear', 'log'} 'tag' 'frescale' 'value' 2}...
{'style' 'text' 'string' 'Plotting options'} ...
{'style' 'checkbox' 'string' 'Templates' 'Tag' 'cbox_plottemplates'} ...
{'style' 'checkbox' 'string' 'Dipoles' 'Tag' 'cbox_plotdipoles'} ...
{'style' 'checkbox' 'string' 'Scalp maps' 'Tag' 'cbox_plotscalpmaps'} ...
};
% {'style' 'checkbox' 'string' 'Clusters' 'Tag' 'cbox_plotcluster'} ...
% {'style' 'checkbox' 'string' 'Subclusters' 'Tag' 'cbox_pltsbcluster'} ...
%
ht = 5; wt = 4 ;
geom = {{wt ht [0 0] [1 1]} {wt ht [1 0] [3 1]}...
{wt ht [0 1] [1 1]} {wt ht [1 1] [1 1]} {wt ht [2.2 1] [1 1]} {wt ht [3 1] [1 1]}...
{wt ht [0 2] [1 1]}...
{wt ht [1 3] [1 1]}...
{wt ht [1 4] [1 1]}...
{wt ht [1 5] [1 1]}...
};
[result, ~, ~, resstruct, ~] = inputgui('title','Plot IM clusters -- pop_plotIMAcluster', 'geom', geom, 'uilist',uilist, 'helpcom','pophelp(''pop_plotIMAcluster'');');
if isempty(result), return; end;
g.freqlim = str2num(resstruct.freqlimits);
g.clust = str2num(resstruct.clustnum);
g.freqscale = freqscalelabel{resstruct.frescale};
g.plottemplates = onofflabel{resstruct.cbox_plottemplates+1};
g.plotdipsources = onofflabel{resstruct.cbox_plotdipoles+1};
g.plotscalpmaps = onofflabel{resstruct.cbox_plotscalpmaps+1};
end
subjcode = STUDY.subject;
templates = [];
IMICindex = [];
dipsources = [];
scalpmaps = [];
for iko = 1:length(subjcode)
indsj = find(ismember(STUDY.subject, subjcode{iko}));
%% load IMA file for curent subject
%load([STUDY.etc.IMA.imafilepath{indsj} filesep STUDY.etc.IMA.imafilename{indsj}], '-mat' );
load([STUDY.etc.IMA.imafilepath{indsj} filesep STUDY.etc.IMA.imafilename{indsj}], '-mat' );
str = string(STUDY.subject(iko));
sujnum = sscanf(str,'S%d');
if isempty(g.freqlim)
g.freqlim = IMA.freqlim;
end
[val, freqind1] = min(abs(IMA.freqvec-g.freqlim(1)));
[val, freqind2] = min(abs(IMA.freqvec-g.freqlim(2)));
templates = [templates; IMA.precluster.templates(:,freqind1:freqind2)];
dipsources = [dipsources IMA.precluster.dipsources];
scalpmaps = [scalpmaps; IMA.precluster.scalpmaps];
freqvec = IMA.freqvec(freqind1:freqind2);
end
plotIMAcluster(STUDY.etc.IMA.clustidx, 'plotclust', g.plotclust, 'clust', g.clust,...
'freqscale', IMA.freqscale,'plottemplates', g.plottemplates, 'templates', templates,...
'freqvec', freqvec, 'plotdipsources', g.plotdipsources, 'dipsources', dipsources,...
'plotscalpmaps', g.plotscalpmaps, 'scalpmaps', scalpmaps,'plotsubclusters', g.plotsubclusters)