From 660f198c12ed7ad15267e324f4779a19af347feb Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Tue, 10 May 2022 13:43:31 +0000 Subject: [PATCH 1/6] added colored labels corresponding to lobe --- pop_roi_connectplot.m | 791 ++++++++++++++++++++++++++++-------------- 1 file changed, 532 insertions(+), 259 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 9562f33..a19474e 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -58,285 +58,558 @@ function [matrix, com] = pop_roi_connectplot(EEG, varargin) -matrix = []; -com = ''; -if nargin < 1 - help pop_roi_connectplot; - return -end + matrix = []; + com = ''; + if nargin < 1 + help pop_roi_connectplot; + return + end -if ~isfield(EEG, 'roi') - error('Compute connectivity first'); -end + if ~isfield(EEG, 'roi') + error('Compute connectivity first'); + end -% if ~isfield(EEG.dipfit, 'hdmfile') -% error('You need to select a head model file using DIPFIT settings first'); -% end -% -% if ~isequal(EEG.dipfit.coordformat, 'MNI') -% error('You can only use this function with MNI coordinates - change head model'); -% end - -cortexFlag = isfield(EEG.roi.cortex, 'Faces'); - -splot = []; -splot(end+1).label = 'Source power spectrum'; -splot(end ).acronym = 'PSD'; -splot(end ).unit = '?'; % not used yet -splot(end ).cortex = cortexFlag; -splot(end ).matrix = -1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI based power spectrum'; -splot(end ).acronym = 'ROIPSD'; -splot(end ).unit = '?'; % not used yet -splot(end ).cortex = cortexFlag; -splot(end ).matrix = -1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI to ROI cross-spectrum'; -splot(end ).labelshort = 'Cross-spectrum'; -splot(end ).acronym = 'crossspecpow'; -splot(end ).unit = 'Power (dB)'; -splot(end ).cortex = cortexFlag; -splot(end ).matrix = -1; -splot(end ).psd = 0; - -splot(end+1).label = 'ROI to ROI imaginary part of cross-spectrum'; -splot(end ).labelshort = 'Img. part of cross-spectrum'; -splot(end ).acronym = 'crossspecimag'; -splot(end ).unit = 'net |iCOH|'; -splot(end ).cortex = cortexFlag; -splot(end ).matrix = 1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI to ROI coherence'; -splot(end ).labelshort = 'Coherence'; -splot(end ).acronym = 'Coh'; -splot(end ).unit = '?'; -splot(end ).cortex = cortexFlag; -splot(end ).matrix = 1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI to ROI granger causality'; -splot(end ).labelshort = 'Granger Causality'; -splot(end ).acronym = 'GC'; -splot(end ).cortex = cortexFlag; -splot(end ).matrix = 1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI to ROI time-reversed granger causality'; -splot(end ).labelshort = 'Time-rev. Granger Causality'; -splot(end ).acronym = 'TRGC'; -splot(end ).unit = '?'; % not used yet -splot(end ).cortex = cortexFlag; -splot(end ).matrix = 1; -splot(end ).psd = -1; - -splot(end+1).label = 'ROI to ROI Maximized Imag. Coh.'; -splot(end ).labelshort = 'Maximized Imag. Coh.'; -splot(end ).acronym = 'MIC'; -splot(end ).unit = '?'; % not used yet -splot(end ).cortex = cortexFlag; -splot(end ).matrix = -1; -splot(end ).psd = 0; - -splot(end+1).label = 'ROI to ROI Multivariate Interaction Measure'; -splot(end ).labelshort = 'Multivariate Interaction Measure'; -splot(end ).acronym = 'MIM'; -splot(end ).unit = '?'; % not used yet -splot(end ).cortex = cortexFlag; -splot(end ).matrix = -1; -splot(end ).psd = 0; - -if nargin < 2 - - cb_select = [ 'usrdat = get(gcf, ''userdata'');' ... - 'usrdat = usrdat(get(findobj(gcf, ''tag'', ''selection''), ''value''));' ... - 'fieldTmp = { ''cortex'' ''matrix'' ''psd'' };' ... - 'for iField = 1:length(fieldTmp),' ... - ' if usrdat.(fieldTmp{iField}) == 1,' ... - ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''on'', ''value'', 1);' ... - ' elseif usrdat.(fieldTmp{iField}) == 0,' ... - ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''on'', ''value'', 0);' ... - ' else,' ... - ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''off'', ''value'', 0);' ... - ' end;' ... - 'end;' ... - 'clear iField fieldTmp usrdat;' ]; - - uigeom = { [1 1] [1 1] 1 [0.3 1.1 1 1] }; - uilist = {{ 'style' 'text' 'string' 'Select a measure to plot' 'fontweight' 'bold'} ... - { 'style' 'popupmenu' 'string' {splot.label} 'callback' cb_select 'value' 4 'tag' 'selection' } ... - { 'style' 'text' 'string' 'Frequency range in Hz [min max]:'} ... - { 'style' 'edit' 'string' ''} ... - {} ... - {} ... - { 'style' 'checkbox' 'string' 'Plot on cortex' 'tag' 'cortex' 'value' 1 } ... - { 'style' 'checkbox' 'string' 'Plot PSD' 'tag' 'psd' 'enable' 'off' } ... - { 'style' 'checkbox' 'string' 'Plot in matrix' 'tag' 'matrix' 'enable' 'off' } ... - }; - - [result,~,~,outs] = inputgui('geometry', uigeom, 'uilist', uilist, 'helpcom', 'pophelp(''pop_loadbv'')', ... - 'title', 'ROI connectivity', 'userdata', splot, 'eval', cb_select); - if isempty(result), return, end + % if ~isfield(EEG.dipfit, 'hdmfile') + % error('You need to select a head model file using DIPFIT settings first'); + % end + % + % if ~isequal(EEG.dipfit.coordformat, 'MNI') + % error('You can only use this function with MNI coordinates - change head model'); + % end + + cortexFlag = isfield(EEG.roi.cortex, 'Faces'); + + splot = []; + splot(end+1).label = 'Source power spectrum'; + splot(end ).acronym = 'PSD'; + splot(end ).unit = '?'; % not used yet + splot(end ).cortex = cortexFlag; + splot(end ).matrix = -1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI based power spectrum'; + splot(end ).acronym = 'ROIPSD'; + splot(end ).unit = '?'; % not used yet + splot(end ).cortex = cortexFlag; + splot(end ).matrix = -1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI to ROI cross-spectrum'; + splot(end ).labelshort = 'Cross-spectrum'; + splot(end ).acronym = 'crossspecpow'; + splot(end ).unit = 'Power (dB)'; + splot(end ).cortex = cortexFlag; + splot(end ).matrix = -1; + splot(end ).psd = 0; + + splot(end+1).label = 'ROI to ROI imaginary part of cross-spectrum'; + splot(end ).labelshort = 'Img. part of cross-spectrum'; + splot(end ).acronym = 'crossspecimag'; + splot(end ).unit = 'net |iCOH|'; + splot(end ).cortex = cortexFlag; + splot(end ).matrix = 1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI to ROI coherence'; + splot(end ).labelshort = 'Coherence'; + splot(end ).acronym = 'Coh'; + splot(end ).unit = '?'; + splot(end ).cortex = cortexFlag; + splot(end ).matrix = 1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI to ROI granger causality'; + splot(end ).labelshort = 'Granger Causality'; + splot(end ).acronym = 'GC'; + splot(end ).cortex = cortexFlag; + splot(end ).matrix = 1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI to ROI time-reversed granger causality'; + splot(end ).labelshort = 'Time-rev. Granger Causality'; + splot(end ).acronym = 'TRGC'; + splot(end ).unit = '?'; % not used yet + splot(end ).cortex = cortexFlag; + splot(end ).matrix = 1; + splot(end ).psd = -1; + + splot(end+1).label = 'ROI to ROI Maximized Imag. Coh.'; + splot(end ).labelshort = 'Maximized Imag. Coh.'; + splot(end ).acronym = 'MIC'; + splot(end ).unit = '?'; % not used yet + splot(end ).cortex = cortexFlag; + splot(end ).matrix = -1; + splot(end ).psd = 0; + + splot(end+1).label = 'ROI to ROI Multivariate Interaction Measure'; + splot(end ).labelshort = 'Multivariate Interaction Measure'; + splot(end ).acronym = 'MIM'; + splot(end ).unit = '?'; % not used yet + splot(end ).cortex = cortexFlag; + splot(end ).matrix = -1; + splot(end ).psd = 0; - options = {}; - options = { options{:} 'measure' splot(result{1}).acronym }; - options = { options{:} 'freqrange' eval( [ '[' result{2} ']' ] ) }; - options = { options{:} 'plotcortex' fastif(outs.cortex, 'on', 'off') }; - options = { options{:} 'plotmatrix' fastif(outs.matrix, 'on', 'off') }; - options = { options{:} 'plotpsd' fastif(outs.psd , 'on', 'off') }; -else - options = varargin; -end + if nargin < 2 -% decode input parameters -% ----------------------- -g = finputcheck(options, { 'measure' 'string' {splot.acronym} ''; - 'freqrange' 'real' { } []; - 'smooth' 'real' { } 0.35; - 'plotcortex' 'string' { 'on' 'off' } 'on'; - 'plotmatrix' 'string' { 'on' 'off' } 'off'; - 'plotpsd' 'string' { 'on' 'off' } 'off' }, 'pop_roi_connectplot'); -if ischar(g), error(g); end -S = EEG.roi; - -% colormap -load cm17; - -% frequency range -if ~isempty(g.freqrange) - frq_inds = find(S.freqs >= g.freqrange(1) & S.freqs < g.freqrange(2)); - titleStr = sprintf('%1.1f-%1.1f Hz frequency band', g.freqrange(1), g.freqrange(2)); -else - frq_inds = 1:length(S.freqs); - titleStr = 'broadband'; -end + cb_select = [ 'usrdat = get(gcf, ''userdata'');' ... + 'usrdat = usrdat(get(findobj(gcf, ''tag'', ''selection''), ''value''));' ... + 'fieldTmp = { ''cortex'' ''matrix'' ''psd'' };' ... + 'for iField = 1:length(fieldTmp),' ... + ' if usrdat.(fieldTmp{iField}) == 1,' ... + ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''on'', ''value'', 1);' ... + ' elseif usrdat.(fieldTmp{iField}) == 0,' ... + ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''on'', ''value'', 0);' ... + ' else,' ... + ' set(findobj(gcf, ''tag'', fieldTmp{iField}), ''enable'', ''off'', ''value'', 0);' ... + ' end;' ... + 'end;' ... + 'clear iField fieldTmp usrdat;' ]; -% plotting options -allMeasures = { splot.acronym }; -pos = strmatch( g.measure, allMeasures, 'exact'); -plotOpt = splot(pos); - -switch lower(g.measure) - case { 'psd' 'roipsd' } - if strcmpi(g.measure, 'psd') - % plot poower of individual voxels - % we would need to save the power in roi_activity. The function below can plot power - % allplots_cortex_BS(S.cortex, P_dB, [min(P_dB) max(P_dB)], cm17a, 'power [dB]', g.smooth); - error('This option is obsolete'); - end - - if strcmpi(g.plotcortex, 'on') - if strcmpi(lower(g.measure), 'roipsd') - source_roi_power_norm_dB = 10*log10( mean(EEG.roi.source_roi_power(frq_inds,:)) ); - allplots_cortex_BS(S.cortex, source_roi_power_norm_dB, [min(source_roi_power_norm_dB) max(source_roi_power_norm_dB)], cm17a, 'power [dB]', g.smooth); - h = textsc([ 'ROI source power (' titleStr ')' ], 'title'); - set(h, 'fontsize', 20); - end - end + uigeom = { [1 1] [1 1] 1 [0.3 1.1 1 1] }; + uilist = {{ 'style' 'text' 'string' 'Select a measure to plot' 'fontweight' 'bold'} ... + { 'style' 'popupmenu' 'string' {splot.label} 'callback' cb_select 'value' 4 'tag' 'selection' } ... + { 'style' 'text' 'string' 'Frequency range in Hz [min max]:'} ... + { 'style' 'edit' 'string' ''} ... + {} ... + {} ... + { 'style' 'checkbox' 'string' 'Plot on cortex' 'tag' 'cortex' 'value' 1 } ... + { 'style' 'checkbox' 'string' 'Plot PSD' 'tag' 'psd' 'enable' 'off' } ... + { 'style' 'checkbox' 'string' 'Plot in matrix' 'tag' 'matrix' 'enable' 'off' } ... + }; + + [result,~,~,outs] = inputgui('geometry', uigeom, 'uilist', uilist, 'helpcom', 'pophelp(''pop_loadbv'')', ... + 'title', 'ROI connectivity', 'userdata', splot, 'eval', cb_select); + if isempty(result), return, end + + options = {}; + options = { options{:} 'measure' splot(result{1}).acronym }; + options = { options{:} 'freqrange' eval( [ '[' result{2} ']' ] ) }; + options = { options{:} 'plotcortex' fastif(outs.cortex, 'on', 'off') }; + options = { options{:} 'plotmatrix' fastif(outs.matrix, 'on', 'off') }; + options = { options{:} 'plotpsd' fastif(outs.psd , 'on', 'off') }; + else + options = varargin; + end + + % decode input parameters + % ----------------------- + g = finputcheck(options, { 'measure' 'string' {splot.acronym} ''; + 'freqrange' 'real' { } []; + 'smooth' 'real' { } 0.35; + 'plotcortex' 'string' { 'on' 'off' } 'on'; + 'plotmatrix' 'string' { 'on' 'off' } 'off'; + 'plotpsd' 'string' { 'on' 'off' } 'off'; + 'plotbarplot' 'string' { 'on' 'off'} 'off'; + 'hemisphere' 'string' {'all' 'left' 'right'} 'all'; + 'region' 'string' { 'all', 'cingulate', 'prefrontal', 'frontal', 'temporal', 'parietal', 'central', 'occipital' } 'all'; + 'largeplot', 'string' { 'on' 'off' } 'off'}, 'pop_roi_connectplot'); + + if ischar(g), error(g); end + S = EEG.roi; + + % colormap + load cm17; + + % frequency range + if ~isempty(g.freqrange) + frq_inds = find(S.freqs >= g.freqrange(1) & S.freqs < g.freqrange(2)); + titleStr = sprintf('%1.1f-%1.1f Hz frequency band', g.freqrange(1), g.freqrange(2)); + else + frq_inds = 1:length(S.freqs); + titleStr = 'broadband'; + end + + % plotting options + allMeasures = { splot.acronym }; + pos = strmatch( g.measure, allMeasures, 'exact'); + plotOpt = splot(pos); + + % either plot large plot with MIM, TRGC and power or only individual plots + if strcmpi(g.largeplot, 'on') + source_roi_power_norm_dB = 10*log10( mean(EEG.roi.source_roi_power(frq_inds,:)) ); % roipsd - case { 'trgc' 'gc' } - % calculation of net TRGC scores (i->j minus j->i), recommended procedure - % TRGCnet = TRGC_(:, 1:2:end)-TRGC_(:, 2:2:end); - % new way to compute net scores - if strcmpi(g.measure, 'GC') - TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); - else - TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); - end + TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); % trgc TRGC = get_connect_mat( TRGCnet, S.nROI, -1); + TRGC_matrix = squeeze(mean(TRGC(frq_inds, :, :))); - if strcmpi(g.plotmatrix, 'on') - matrix = squeeze(mean(TRGC(frq_inds, :, :))); - figure; imagesc(matrix); colorbar - xlabel('ROI index (see Atlas for more info)'); - h = title([ 'ROI to ROI ' upper(g.measure) ' (' titleStr ')' ]); - set(h, 'fontsize', 16); - end - - if strcmpi(g.plotcortex, 'on') - atrgc = mean(squeeze(mean(TRGC(frq_inds, :, :))), 2); - allplots_cortex_BS(S.cortex, atrgc, [-max(abs(atrgc)) max(abs(atrgc))], cm17, upper(g.measure), g.smooth); - h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); - set(h, 'fontsize', 20); - end + MI = S.MIM(:, :); + MI = get_connect_mat( MI, S.nROI, +1); + MIM_matrix = squeeze(mean(MI(frq_inds, :, :))); - case { 'mim' 'mic' } - if strcmpi(g.measure, 'MIC') - MI = S.MIC(:, :); - else - MI = S.MIM(:, :); + pltlarge(EEG, MIM_matrix, TRGC_matrix, source_roi_power_norm_dB, titleStr) + else + switch lower(g.measure) + case { 'psd' 'roipsd' } + if strcmpi(g.measure, 'psd') + % plot power of individual voxels + % we would need to save the power in roi_activity. The function below can plot power + % allplots_cortex_BS(S.cortex, P_dB, [min(P_dB) max(P_dB)], cm17a, 'power [dB]', g.smooth); + error('This option is obsolete'); + end + + if strcmpi(g.plotcortex, 'on') + if strcmpi(lower(g.measure), 'roipsd') + source_roi_power_norm_dB = 10*log10( mean(EEG.roi.source_roi_power(frq_inds,:)) ); + allplots_cortex_BS(S.cortex, source_roi_power_norm_dB, [min(source_roi_power_norm_dB) max(source_roi_power_norm_dB)], cm17a, 'power [dB]', g.smooth); + h = textsc([ 'ROI source power (' titleStr ')' ], 'title'); + set(h, 'fontsize', 20); + movegui(gcf, 'south') % remove after + end + end + + if strcmpi(g.plotbarplot, 'on') + source_roi_power_norm_dB = 10*log10( mean(EEG.roi.source_roi_power(frq_inds,:)) ); + pltmatrix(EEG, source_roi_power_norm_dB, titleStr, g.measure, g.hemisphere, g.region); + end + + case { 'trgc' 'gc' } + % calculation of net TRGC scores (i->j minus j->i), recommended procedure + % TRGCnet = TRGC_(:, 1:2:end)-TRGC_(:, 2:2:end); + % new way to compute net scores + if strcmpi(g.measure, 'GC') + TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); + else + TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); + end + TRGC = get_connect_mat( TRGCnet, S.nROI, -1); + + if strcmpi(g.plotmatrix, 'on') + matrix = squeeze(mean(TRGC(frq_inds, :, :))); + pltmatrix(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); + end + + if strcmpi(g.plotcortex, 'on') + atrgc = mean(squeeze(mean(TRGC(frq_inds, :, :))), 2); + allplots_cortex_BS(S.cortex, atrgc, [-max(abs(atrgc)) max(abs(atrgc))], cm17, upper(g.measure), g.smooth); + h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); + set(h, 'fontsize', 20); + movegui(gcf, 'south') % remove after + end + + case { 'mim' 'mic' } + if strcmpi(g.measure, 'MIC') + MI = S.MIC(:, :); + else + MI = S.MIM(:, :); + end + MI = get_connect_mat( MI, S.nROI, +1); + + if strcmpi(g.plotmatrix, 'on') + matrix = squeeze(mean(MI(frq_inds, :, :))); + pltmatrix(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); + end + + if strcmpi(g.plotcortex, 'on') + ami = mean(squeeze(mean(MI(frq_inds, :, :))), 2); + allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17, upper(g.measure), g.smooth); + h = textsc([ upper(g.measure) ' (' titleStr ');' ], 'title'); + set(h, 'fontsize', 20); + movegui(gcf, 'south') % remove after + end + + case { 'crossspecpow' 'coh' 'crossspecimag' } + if strcmpi(g.measure, 'coh') + PS = S.COH; % do not know what to do here + PS = squeeze(mean(mean(reshape(PS, S.srate+1, 3, S.nROI, 3, S.nROI), 2), 4)); + PSmean = mean(squeeze(mean(PS(frq_inds, :, :))), 2); + elseif strcmpi(g.measure, 'crossspecimag') + PS = abs(imag(cs2coh(S.CS))); % shape (before and afterwards): (101,204,204) + % anstatt '3' variable PCA components (wahrscheinlich + % irgendwo in EEG.roi) + PS = squeeze(mean(mean(reshape(PS, S.srate+1, 3, S.nROI, 3, S.nROI), 2), 4)); % afterwards shape: (101,68,68) + PSmean = mean(squeeze(mean(PS(frq_inds, :, :))), 2); % afterwards shape: (68,1) + else + PS = cs2psd(S.CS); + apow = squeeze(sum(sum(reshape(PS(frq_inds, :), [], S.nPCA, S.nROI), 1), 2)).*S.source_roi_power_norm'; + PSmean = 10*log10(apow); + end + + if strcmpi(g.plotmatrix, 'on') + matrix = squeeze(mean(PS(frq_inds, :, :))); + figure; imagesc(matrix); colormap(cm17a); colorbar + xlabel('ROI index (see Atlas for more info)'); + h = title([ plotOpt.label ' (' titleStr ')']); + set(h, 'fontsize', 16); + end + + if strcmpi(g.plotcortex, 'on') + allplots_cortex_BS(S.cortex, PSmean, [min(PSmean) max(PSmean)], cm17a, plotOpt.unit, g.smooth); + h = textsc([ plotOpt.labelshort ' (' titleStr ')' ], 'title'); + set(h, 'fontsize', 20); + movegui(gcf, 'south') % remove after + end + + if strcmpi(g.plotpsd, 'on') + figure; semilogy(S.freqs(frq_inds), PSmean(frq_inds, :)); grid on + h = textsc(plotOptS.label, 'title'); + set(h, 'fontsize', 20); + end + end - MI = get_connect_mat( MI, S.nROI, +1); + end + + if nargin < 2 + com = sprintf('pop_roi_connectplot(EEG, %s);', vararg2str( options )); + end +end - if strcmpi(g.plotmatrix, 'on') - matrix = squeeze(mean(MI(frq_inds, :, :))); - figure; imagesc(matrix); colorbar - xlabel('ROI index (see Atlas for more info)'); - h = title(['ROI to ROI imag. part of coherence (' titleStr ')']); - set(h, 'fontsize', 16); - end +function measure = get_connect_mat( measureOri, nROI, signVal) + % create a ROI x ROI connectivity matrix, if needed + % TRGCmat(f, ii, jj) is net TRGC from jj to ii + measure = []; + iinds = 0; + for iroi = 1:nROI + for jroi = (iroi+1):nROI + iinds = iinds + 1; + measure(:, iroi, jroi) = signVal * measureOri(:, iinds); + measure(:, jroi, iroi) = measureOri(:, iinds); + end + end +end - if strcmpi(g.plotcortex, 'on') - ami = mean(squeeze(mean(MI(frq_inds, :, :))), 2); - allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17, upper(g.measure), g.smooth); - h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); - set(h, 'fontsize', 20); +function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) + % plot individual ROI to ROI matrix with colored labels (corresponding lobes/regions) + + % colormap + load cm17 + switch lower(measure) + case {'mim', 'mic', 'coh'} + cmap = cm17a; + otherwise + cmap = cm17; + end + + % plot matrix with colored labels sorted by region according to the + % Desikan-Killiany atlas + labels = strings(1,length(EEG.roi.atlas.Scouts)); + for i = 1:length(labels) + scout = struct2cell(EEG.roi.atlas.Scouts(i)); + labels(i) = char(scout(1)); + end + labels = cellstr(labels); + + % assign labels to colors + colors = {[0,0,0]/255, [163, 107, 64]/255, [171, 163, 71]/255, [217, 37, 88]/255, [113, 15, 82]/255,[35, 103, 81]/255,[2, 45, 126]/255,}; + roi_loc ={'LT';'RT';'LL';'RL';'LF';'RF';'LO';'RO';'LT';'RT';'LPF';'RPF';'LT';'RT';'LP';'RP';'LT';'RT';'LT';'RT';'LL';'RL';'LO';'RO';'LPF';'RPF';'LO';'RO';'LPF';'RPF';'LT';'RT';'LC';'RC';'LT';'RT';'LF';'RF';'LPF';'RPF';'LF';'RF';'LO';'RO';'LC';'RC';'LL';'RL';'LC';'RC';'LP';'RP';'LL';'RL';'LF';'RF';'LF';'RF';'LP';'RP';'LT';'RT';'LP';'RP';'LT';'RT';'LT';'RT'}; + roi_loc = string(roi_loc); + roi_loc = strrep(roi_loc, 'PF', '2'); + roi_loc = strrep(roi_loc, 'F', '3'); + roi_loc = strrep(roi_loc, 'T', '4'); + roi_loc = strrep(roi_loc, 'P', '5'); + roi_loc = strrep(roi_loc, 'C', '6'); + roi_loc = strrep(roi_loc, 'O', '7'); + roi_loc = strrep(roi_loc, 'LL', 'L1'); + roi_loc = strrep(roi_loc, 'RL', 'R1'); + roi_loc = strrep(roi_loc, 'L', ''); + roi_loc = strrep(roi_loc, 'R', ''); + [color_idxx,roi_idxx] = sort(str2double(roi_loc)); + labels_dk_cell_idx = labels(roi_idxx); + + if strcmpi(measure, 'roipsd') % plot barplot for power +% f = figure(); +% f.WindowState = 'maximized'; + barh(matrix(roi_idxx)); + + set(gca, 'YDir', 'reverse'); + set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontweight','bold','fontsize', 9, 'TickLength',[0.015, 0.02], 'LineWidth',0.7); + h = title([ 'ROI source power' ' (' titleStr ')' ]); + set(h, 'fontsize', 16); + ylabel('power [dB]') + + ax = gca; + for i=1:numel(roi_idxx) + ax.YTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i)}); end + pos = get(gcf, 'Position'); + set(gcf, 'Position', [pos(1) pos(2) pos(3) pos(4)*1.8]) + movegui(gcf, 'south') % remove after - case { 'crossspecpow' 'coh' 'crossspecimag' } - if strcmpi(g.measure, 'coh') - PS = S.COH; % do not know what to do here - PS = squeeze(mean(mean(reshape(PS, S.srate+1, 3, S.nROI, 3, S.nROI), 2), 4)); - PSmean = mean(squeeze(mean(PS(frq_inds, :, :))), 2); - elseif strcmpi(g.measure, 'crossspecimag') - PS = abs(imag(cs2coh(S.CS))); - PS = squeeze(mean(mean(reshape(PS, S.srate+1, 3, S.nROI, 3, S.nROI), 2), 4)); - PSmean = mean(squeeze(mean(PS(frq_inds, :, :))), 2); + else % create fc matrix + % assign region input to an index + [GC, GR] = groupcounts(roi_loc); + switch lower(region) + case 'cingulate' + region_idx = 1; + case 'prefrontal' + region_idx = 2; + case 'frontal' + region_idx = 3; + case 'temporal' + region_idx = 4; + case 'parietal' + region_idx = 5; + case 'central' + region_idx = 6; + case 'occipital' + region_idx = 7; + otherwise + region_idx = 99; + end + + matrix = matrix(roi_idxx, roi_idxx); % sort matrix according to color scheme + % reduce matrix to only keep components corresponding to selected region + if not(region_idx == 99) + if region_idx == 1 + start_idx = 1; + else + start_idx = 1 + sum(GC(1:region_idx-1)); + end + end_idx = start_idx + GC(region_idx) - 1; + matrix = matrix(start_idx:end_idx, start_idx:end_idx); + labels_dk_cell_idx = labels_dk_cell_idx(start_idx:end_idx); + color_idxx = color_idxx(start_idx:end_idx); + end + n_roi_labels = size(matrix, 1); % only 68 if no region is selected + + % create dummy plot and add custom legend + f = figure(); + f.WindowState = 'maximized'; + hold on + n_dummy_labels = 7; + x = 1:10; + for k=1:n_dummy_labels + plot(x, x*k, '-', 'LineWidth', 9, 'Color', colors{k}); + end + + % hemisphere parameters to determine which labels to use + if strcmpi(hemisphere, 'left') + hem_idx = {1 2 2}; % use labels 1:2:68 (first two values), only use 1/2 of the labels (3rd value) + elseif strcmpi(hemisphere, 'right') + hem_idx = {2 2 2}; % use labels 2:2:68 (first two values), only use 1/2 of the labels (3rd value) else - PS = cs2psd(S.CS); - apow = squeeze(sum(sum(reshape(PS(frq_inds, :), [], S.nPCA, S.nROI), 1), 2)).*S.source_roi_power_norm'; - PSmean = 10*log10(apow); + hem_idx = {1 1 1}; % use labels 1:1:68 (first two values, all labels), use 1/1 of the labels (3rd value, all labels) end - - if strcmpi(g.plotmatrix, 'on') - matrix = squeeze(mean(PS(frq_inds, :, :))); - figure; imagesc(matrix); colorbar - xlabel('ROI index (see Atlas for more info)'); - h = title([ plotOpt.label ' (' titleStr ')']); - set(h, 'fontsize', 16); + + % labels on dummy plot for positioning + xlim([0 n_roi_labels]) + ylim([0 n_roi_labels]) + set(gca,'xtick',[1:n_roi_labels],'xticklabel',labels_dk_cell_idx(hem_idx{1}:hem_idx{2}:n_roi_labels)); + ax = gca; + for i=hem_idx{1}:hem_idx{2}:n_roi_labels + ax.XTickLabel{ceil(i/hem_idx{3})} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.XTickLabel{ceil(i/2)}); end - - if strcmpi(g.plotcortex, 'on') - allplots_cortex_BS(S.cortex, PSmean, [min(PSmean) max(PSmean)], cm17a, plotOpt.unit, g.smooth); - h = textsc([ plotOpt.labelshort ' (' titleStr ')' ], 'title'); - set(h, 'fontsize', 20); + xtickangle(90) + pos = get(gca, 'Position'); + legend('Cingulate', 'Prefrontal', 'Frontal', 'Temporal', 'Parietal', 'Central', 'Occipital', 'Location', 'southeastoutside'); % modify legend position + set(gca, 'Position', pos, 'DataAspectRatio',[1 1 1], 'visible', 'off') + + % plot matrix over the dummy plot and keep the legend + axes('pos', [pos(1) pos(2) pos(3) pos(4)]) + if strcmp(hemisphere, 'left') || strcmp(hemisphere, 'right') + matrix(hem_idx{1}:hem_idx{2}:n_roi_labels,:) = []; % reduce matrix + matrix(:,hem_idx{1}:hem_idx{2}:n_roi_labels) = []; + imagesc(matrix); colormap(cmap); + else + imagesc(matrix); colormap(cmap); + end - - if strcmpi(g.plotpsd, 'on') - figure; semilogy(S.freqs(frq_inds), PSmean(frq_inds, :)); grid on - h = textsc(plotOptS.label, 'title'); - set(h, 'fontsize', 20); + cb = colorbar; + set(cb, 'Location', 'southoutside') + set(gca, 'Position', pos, 'DataAspectRatio',[1 1 1], 'visible', 'on') + + % add colored labels with display option + set(gca,'ytick',[1:n_roi_labels],'yticklabel',labels_dk_cell_idx(hem_idx{1}:hem_idx{2}:n_roi_labels), 'fontweight','bold', 'fontsize', 9, 'TickLength',[0.015, 0.02], 'LineWidth',0.75); + set(gca,'xtick',[1:n_roi_labels],'xticklabel',labels_dk_cell_idx(hem_idx{1}:hem_idx{2}:n_roi_labels)); + ax = gca; + for i=hem_idx{1}:hem_idx{2}:n_roi_labels + ax.XTickLabel{ceil(i/hem_idx{3})} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.XTickLabel{ceil(i/hem_idx{3})}); + ax.YTickLabel{ceil(i/hem_idx{3})} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i/hem_idx{3})}); end - -end + h = title([ 'ROI to ROI ' upper(measure) ' (' titleStr ')' ]); + set(h, 'fontsize', 16); + xtickangle(90) + end +end -if nargin < 2 - com = sprintf('pop_roi_connectplot(EEG, %s);', vararg2str( options )); -end +function pltlarge(EEG, mim, trgc, roipsd, titleStr) + % plot MIM, TRGC and power (barplot) in a single large figure -function measure = get_connect_mat( measureOri, nROI, signVal) - % create a ROI x ROI connectivity matrix, if needed - % TRGCmat(f, ii, jj) is net TRGC from jj to ii - measure = []; - iinds = 0; - for iroi = 1:nROI - for jroi = (iroi+1):nROI - iinds = iinds + 1; - measure(:, iroi, jroi) = signVal * measureOri(:, iinds); - measure(:, jroi, iroi) = measureOri(:, iinds); - end + % colormap + load cm17 + + % plot matrix with colored labels sorted by region according to the + % Desikan-Killiany atlas + labels = strings(1,length(EEG.roi.atlas.Scouts)); + for i = 1:length(labels) + scout = struct2cell(EEG.roi.atlas.Scouts(i)); + labels(i) = char(scout(1)); + end + + % assign labels to colors + labels = cellstr(labels); + colors = {[0,0,0]/255, [163, 107, 64]/255, [171, 163, 71]/255, [217, 37, 88]/255, [113, 15, 82]/255,[35, 103, 81]/255,[2, 45, 126]/255,}; + roi_loc ={'LT';'RT';'LL';'RL';'LF';'RF';'LO';'RO';'LT';'RT';'LPF';'RPF';'LT';'RT';'LP';'RP';'LT';'RT';'LT';'RT';'LL';'RL';'LO';'RO';'LPF';'RPF';'LO';'RO';'LPF';'RPF';'LT';'RT';'LC';'RC';'LT';'RT';'LF';'RF';'LPF';'RPF';'LF';'RF';'LO';'RO';'LC';'RC';'LL';'RL';'LC';'RC';'LP';'RP';'LL';'RL';'LF';'RF';'LF';'RF';'LP';'RP';'LT';'RT';'LP';'RP';'LT';'RT';'LT';'RT'}; + roi_loc = string(roi_loc); + roi_loc = strrep(roi_loc, 'PF', '2'); + roi_loc = strrep(roi_loc, 'F', '3'); + roi_loc = strrep(roi_loc, 'T', '4'); + roi_loc = strrep(roi_loc, 'P', '5'); + roi_loc = strrep(roi_loc, 'C', '6'); + roi_loc = strrep(roi_loc, 'O', '7'); + roi_loc = strrep(roi_loc, 'LL', 'L1'); + roi_loc = strrep(roi_loc, 'RL', 'R1'); + roi_loc = strrep(roi_loc, 'L', ''); + roi_loc = strrep(roi_loc, 'R', ''); + [color_idxx,roi_idxx] = sort(str2double(roi_loc)); + labels_dk_cell_idx = labels(roi_idxx); + + f = figure(); + f.WindowState = 'maximized'; + + fc_matrices = cell(1,2); + fc_matrices{1,1} = mim; + fc_matrices{1,2} = trgc; + fc_names = ["MIM", "TRGC"]; + + for k = 1:2 + plt(k) = subplot(1,3,k); + fc = fc_matrices{k}; + img = squeeze(fc)'; + img_sorted = img(roi_idxx, roi_idxx); + imagesc(img_sorted) + + set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontsize', 5, 'TickLength',[0.015, 0.02], 'LineWidth',0.75); + set(gca,'xtick',[1:68],'xticklabel',labels_dk_cell_idx(1:68)); + h = title([ 'ROI to ROI ' fc_names{k} ' (' titleStr ')' ]); + set(h, 'fontsize', 16); + hcb = colorbar; + hcb.Label.FontSize = 10; + set(gca,'DataAspectRatio',[1 1 1]) + xtickangle(90) + + ax = gca; + for i=1:numel(roi_idxx) + ax.XTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.XTickLabel{ceil(i)}); + ax.YTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i)}); end + end + colormap(plt(1), cm17a) + colormap(plt(2), cm17) + + % power + subplot(1,3,3); + barh(roipsd(roi_idxx)); + + set(gca, 'YDir', 'reverse'); + set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontweight','bold','fontsize', 9, 'TickLength',[0.015, 0.02], 'LineWidth',0.7); + h = title([ 'ROI source power' ' (' titleStr ')' ]); + set(h, 'fontsize', 16); + ylabel('power [dB]') + + ax = gca; + for i=1:numel(roi_idxx) + ax.YTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i)}); + end + + % invisible plot to add legend + hold on + n_labels = 7; + h = zeros(n_labels, 1); + for k=1:numel(h) + h(k) = plot(NaN, NaN, '-', 'LineWidth', 8, 'Color', colors{k}); + end + lgd = legend(h, 'Cingulate', 'Prefrontal', 'Frontal', 'Temporal', 'Parietal', 'Central', 'Occipital'); + lgd.FontSize = 10; + set(lgd, 'Position', [0.44 0.06 0.25 0.25]); +end From 8d08b88d33f7b61ce6ed820f6b02d5bb02e1c9f9 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Mon, 23 May 2022 17:59:30 +0000 Subject: [PATCH 2/6] replacing new way of computing TRGC with old way --- libs/haufe/allplots_cortex_BS.m | 6 +++--- pop_roi_connectplot.m | 31 +++++++++---------------------- roi_connect.m | 4 ++-- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/libs/haufe/allplots_cortex_BS.m b/libs/haufe/allplots_cortex_BS.m index 258064e..c6bc424 100755 --- a/libs/haufe/allplots_cortex_BS.m +++ b/libs/haufe/allplots_cortex_BS.m @@ -25,8 +25,8 @@ function allplots_cortex_BS(cortex, data_in, colorlimits, cm, unit, smooth, prin end end -cortex.Vertices = cortex.Vertices(:, [2 1 3]); -cortex.Vertices(:, 1) = -cortex.Vertices(:, 1); +% cortex.Vertices = cortex.Vertices(:, [2 1 3]); +% cortex.Vertices(:, 1) = -cortex.Vertices(:, 1); for iatl = 1:length(cortex.Atlas) @@ -75,7 +75,7 @@ function allplots_cortex_BS(cortex, data_in, colorlimits, cm, unit, smooth, prin end end -figure('position', [60 828 950 500]); +figure('position', [60 828 950 500]); subplot(2,3,1); surface_pars.myviewdir = [-1 0 0]; showsurface3(vc, cortex.Faces_left, surface_pars, data, varargin1{:}); diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 55e97ea..dc02356 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -273,12 +273,11 @@ if strcmpi(g.largeplot, 'on') source_roi_power_norm_dB = 10*log10( mean(EEG.roi.source_roi_power(frq_inds,:)) ); % roipsd - % new, not working % TRGCnet = S.TRGC; % TRGCnet = TRGCnet - permute(TRGCnet, [1 3 2]); % TRGCnet = TRGCnet(:,:); - % old - TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); % trgc + + TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); TRGC = get_connect_mat( TRGCnet, S.nROI, -1); TRGC_matrix = squeeze(mean(TRGC(frq_inds, :, :))); @@ -316,14 +315,14 @@ % TRGCnet = TRGC_(:, 1:2:end)-TRGC_(:, 2:2:end); % new way to compute net scores if strcmpi(g.measure, 'GC') - % TRGCnet = S.GC; % new, not working + % TRGCnet = S.GC; TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); else - % TRGCnet = S.TRGC; % new, not working + % TRGCnet = S.TRGC; TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); end -% TRGCnet = TRGCnet - permute(TRGCnet, [1 3 2]); % new, not working -% TRGCnet = TRGCnet(:,:); % new, not working +% TRGCnet = TRGCnet - permute(TRGCnet, [1 3 2]); +% TRGCnet = TRGCnet(:,:); % TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); TRGC = get_connect_mat( TRGCnet, S.nROI, -1); @@ -431,8 +430,6 @@ function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) % plot individual ROI to ROI matrix with colored labels (corresponding lobes/regions) - - % colormap load cm17 switch lower(measure) case {'mim', 'mic', 'coh'} @@ -441,8 +438,7 @@ function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) cmap = cm17; end - % plot matrix with colored labels sorted by region according to the - % Desikan-Killiany atlas + % plot matrix with colored labels sorted by region according to the Desikan-Killiany atlas labels = strings(1,length(EEG.roi.atlas.Scouts)); for i = 1:length(labels) scout = struct2cell(EEG.roi.atlas.Scouts(i)); @@ -468,16 +464,12 @@ function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) labels_dk_cell_idx = labels(roi_idxx); if strcmpi(measure, 'roipsd') % plot barplot for power -% f = figure(); -% f.WindowState = 'maximized'; barh(matrix(roi_idxx)); - set(gca, 'YDir', 'reverse'); set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontweight','bold','fontsize', 9, 'TickLength',[0.015, 0.02], 'LineWidth',0.7); h = title([ 'ROI source power' ' (' titleStr ')' ]); set(h, 'fontsize', 16); ylabel('power [dB]') - ax = gca; for i=1:numel(roi_idxx) ax.YTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i)}); @@ -585,8 +577,6 @@ function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) function pltlarge(EEG, mim, trgc, roipsd, titleStr) % plot MIM, TRGC and power (barplot) in a single large figure - - % colormap load cm17 % plot matrix with colored labels sorted by region according to the @@ -617,7 +607,6 @@ function pltlarge(EEG, mim, trgc, roipsd, titleStr) f = figure(); f.WindowState = 'maximized'; - fc_matrices = cell(1,2); fc_matrices{1,1} = mim; fc_matrices{1,2} = trgc; @@ -629,7 +618,7 @@ function pltlarge(EEG, mim, trgc, roipsd, titleStr) img = squeeze(fc)'; img_sorted = img(roi_idxx, roi_idxx); imagesc(img_sorted) - + set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontsize', 5, 'TickLength',[0.015, 0.02], 'LineWidth',0.75); set(gca,'xtick',[1:68],'xticklabel',labels_dk_cell_idx(1:68)); h = title([ 'ROI to ROI ' fc_names{k} ' (' titleStr ')' ]); @@ -638,7 +627,6 @@ function pltlarge(EEG, mim, trgc, roipsd, titleStr) hcb.Label.FontSize = 10; set(gca,'DataAspectRatio',[1 1 1]) xtickangle(90) - ax = gca; for i=1:numel(roi_idxx) ax.XTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.XTickLabel{ceil(i)}); @@ -651,13 +639,12 @@ function pltlarge(EEG, mim, trgc, roipsd, titleStr) % power subplot(1,3,3); barh(roipsd(roi_idxx)); - + set(gca, 'YDir', 'reverse'); set(gca,'ytick',[1:68],'yticklabel',labels_dk_cell_idx(1:68), 'fontweight','bold','fontsize', 9, 'TickLength',[0.015, 0.02], 'LineWidth',0.7); h = title([ 'ROI source power' ' (' titleStr ')' ]); set(h, 'fontsize', 16); ylabel('power [dB]') - ax = gca; for i=1:numel(roi_idxx) ax.YTickLabel{ceil(i)} = sprintf('\\color[rgb]{%f,%f,%f}%s', colors{color_idxx(i)}, ax.YTickLabel{ceil(i)}); diff --git a/roi_connect.m b/roi_connect.m index 619ca53..68dd18c 100644 --- a/roi_connect.m +++ b/roi_connect.m @@ -80,8 +80,8 @@ end end if ~isempty(g.methods) - % conn_mult = data2sctrgcmim(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], inds, g.methods); - conn_mult = data2spwctrgc(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], g.methods); + conn_mult = data2sctrgcmim(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], inds, g.methods); +% conn_mult = data2spwctrgc(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], g.methods); end fields = fieldnames(conn_mult); From fe4e7a3bc182d420bf3267fd3a6168627c73e558 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Mon, 23 May 2022 18:28:16 +0000 Subject: [PATCH 3/6] copy from upstream --- pop_roi_connectplot.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index dc02356..cf2528d 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -1,4 +1,4 @@ -% pop_roi_connectplot - plot results of connectivity analysis computed +edit % pop_roi_connectplot - plot results of connectivity analysis computed % by roi_connect. % Usage: % pop_roi_connectplot(EEG, 'key', 'val', ...); From b23a5167c1cfc0d3b4e376af4d6c2722f254670f Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Mon, 23 May 2022 18:39:18 +0000 Subject: [PATCH 4/6] copy from upstream --- roi_connect.m | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/roi_connect.m b/roi_connect.m index 68dd18c..d21d3d9 100644 --- a/roi_connect.m +++ b/roi_connect.m @@ -12,14 +12,17 @@ % 'crossspec' - ['on'|'off'] compute cross-spectrum from which coherence can % be derived. Default is 'on'. % 'methods' - [cell of string 'psd'|'roipsd'|'trgc'|'crossspecimag'|'crossspecpow'|'mic'|'mim'] -% 'psd' : Source power spectrum -% 'psdroi': ROI based power spectrum +% 'cs' : cross spectrum +% 'coh' : coherence +% 'gc' : Granger causality % 'trgc' : Time-reversed granger causality -% 'crossspecimag': Imaginary part of coherence from cross-spectrum -% 'crossspecpow' : Average cross-spectrum power for each ROI -% 'mic' : Maximized Imaginary Coherency for each ROI -% 'mim' : Multivariate Interaction Measure for each ROI -% +% 'wpli' : Weighted phase lag index +% 'pdc' : Partial directed coherence +% 'trpdc' : Time-reversed partial directed coherence +% 'dtf' : Directed transfer entropy +% 'trdtf' : Time-reversed directed transfer entropy +% 'mic' : Maximized Imaginary Coherency for each ROI +% 'mim' : Multivariate Interaction Measure for each ROI % Output: % EEG - EEG structure with EEG.roi field updated and now containing % connectivity information. @@ -69,6 +72,10 @@ 'methods' 'cell' { } {} }, 'roi_connect'); if ischar(g), error(g); end if isempty(g.naccu), g.naccu = 0; end +tmpMethods = setdiff(g.methods, { 'CS' 'COH' 'GC' 'TRGC' 'wPLI' 'PDC' 'TRPDC' 'DTF' 'TRDTF' 'MIM' 'MIC'}); +if ~isempty(tmpMethods) + error('Unknown methods %s', vararg2str(tmpMethods)) +end inds = {}; ninds = 0; nROI = EEG.roi.nROI; @@ -79,15 +86,25 @@ ninds = ninds + 1; end end -if ~isempty(g.methods) - conn_mult = data2sctrgcmim(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], inds, g.methods); -% conn_mult = data2spwctrgc(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], g.methods); -end -fields = fieldnames(conn_mult); -for iField = 1:length(fields) - EEG.roi.(fields{iField}) = conn_mult.(fields{iField}); +% MIC and MIM use a different function +if ismember(g.methods, 'MIC') || ismember(g.methods, 'MIM') + tmpMethods = setdiff(g.methods, { 'CS' 'COH' 'PSD' 'PSDROI' 'GC' 'TRGC' 'wPLI' 'PDC' 'TRPDC' 'DTF' 'TRDTF' }); + conn_mult = data2sctrgcmim(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], inds, tmpMethods); + fields = fieldnames(conn_mult); + for iField = 1:length(fields) + EEG.roi.(fields{iField}) = conn_mult.(fields{iField}); + end end +tmpMethods2 = setdiff(g.methods, { 'MIM' 'MIC' }); +if ~isempty(tmpMethods2) + conn_mult = data2spwctrgc(source_roi_data, EEG.srate, g.morder, 0, g.naccu, [], tmpMethods2); + fields = fieldnames(conn_mult); + for iField = 1:length(fields) + EEG.roi.(fields{iField}) = conn_mult.(fields{iField}); + end +end + % convert to matrices function EEG = vec2mat(EEG) @@ -104,4 +121,4 @@ end end EEG.roi.MIM_matrix = mim_; -EEG.roi.TRGC_matrix = trgc_; +EEG.roi.TRGC_matrix = trgc_; \ No newline at end of file From c3b910f224d8bca769ef8ff6608e0a87d7c9e239 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Mon, 23 May 2022 18:42:12 +0000 Subject: [PATCH 5/6] added colored labels corresponding to brain lobes to FC matrices --- libs/haufe/allplots_cortex_BS.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/haufe/allplots_cortex_BS.m b/libs/haufe/allplots_cortex_BS.m index c6bc424..90bf4fb 100755 --- a/libs/haufe/allplots_cortex_BS.m +++ b/libs/haufe/allplots_cortex_BS.m @@ -25,8 +25,8 @@ function allplots_cortex_BS(cortex, data_in, colorlimits, cm, unit, smooth, prin end end -% cortex.Vertices = cortex.Vertices(:, [2 1 3]); -% cortex.Vertices(:, 1) = -cortex.Vertices(:, 1); +cortex.Vertices = cortex.Vertices(:, [2 1 3]); +cortex.Vertices(:, 1) = -cortex.Vertices(:, 1); for iatl = 1:length(cortex.Atlas) From ed788c992f15d9a6f021f24bf2141290b2fa0561 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Mon, 23 May 2022 18:48:29 +0000 Subject: [PATCH 6/6] bugfix --- pop_roi_connectplot.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index cf2528d..dc02356 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -1,4 +1,4 @@ -edit % pop_roi_connectplot - plot results of connectivity analysis computed +% pop_roi_connectplot - plot results of connectivity analysis computed % by roi_connect. % Usage: % pop_roi_connectplot(EEG, 'key', 'val', ...);