From cc7a86390869cf72c14887466b203e80a968faae Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 25 May 2022 10:03:38 +0000 Subject: [PATCH 1/9] change function names --- pop_roi_connectplot.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index dc02356..794c711 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -285,7 +285,7 @@ MI = get_connect_mat( MI, S.nROI, +1); MIM_matrix = squeeze(mean(MI(frq_inds, :, :))); - pltlarge(EEG, MIM_matrix, TRGC_matrix, source_roi_power_norm_dB, titleStr) + roi_largeplot(EEG, MIM_matrix, TRGC_matrix, source_roi_power_norm_dB, titleStr) else switch lower(g.measure) case { 'psd' 'roipsd' } @@ -307,7 +307,7 @@ 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); + roi_plotcoloredlobes(EEG, source_roi_power_norm_dB, titleStr, g.measure, g.hemisphere, g.region); end case { 'trgc' 'gc' } @@ -328,7 +328,7 @@ if strcmpi(g.plotmatrix, 'on') matrix = squeeze(mean(TRGC(frq_inds, :, :))); - pltmatrix(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); + roi_plotcoloredlobes(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); end if strcmpi(g.plot3d, 'on') @@ -353,7 +353,7 @@ if strcmpi(g.plotmatrix, 'on') matrix = squeeze(mean(MI(frq_inds, :, :))); - pltmatrix(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); + roi_plotcoloredlobes(EEG, matrix, titleStr, g.measure, g.hemisphere, g.region); end if strcmpi(g.plotcortex, 'on') @@ -428,7 +428,7 @@ end end -function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) +function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, region) % plot individual ROI to ROI matrix with colored labels (corresponding lobes/regions) load cm17 switch lower(measure) @@ -575,7 +575,7 @@ function pltmatrix( EEG, matrix, titleStr, measure, hemisphere, region) end end -function pltlarge(EEG, mim, trgc, roipsd, titleStr) +function roi_largeplot(EEG, mim, trgc, roipsd, titleStr) % plot MIM, TRGC and power (barplot) in a single large figure load cm17 From fe48bbd6870eb49b7860de1988fd09fa71e94b54 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 25 May 2022 10:21:17 +0000 Subject: [PATCH 2/9] disable coordinate transformation --- libs/haufe/allplots_cortex_BS.m | 5 +++-- pop_roi_connectplot.m | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/haufe/allplots_cortex_BS.m b/libs/haufe/allplots_cortex_BS.m index 90bf4fb..1d15754 100755 --- a/libs/haufe/allplots_cortex_BS.m +++ b/libs/haufe/allplots_cortex_BS.m @@ -25,8 +25,9 @@ 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); +% coordinate transformation +% cortex.Vertices = cortex.Vertices(:, [2 1 3]); +% cortex.Vertices(:, 1) = -cortex.Vertices(:, 1); for iatl = 1:length(cortex.Atlas) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 794c711..932ad65 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -341,6 +341,7 @@ 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') end case { 'mim' 'mic' } From fde360466681f10b472541619d2be1771e95a94b Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 25 May 2022 15:49:57 +0000 Subject: [PATCH 3/9] add option to plot seed voxel in the head plot --- pop_roi_connectplot.m | 64 +++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 932ad65..64e7e10 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -237,18 +237,19 @@ % decode input parameters % ----------------------- g = finputcheck(options, { 'measure' 'string' {splot.acronym} ''; - 'freqrange' 'real' { } []; - 'smooth' 'real' { } 0.35; - 'plotcortex' 'string' { 'on' 'off' } 'on'; - 'plotcortexparams' 'cell' { } {}; - 'plot3d' 'string' { 'on' 'off' } 'off'; - 'plot3dparams' 'cell' { } {}; - 'plotmatrix' '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'; - 'plotpsd', 'string' { 'on' 'off' } 'off' }, 'pop_roi_connectplot'); + 'freqrange' 'real' { } []; + 'smooth' 'real' { } 0.35; + 'plotcortex' 'string' { 'on' 'off' } 'on'; + 'plotcortexparams' 'cell' { } {}; + 'plotcortexseedregion' 'string' { } []; + 'plot3d' 'string' { 'on' 'off' } 'off'; + 'plot3dparams' 'cell' { } {}; + 'plotmatrix' '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'; + 'plotpsd', 'string' { 'on' 'off' } 'off' }, 'pop_roi_connectplot'); if ischar(g), error(g); end S = EEG.roi; @@ -337,8 +338,14 @@ 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); + if isempty(g.plotcortexseedregion) + 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); + else + [coordinate, seed_idx] = get_seedregion_coordinate(g.plotcortexseedregion, EEG.roi.cortex.Vertices); + atrgc = squeeze(mean(TRGC(frq_inds, seed_idx, :))); + allplots_cortex_BS(S.cortex, atrgc, [-max(abs(atrgc)) max(abs(atrgc))], cm17, upper(g.measure), g.smooth, [], {coordinate}); + end h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); set(h, 'fontsize', 20); movegui(gcf, 'south') @@ -358,9 +365,15 @@ 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'); + if isempty(g.plotcortexseedregion) + ami = mean(squeeze(mean(MI(frq_inds, :, :))), 2); + allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth); + else + [coordinate, seed_idx] = get_seedregion_coordinate(g.plotcortexseedregion, EEG.roi.cortex.Vertices); + ami = squeeze(mean(MI(frq_inds, seed_idx,:))); + allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth, [], {coordinate}); + end + h = textsc([ upper(g.measure) ' (' titleStr ') '], 'title'); set(h, 'fontsize', 20); end @@ -428,6 +441,23 @@ end end end + +function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) + % determine voxel of selected seed region, if needed + % assign region index to selected seed region (passed as string) + load cortex + cortex_struct = struct2cell(a); + seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); + if ~isempty(seed_idx) + pos_idx = a(seed_idx).Vertices; + pos = vc(pos_idx,:); + mid_point = mean(pos,1); + [~,closest_pos_idx] = min(eucl(mid_point, pos)); + coordinate = pos(closest_pos_idx,:); + else + error('Selected region not in cortex') + end +end function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, region) % plot individual ROI to ROI matrix with colored labels (corresponding lobes/regions) From af06aaf3a7d63622e16c6ac0239852502436ee12 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Thu, 26 May 2022 15:19:04 +0000 Subject: [PATCH 4/9] adding documentation --- pop_roi_connectplot.m | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 64e7e10..ea55c52 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -11,20 +11,28 @@ % 'sourcemodel' - [string] source model file % % Optional inputs: -% 'measure' - ['psd'|'roipsd'|'trgc'|'crossspecimag'|'crossspecpow'|'mic'|'mim'] -% 'psd' : Source power spectrum -% 'psdroi': ROI based power spectrum -% '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 -% 'freqrange' - [min max] frequency range in Hz. Default is to plot -% broadband power. -% 'smooth' - [float] smoothing factor for cortex surface plotting -% 'plotcortex' - ['on'|'off'] plot results on smooth cortex. Default is 'on' -% 'plotmatrix' - ['on'|'off'] plot results on smooth cortex. Default is 'off' -% 'plotpsd' - ['on'|'off'] plot PSD (for 'crossspecpow' only). Default is 'off' +% 'measure' - ['psd'|'roipsd'|'trgc'|'crossspecimag'|'crossspecpow'|'mic'|'mim'] +% 'psd' : Source power spectrum +% 'psdroi': ROI based power spectrum +% 'trgc' : Time-reversed granger causality +% 'gc' : 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 +% 'freqrange' - [min max] frequency range in Hz. Default is to plot broadband power. +% 'smooth' - [float] smoothing factor for cortex surface plotting +% 'plotcortex' - ['on'|'off'] plot results on smooth cortex. Default is 'on' +% 'plotcortexparams' - [cell] ... +% 'plotcortexseedregion' - [string] plot seed voxel on cortex. Takes name of seed region as input. +% 'plot3d' - ['on'|'off'] ... Default is 'off' +% 'plot3dparams' - [cell] ... +% 'plotmatrix' - ['on'|'off'] plot results as ROI to ROI matrix. Default is 'off' +% 'plotbarplot' - ['on'|'off'] plot ROI based power spectrum as barplot. Default is 'off' +% 'hemisphere' - ['all'|'left'|'right'] hemisphere options for ROI to ROI matrix. Default is 'all' +% 'region' - ['all'|'cingulate'|'prefrontal'|'frontal'|'temporal'|'parietal'|'central'|'occipital'] region selection for ROI to ROI matrix. Default is 'all' +% 'largeplot' - ['on'|'off'] plot MIM, TRGC and Power in a single large plot. Default is 'off' +% 'plotpsd' - ['on'|'off'] plot PSD (for 'crossspecpow' only). Default is 'off' % % Author: Stefan Haufe and Arnaud Delorme, 2019 % From 9ab2f10a0b4373ae9be127cbcc27204b4b1058d0 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 1 Jun 2022 14:34:00 +0000 Subject: [PATCH 5/9] add GUI elements, plot seed region on cortex (still buggy) --- pop_roi_connectplot.m | 64 +++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index ea55c52..0a422d3 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -187,6 +187,7 @@ splot(end ).matrix = -1; splot(end ).psd = 0; end + if nargin < 2 @@ -203,9 +204,10 @@ ' end;' ... 'end;' ... 'clear iField fieldTmp usrdat;' ]; - + + fcregions = {'all', 'cingulate', 'prefrontal', 'frontal', 'temporal', 'parietal', 'central', 'occipital'}; plotrow = [1 1]; - uigeom = { [1 1] [1 1] 1 [1 1] plotrow plotrow plotrow plotrow }; + uigeom = { [1 1] [1 1] 1 [1 1] plotrow [5 3 2] [3.5 1.5 1 1] plotrow }; 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]:'} ... @@ -218,9 +220,13 @@ { 'style' 'edit' 'string' '''thresholdper'', 0.8' 'tag' 'plot3dparams' } ... ... { 'style' 'checkbox' 'string' 'Connectivity of each area' 'tag' 'cortex' 'value' 1 } ... - { 'style' 'text' 'string' '' 'tag' 'cortexparams' } ... + { 'style' 'text' 'string' 'Index of seed region:' 'fontweight' 'bold' } ... + { 'style' 'edit' 'string' '' 'tag' 'seed_region'} ... ... - { 'style' 'checkbox' 'string' 'Matrix representation' 'tag' 'matrix' 'enable' 'off' } {} ... + { 'style' 'checkbox' 'string' 'Matrix representation' 'tag' 'matrix' 'enable' 'off' } ... + { 'style' 'popupmenu' 'string' fcregions 'callback' cb_select 'value' 3 'tag' 'region' } .... + { 'style' 'checkbox' 'string' 'left' 'tag' 'hemisphere_left' 'value' 1 } ... + { 'style' 'checkbox' 'string' 'right' 'tag' 'hemisphere_right' 'value' 1 } ... ... { 'style' 'checkbox' 'string' 'Power spectral density' 'tag' 'psd' 'enable' 'off' } {} ... }; @@ -234,10 +240,20 @@ options = { options{:} 'freqrange' eval( [ '[' result{2} ']' ] ) }; options = { options{:} 'plotcortex' fastif(outs.cortex, 'on', 'off') }; options = { options{:} 'plotcortexparams' {} }; + options = { options{:} 'plotcortexseedregion' str2num(result{6}) }; options = { options{:} 'plotmatrix' fastif(outs.matrix, 'on', 'off') }; options = { options{:} 'plotpsd' fastif(outs.psd , 'on', 'off') }; options = { options{:} 'plot3d' fastif(outs.plot3d, 'on', 'off') }; options = { options{:} 'plot3dparams' eval( [ '{' outs.plot3dparams '}' ] ) }; + options = { options{:} 'region' fcregions{result{9}} }; + % choose which hemisphere to plot + if outs.hemisphere_left == 1 && outs.hemisphere_right == 0 + options = { options{:} 'hemisphere' 'left' }; + elseif outs.hemisphere_left == 0 && outs.hemisphere_right == 1 + options = { options{:} 'hemisphere' 'right' }; + else + options = { options{:} 'hemisphere' 'all' }; + end else options = varargin; end @@ -249,7 +265,7 @@ 'smooth' 'real' { } 0.35; 'plotcortex' 'string' { 'on' 'off' } 'on'; 'plotcortexparams' 'cell' { } {}; - 'plotcortexseedregion' 'string' { } []; + 'plotcortexseedregion' 'integer' { } []; 'plot3d' 'string' { 'on' 'off' } 'off'; 'plot3dparams' 'cell' { } {}; 'plotmatrix' 'string' { 'on' 'off' } 'off'; @@ -324,15 +340,15 @@ % TRGCnet = TRGC_(:, 1:2:end)-TRGC_(:, 2:2:end); % new way to compute net scores if strcmpi(g.measure, 'GC') - % TRGCnet = S.GC; +% TRGCnet = S.GC; TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); else - % TRGCnet = S.TRGC; +% TRGCnet = S.TRGC; TRGCnet = S.TRGC(:, :, 1) - S.TRGC(:, :, 2); end % TRGCnet = TRGCnet - permute(TRGCnet, [1 3 2]); % TRGCnet = TRGCnet(:,:); - % TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); +% TRGCnet = S.GC(:, :, 1) - S.GC(:, :, 2); TRGC = get_connect_mat( TRGCnet, S.nROI, -1); if strcmpi(g.plotmatrix, 'on') @@ -356,7 +372,6 @@ end h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); set(h, 'fontsize', 20); - movegui(gcf, 'south') end case { 'mim' 'mic' } @@ -376,10 +391,12 @@ if isempty(g.plotcortexseedregion) ami = mean(squeeze(mean(MI(frq_inds, :, :))), 2); allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth); + movegui(gcf, 'south') else [coordinate, seed_idx] = get_seedregion_coordinate(g.plotcortexseedregion, EEG.roi.cortex.Vertices); ami = squeeze(mean(MI(frq_inds, seed_idx,:))); allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth, [], {coordinate}); + movegui(gcf, 'south') end h = textsc([ upper(g.measure) ' (' titleStr ') '], 'title'); set(h, 'fontsize', 20); @@ -450,12 +467,13 @@ end end -function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) +% function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) +function [coordinate, seed_idx] = get_seedregion_coordinate(seed_idx, vc) % determine voxel of selected seed region, if needed % assign region index to selected seed region (passed as string) load cortex - cortex_struct = struct2cell(a); - seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); +% cortex_struct = struct2cell(a); +% seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); if ~isempty(seed_idx) pos_idx = a(seed_idx).Vertices; pos = vc(pos_idx,:); @@ -468,7 +486,7 @@ end function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, region) - % plot individual ROI to ROI matrix with colored labels (corresponding lobes/regions) + % plot matrix with colored labels sorted by region according to the Desikan-Killiany atlas load cm17 switch lower(measure) case {'mim', 'mic', 'coh'} @@ -477,7 +495,7 @@ function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, regio cmap = cm17; end - % plot matrix with colored labels sorted by region according to the Desikan-Killiany atlas + % retrieve labels from atlas labels = strings(1,length(EEG.roi.atlas.Scouts)); for i = 1:length(labels) scout = struct2cell(EEG.roi.atlas.Scouts(i)); @@ -553,6 +571,15 @@ function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, regio color_idxx = color_idxx(start_idx:end_idx); end n_roi_labels = size(matrix, 1); % only 68 if no region is selected + + % 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 + 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 % create dummy plot and add custom legend f = figure(); @@ -564,15 +591,6 @@ function roi_plotcoloredlobes( EEG, matrix, titleStr, measure, hemisphere, regio 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 - 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 - % labels on dummy plot for positioning xlim([0 n_roi_labels]) ylim([0 n_roi_labels]) From f3995b9563b06b7db161d9009c722941d6a15469 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 1 Jun 2022 16:16:46 +0000 Subject: [PATCH 6/9] plot seed region on cortex for MIM/MIC and GC/TRGC --- pop_roi_connectplot.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index 0a422d3..f37cea3 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -265,7 +265,7 @@ 'smooth' 'real' { } 0.35; 'plotcortex' 'string' { 'on' 'off' } 'on'; 'plotcortexparams' 'cell' { } {}; - 'plotcortexseedregion' 'integer' { } []; + 'plotcortexseedregion' 'integer' { } []; 'plot3d' 'string' { 'on' 'off' } 'off'; 'plot3dparams' 'cell' { } {}; 'plotmatrix' 'string' { 'on' 'off' } 'off'; @@ -366,7 +366,7 @@ 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); else - [coordinate, seed_idx] = get_seedregion_coordinate(g.plotcortexseedregion, EEG.roi.cortex.Vertices); + [coordinate, seed_idx] = get_seedregion_coordinate(EEG.roi.atlas.Scouts, g.plotcortexseedregion, EEG.roi.cortex.Vertices); atrgc = squeeze(mean(TRGC(frq_inds, seed_idx, :))); allplots_cortex_BS(S.cortex, atrgc, [-max(abs(atrgc)) max(abs(atrgc))], cm17, upper(g.measure), g.smooth, [], {coordinate}); end @@ -391,12 +391,10 @@ if isempty(g.plotcortexseedregion) ami = mean(squeeze(mean(MI(frq_inds, :, :))), 2); allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth); - movegui(gcf, 'south') else - [coordinate, seed_idx] = get_seedregion_coordinate(g.plotcortexseedregion, EEG.roi.cortex.Vertices); + [coordinate, seed_idx] = get_seedregion_coordinate(EEG.roi.atlas.Scouts, g.plotcortexseedregion, EEG.roi.cortex.Vertices); ami = squeeze(mean(MI(frq_inds, seed_idx,:))); allplots_cortex_BS(S.cortex, ami, [min(ami) max(ami)], cm17a, upper(g.measure), g.smooth, [], {coordinate}); - movegui(gcf, 'south') end h = textsc([ upper(g.measure) ' (' titleStr ') '], 'title'); set(h, 'fontsize', 20); @@ -468,14 +466,13 @@ end % function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) -function [coordinate, seed_idx] = get_seedregion_coordinate(seed_idx, vc) +function [coordinate, seed_idx] = get_seedregion_coordinate(scouts, seed_idx, vc) % determine voxel of selected seed region, if needed % assign region index to selected seed region (passed as string) - load cortex % cortex_struct = struct2cell(a); % seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); if ~isempty(seed_idx) - pos_idx = a(seed_idx).Vertices; + pos_idx = scouts(seed_idx).Vertices; pos = vc(pos_idx,:); mid_point = mean(pos,1); [~,closest_pos_idx] = min(eucl(mid_point, pos)); From a8b5092a577aecbbfc56421086cbf347deeff78c Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 8 Jun 2022 15:18:47 +0000 Subject: [PATCH 7/9] bugfix --- pop_roi_connectplot.m | 4 +++- roi_connect.m | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index f37cea3..d56b1f4 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -245,7 +245,7 @@ options = { options{:} 'plotpsd' fastif(outs.psd , 'on', 'off') }; options = { options{:} 'plot3d' fastif(outs.plot3d, 'on', 'off') }; options = { options{:} 'plot3dparams' eval( [ '{' outs.plot3dparams '}' ] ) }; - options = { options{:} 'region' fcregions{result{9}} }; + options = { options{:} 'region' fcregions{result{8}} }; % choose which hemisphere to plot if outs.hemisphere_left == 1 && outs.hemisphere_right == 0 options = { options{:} 'hemisphere' 'left' }; @@ -365,10 +365,12 @@ if isempty(g.plotcortexseedregion) 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); + movegui(gcf, 'south') else [coordinate, seed_idx] = get_seedregion_coordinate(EEG.roi.atlas.Scouts, g.plotcortexseedregion, EEG.roi.cortex.Vertices); atrgc = squeeze(mean(TRGC(frq_inds, seed_idx, :))); allplots_cortex_BS(S.cortex, atrgc, [-max(abs(atrgc)) max(abs(atrgc))], cm17, upper(g.measure), g.smooth, [], {coordinate}); + movegui(gcf, 'south') end h = textsc([ upper(g.measure) ' (' titleStr '); Red = net sender; Blue = net receiver' ], 'title'); set(h, 'fontsize', 20); diff --git a/roi_connect.m b/roi_connect.m index d21d3d9..f81a73f 100644 --- a/roi_connect.m +++ b/roi_connect.m @@ -87,8 +87,8 @@ end end -% MIC and MIM use a different function -if ismember(g.methods, 'MIC') || ismember(g.methods, 'MIM') +% % MIC and MIM use a different function +if any(ismember(g.methods, 'MIC')) || any(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); From f9111b0fdfcf41491daca2c481847fd37ccb2d35 Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 8 Jun 2022 15:36:56 +0000 Subject: [PATCH 8/9] adjust documentation --- 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 d56b1f4..e87faca 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -470,7 +470,7 @@ % function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) function [coordinate, seed_idx] = get_seedregion_coordinate(scouts, seed_idx, vc) % determine voxel of selected seed region, if needed - % assign region index to selected seed region (passed as string) + % assign region index to selected seed region (passed as index) % cortex_struct = struct2cell(a); % seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); if ~isempty(seed_idx) From 5181efbad61e03a9fff14eeb8d793fb690f31caa Mon Sep 17 00:00:00 2001 From: Hiyeri Date: Wed, 15 Jun 2022 11:46:05 +0000 Subject: [PATCH 9/9] seed voxel (small ball) on head plot now visible for every region --- pop_roi_connectplot.m | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pop_roi_connectplot.m b/pop_roi_connectplot.m index e87faca..c5f4ad8 100644 --- a/pop_roi_connectplot.m +++ b/pop_roi_connectplot.m @@ -467,18 +467,24 @@ end end -% function [coordinate, seed_idx] = get_seedregion_coordinate(seed_region, vc) function [coordinate, seed_idx] = get_seedregion_coordinate(scouts, seed_idx, vc) % determine voxel of selected seed region, if needed % assign region index to selected seed region (passed as index) -% cortex_struct = struct2cell(a); -% seed_idx = find(contains(cortex_struct(4,:,:), seed_region)); if ~isempty(seed_idx) + % ball not visible for these regions when plotting the mean voxel + manual_region_idxs = [2, 16, 18, 25, 26, 31, 32, 45, 49, 50, 55, 56, 59, 60, 61, 64]; pos_idx = scouts(seed_idx).Vertices; pos = vc(pos_idx,:); - mid_point = mean(pos,1); - [~,closest_pos_idx] = min(eucl(mid_point, pos)); - coordinate = pos(closest_pos_idx,:); + if seed_idx == 1 + coordinate = vc(736,:); + elseif ismember(seed_idx, manual_region_idxs) + pos_sorted = sortrows(pos, 3, 'descend'); % sort by descending Z-coordinate + coordinate = pos_sorted(1,:); + else + mid_point = mean(pos,1); + [~,closest_pos_idx] = min(eucl(mid_point, pos)); % determine mean voxel + coordinate = pos(closest_pos_idx,:); + end else error('Selected region not in cortex') end