Circular Graph Examples
Contents
1. Adjacency matrix of 1s and 0s
Create an example adjacency matrix made up of ones and zeros.
rng(0);
+x = rand(50);
+thresh = 0.93;
+x(x > thresh) = 1;
+x(x <= thresh) = 0;
+
Call CIRCULARGRAPH with only the adjacency matrix as an argument.
circularGraph(x);
+
Click on a node to make the connections that emanate from it more visible or less visible. Click on the 'Show All' button to make all nodes and their connections visible. Click on the 'Hide All' button to make all nodes and their connections less visible.
2. Supply custom properties
Create an example adjacency matrix made up of various values and supply custom properties.
rng(0);
+x = rand(20);
+thresh = 0.93;
+x(x > thresh) = 1;
+x(x <= thresh) = 0;
+for i = 1:numel(x)
+ if x(i) > 0
+ x(i) = rand(1,1);
+ end
+end
+
Create custom node labels
myLabel = cell(length(x));
+for i = 1:length(x)
+ myLabel{i} = num2str(round(1000000*rand(1,1)));
+end
+
Create custom colormap
figure;
+myColorMap = lines(length(x));
+
+circularGraph(x,'Colormap',myColorMap,'Label',myLabel);
+
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/circularGraph/html/example.png b/Visualize_Results/scripts/helper_fun/circularGraph/html/example.png
new file mode 100644
index 0000000..67ebd07
Binary files /dev/null and b/Visualize_Results/scripts/helper_fun/circularGraph/html/example.png differ
diff --git a/Visualize_Results/scripts/helper_fun/circularGraph/html/example_01.png b/Visualize_Results/scripts/helper_fun/circularGraph/html/example_01.png
new file mode 100644
index 0000000..d03b7ce
Binary files /dev/null and b/Visualize_Results/scripts/helper_fun/circularGraph/html/example_01.png differ
diff --git a/Visualize_Results/scripts/helper_fun/circularGraph/html/example_02.png b/Visualize_Results/scripts/helper_fun/circularGraph/html/example_02.png
new file mode 100644
index 0000000..c3732c4
Binary files /dev/null and b/Visualize_Results/scripts/helper_fun/circularGraph/html/example_02.png differ
diff --git a/Visualize_Results/scripts/helper_fun/circularGraph/license.txt b/Visualize_Results/scripts/helper_fun/circularGraph/license.txt
new file mode 100644
index 0000000..599af41
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/circularGraph/license.txt
@@ -0,0 +1,27 @@
+Copyright (c) 2016, The MathWorks, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution
+ * Neither the name of the The MathWorks, Inc. nor the names
+ of its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Visualize_Results/scripts/helper_fun/circularGraph/node.m b/Visualize_Results/scripts/helper_fun/circularGraph/node.m
new file mode 100644
index 0000000..f362b2e
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/circularGraph/node.m
@@ -0,0 +1,127 @@
+classdef node < handle
+% NODE Helper class for circularGraph. Not intended for direct user manipulation.
+%%
+% Copyright 2016 The MathWorks, Inc.
+ properties (Access = public)
+ Label = ''; % String
+ Connection = line(0,0); % Array of lines
+ Position; % [x,y] coordinates
+ Color = [0 0 0]; % [r g b]
+ Visible = true; % Logical true or false
+ end
+
+ properties (Access = public, Dependent = true)
+ Extent; % Width of text label
+ end
+
+ properties (Access = private)
+ TextLabel; % Text graphics object
+ NodeMarker; % Line that makes the node visible
+ Marker = 'o'; % Marker symbol when the node is 'on'
+ end
+
+ properties (Access = private, Constant)
+ labelOffsetFactor = 1.1;
+ end
+
+ methods
+ function this = node(x,y)
+ % Constructor
+ this.Position = [x,y];
+ this.Connection = line(0,0);
+ makeLine(this);
+ end
+
+ function makeLine(this)
+ % Make the node's line graphic object
+ this.NodeMarker = line(...
+ this.Position(1),...
+ this.Position(2),...
+ 2,...
+ 'Color',this.Color,...
+ 'Marker',this.Marker,...
+ 'LineStyle','none',...
+ 'PickableParts','all',...
+ 'ButtonDownFcn',@node.ButtonDownFcn,...
+ 'UserData',this);
+ end
+
+ function set.Visible(this,value)
+ this.Visible = value;
+ updateVisible(this);
+ end
+
+ function set.Color(this,value)
+ this.Color = value;
+ updateColor(this);
+ end
+
+ function set.Label(this,value)
+ this.Label = value;
+ updateTextLabel(this);
+ end
+
+ function value = get.Extent(this)
+ value = this.TextLabel.Extent(3);
+ end
+
+ function updateVisible(this)
+ if this.Visible
+ this.NodeMarker.Marker = 'o';
+ set(this.Connection,'Color',this.Color);
+ for i = 1:length(this.Connection)
+ this.Connection(i).ZData = ones(size(this.Connection(i).XData));
+ end
+ else
+ this.NodeMarker.Marker = 'x';
+ set(this.Connection,'Color',0.9*[1 1 1]);
+ for i = 1:length(this.Connection)
+ this.Connection(i).ZData = zeros(size(this.Connection(i).XData));
+ end
+ end
+ end
+
+ function updateColor(this)
+ this.NodeMarker.Color = this.Color;
+ set(this.Connection,'Color',this.Color);
+ end
+
+ function updateTextLabel(this)
+ delete(this.TextLabel);
+
+ x = this.Position(1);
+ y = this.Position(2);
+ t = atan2(y,x);
+
+ this.TextLabel = text(0,0,this.Label);
+
+ this.TextLabel.Position = node.labelOffsetFactor*this.Position;
+ if abs(t) > pi/2
+ this.TextLabel.Rotation = 180*(t/pi + 1);
+ this.TextLabel.HorizontalAlignment = 'right';
+ else
+ this.TextLabel.Rotation = t*180/pi;
+ end
+ end
+
+ function delete(this)
+ % Destructor
+ delete(this.Connection(:))
+ delete(this.TextLabel);
+ delete(this.NodeMarker);
+ delete(this);
+ end
+
+ end
+
+ methods (Static = true)
+ function ButtonDownFcn(this,~)
+ n = this.UserData;
+ if n.Visible
+ n.Visible = false;
+ else
+ n.Visible = true;
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/cmap_rbw.m b/Visualize_Results/scripts/helper_fun/cmap_rbw.m
new file mode 100644
index 0000000..1168afe
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/cmap_rbw.m
@@ -0,0 +1,42 @@
+function CMap = cmap_rbw(N)
+% CMAP_RBW: Red-blue-white colormap.
+
+% @=============================================================================
+% This function is part of the Brainstorm software:
+% https://neuroimage.usc.edu/brainstorm
+%
+% Copyright (c)2000-2020 University of Southern California & McGill University
+% This software is distributed under the terms of the GNU General Public License
+% as published by the Free Software Foundation. Further details on the GPLv3
+% license can be found at http://www.gnu.org/copyleft/gpl.html.
+%
+% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
+% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
+% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
+% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
+% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
+%
+% For more information type "brainstorm license" at command prompt.
+% =============================================================================@
+%
+% Authors: Sylvain Baillet
+
+if (nargin < 1)
+ N = 128; % Number of color levels
+end
+
+Wwidth = 0; % Width of the white zero level
+Cmin = 0;
+Cmax = 1;
+
+Half = floor(N/2);
+
+R1 = linspace(Cmin,Cmax,Half-Wwidth);
+R2 = ones(1,Wwidth*2);
+R3 = ones(1,Half-Wwidth)*Cmax;
+R = [R1 R2 R3];
+B = fliplr(R);
+G3 = fliplr(R1);
+G = [R1 R2 G3];
+CMap = [R' G' B'];
+
diff --git a/Visualize_Results/scripts/helper_fun/customMap_effectiveConn.m b/Visualize_Results/scripts/helper_fun/customMap_effectiveConn.m
new file mode 100644
index 0000000..6effdd7
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/customMap_effectiveConn.m
@@ -0,0 +1,52 @@
+function CMap = customMap_effectiveConn(N)
+
+% % Orhan:
+% https://jdherman.github.io/colormap/
+
+% @=============================================================================
+% This function is part of the Brainstorm software:
+% https://neuroimage.usc.edu/brainstorm
+%
+% Copyright (c)2000-2020 University of Southern California & McGill University
+% This software is distributed under the terms of the GNU General Public License
+% as published by the Free Software Foundation. Further details on the GPLv3
+% license can be found at http://www.gnu.org/copyleft/gpl.html.
+%
+% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
+% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
+% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
+% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
+% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
+%
+% For more information type "brainstorm license" at command prompt.
+% =============================================================================@
+%
+% Authors: Sylvain Baillet
+
+if (nargin < 1)
+ N = 128; % Number of color levels
+end
+
+%%
+
+Wwidth = 0; % Width of the white zero level
+Half = floor(N/2);
+
+R1 = linspace(0.1569, 1, Half-Wwidth);
+R2 = ones(1,Wwidth*2);
+R3 = flip(linspace(0, 1, Half-Wwidth));
+R = [R1 R2 R3]';
+
+G1 = linspace(0, 1, Half-Wwidth);
+G2 = ones(1,Wwidth*2);
+G3 = flip(linspace(0.3137, 1, Half-Wwidth));
+G = [G1 G2 G3]';
+
+B1 = linspace(0.3137, 1, Half-Wwidth);
+B2 = ones(1,Wwidth*2);
+B3 = flip(linspace(0.1569, 1, Half-Wwidth));
+B = [B1 B2 B3]';
+
+CMap = [R G B];
+
+
diff --git a/Visualize_Results/scripts/helper_fun/fdr_bh.m b/Visualize_Results/scripts/helper_fun/fdr_bh.m
new file mode 100644
index 0000000..ef12d8b
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/fdr_bh.m
@@ -0,0 +1,226 @@
+% fdr_bh() - Executes the Benjamini & Hochberg (1995) and the Benjamini &
+% Yekutieli (2001) procedure for controlling the false discovery
+% rate (FDR) of a family of hypothesis tests. FDR is the expected
+% proportion of rejected hypotheses that are mistakenly rejected
+% (i.e., the null hypothesis is actually true for those tests).
+% FDR is a somewhat less conservative/more powerful method for
+% correcting for multiple comparisons than procedures like Bonferroni
+% correction that provide strong control of the family-wise
+% error rate (i.e., the probability that one or more null
+% hypotheses are mistakenly rejected).
+%
+% This function also returns the false coverage-statement rate
+% (FCR)-adjusted selected confidence interval coverage (i.e.,
+% the coverage needed to construct multiple comparison corrected
+% confidence intervals that correspond to the FDR-adjusted p-values).
+%
+%
+% Usage:
+% >> [h, crit_p, adj_ci_cvrg, adj_p]=fdr_bh(pvals,q,method,report);
+%
+% Required Input:
+% pvals - A vector or matrix (two dimensions or more) containing the
+% p-value of each individual test in a family of tests.
+%
+% Optional Inputs:
+% q - The desired false discovery rate. {default: 0.05}
+% method - ['pdep' or 'dep'] If 'pdep,' the original Bejnamini & Hochberg
+% FDR procedure is used, which is guaranteed to be accurate if
+% the individual tests are independent or positively dependent
+% (e.g., Gaussian variables that are positively correlated or
+% independent). If 'dep,' the FDR procedure
+% described in Benjamini & Yekutieli (2001) that is guaranteed
+% to be accurate for any test dependency structure (e.g.,
+% Gaussian variables with any covariance matrix) is used. 'dep'
+% is always appropriate to use but is less powerful than 'pdep.'
+% {default: 'pdep'}
+% report - ['yes' or 'no'] If 'yes', a brief summary of FDR results are
+% output to the MATLAB command line {default: 'no'}
+%
+%
+% Outputs:
+% h - A binary vector or matrix of the same size as the input "pvals."
+% If the ith element of h is 1, then the test that produced the
+% ith p-value in pvals is significant (i.e., the null hypothesis
+% of the test is rejected).
+% crit_p - All uncorrected p-values less than or equal to crit_p are
+% significant (i.e., their null hypotheses are rejected). If
+% no p-values are significant, crit_p=0.
+% adj_ci_cvrg - The FCR-adjusted BH- or BY-selected
+% confidence interval coverage. For any p-values that
+% are significant after FDR adjustment, this gives you the
+% proportion of coverage (e.g., 0.99) you should use when generating
+% confidence intervals for those parameters. In other words,
+% this allows you to correct your confidence intervals for
+% multiple comparisons. You can NOT obtain confidence intervals
+% for non-significant p-values. The adjusted confidence intervals
+% guarantee that the expected FCR is less than or equal to q
+% if using the appropriate FDR control algorithm for the
+% dependency structure of your data (Benjamini & Yekutieli, 2005).
+% FCR (i.e., false coverage-statement rate) is the proportion
+% of confidence intervals you construct
+% that miss the true value of the parameter. adj_ci=NaN if no
+% p-values are significant after adjustment.
+% adj_p - All adjusted p-values less than or equal to q are significant
+% (i.e., their null hypotheses are rejected). Note, adjusted
+% p-values can be greater than 1.
+%
+%
+% References:
+% Benjamini, Y. & Hochberg, Y. (1995) Controlling the false discovery
+% rate: A practical and powerful approach to multiple testing. Journal
+% of the Royal Statistical Society, Series B (Methodological). 57(1),
+% 289-300.
+%
+% Benjamini, Y. & Yekutieli, D. (2001) The control of the false discovery
+% rate in multiple testing under dependency. The Annals of Statistics.
+% 29(4), 1165-1188.
+%
+% Benjamini, Y., & Yekutieli, D. (2005). False discovery rate?adjusted
+% multiple confidence intervals for selected parameters. Journal of the
+% American Statistical Association, 100(469), 71?81. doi:10.1198/016214504000001907
+%
+%
+% Example:
+% nullVars=randn(12,15);
+% [~, p_null]=ttest(nullVars); %15 tests where the null hypothesis
+% %is true
+% effectVars=randn(12,5)+1;
+% [~, p_effect]=ttest(effectVars); %5 tests where the null
+% %hypothesis is false
+% [h, crit_p, adj_ci_cvrg, adj_p]=fdr_bh([p_null p_effect],.05,'pdep','yes');
+% data=[nullVars effectVars];
+% fcr_adj_cis=NaN*zeros(2,20); %initialize confidence interval bounds to NaN
+% if ~isnan(adj_ci_cvrg),
+% sigIds=find(h);
+% fcr_adj_cis(:,sigIds)=tCIs(data(:,sigIds),adj_ci_cvrg); % tCIs.m is available on the
+% %Mathworks File Exchagne
+% end
+%
+%
+% For a review of false discovery rate control and other contemporary
+% techniques for correcting for multiple comparisons see:
+%
+% Groppe, D.M., Urbach, T.P., & Kutas, M. (2011) Mass univariate analysis
+% of event-related brain potentials/fields I: A critical tutorial review.
+% Psychophysiology, 48(12) pp. 1711-1725, DOI: 10.1111/j.1469-8986.2011.01273.x
+% http://www.cogsci.ucsd.edu/~dgroppe/PUBLICATIONS/mass_uni_preprint1.pdf
+%
+%
+% For a review of FCR-adjusted confidence intervals (CIs) and other techniques
+% for adjusting CIs for multiple comparisons see:
+%
+% Groppe, D.M. (in press) Combating the scientific decline effect with
+% confidence (intervals). Psychophysiology.
+% http://biorxiv.org/content/biorxiv/early/2015/12/10/034074.full.pdf
+%
+%
+% Author:
+% David M. Groppe
+% Kutaslab
+% Dept. of Cognitive Science
+% University of California, San Diego
+% March 24, 2010
+
+%%%%%%%%%%%%%%%% REVISION LOG %%%%%%%%%%%%%%%%%
+%
+% 5/7/2010-Added FDR adjusted p-values
+% 5/14/2013- D.H.J. Poot, Erasmus MC, improved run-time complexity
+% 10/2015- Now returns FCR adjusted confidence intervals
+
+function [h, crit_p, adj_ci_cvrg, adj_p]=fdr_bh(pvals,q,method,report)
+
+if nargin<1,
+ error('You need to provide a vector or matrix of p-values.');
+else
+ if ~isempty(find(pvals<0,1)),
+ error('Some p-values are less than 0.');
+ elseif ~isempty(find(pvals>1,1)),
+ error('Some p-values are greater than 1.');
+ end
+end
+
+if nargin<2,
+ q=.05;
+end
+
+if nargin<3,
+ method='pdep';
+end
+
+if nargin<4,
+ report='no';
+end
+
+s=size(pvals);
+if (length(s)>2) || s(1)>1,
+ [p_sorted, sort_ids]=sort(reshape(pvals,1,prod(s)));
+else
+ %p-values are already a row vector
+ [p_sorted, sort_ids]=sort(pvals);
+end
+[dummy, unsort_ids]=sort(sort_ids); %indexes to return p_sorted to pvals order
+m=length(p_sorted); %number of tests
+
+if strcmpi(method,'pdep'),
+ %BH procedure for independence or positive dependence
+ thresh=(1:m)*q/m;
+ wtd_p=m*p_sorted./(1:m);
+
+elseif strcmpi(method,'dep')
+ %BH procedure for any dependency structure
+ denom=m*sum(1./(1:m));
+ thresh=(1:m)*q/denom;
+ wtd_p=denom*p_sorted./[1:m];
+ %Note, it can produce adjusted p-values greater than 1!
+ %compute adjusted p-values
+else
+ error('Argument ''method'' needs to be ''pdep'' or ''dep''.');
+end
+
+if nargout>3,
+ %compute adjusted p-values; This can be a bit computationally intensive
+ adj_p=zeros(1,m)*NaN;
+ [wtd_p_sorted, wtd_p_sindex] = sort( wtd_p );
+ nextfill = 1;
+ for k = 1 : m
+ if wtd_p_sindex(k)>=nextfill
+ adj_p(nextfill:wtd_p_sindex(k)) = wtd_p_sorted(k);
+ nextfill = wtd_p_sindex(k)+1;
+ if nextfill>m
+ break;
+ end;
+ end;
+ end;
+ adj_p=reshape(adj_p(unsort_ids),s);
+end
+
+rej=p_sorted<=thresh;
+max_id=find(rej,1,'last'); %find greatest significant pvalue
+if isempty(max_id),
+ crit_p=0;
+ h=pvals*0;
+ adj_ci_cvrg=NaN;
+else
+ crit_p=p_sorted(max_id);
+ h=pvals<=crit_p;
+ adj_ci_cvrg=1-thresh(max_id);
+end
+
+if strcmpi(report,'yes'),
+ n_sig=sum(p_sorted<=crit_p);
+ if n_sig==1,
+ fprintf('Out of %d tests, %d is significant using a false discovery rate of %f.\n',m,n_sig,q);
+ else
+ fprintf('Out of %d tests, %d are significant using a false discovery rate of %f.\n',m,n_sig,q);
+ end
+ if strcmpi(method,'pdep'),
+ fprintf('FDR/FCR procedure used is guaranteed valid for independent or positively dependent tests.\n');
+ else
+ fprintf('FDR/FCR procedure used is guaranteed valid for independent or dependent tests.\n');
+ end
+end
+
+
+
+
diff --git a/Visualize_Results/scripts/helper_fun/helper_boxplot.m b/Visualize_Results/scripts/helper_fun/helper_boxplot.m
new file mode 100644
index 0000000..80c1a04
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_boxplot.m
@@ -0,0 +1,91 @@
+function helper_boxplot(seed1, seed2, seeds, ROIs)
+
+%% Run with MATLAB 2021b and later.
+
+n_seeds = length(seeds);
+
+% labels
+label = ROIs.name;
+for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+end
+
+%% dorsal stream
+idx_dorsal = 1:17;
+dorsal = myLabel(idx_dorsal);
+n_targets = length(dorsal);
+ROI_FEF = seed1(ROIs.idx(idx_dorsal),:)';
+ROI_IFJ = seed2(ROIs.idx(idx_dorsal),:)';
+
+tmp_Seeds = repmat(repmat(seeds,1,1), 1, 55*n_targets)';
+Seeds = tmp_Seeds(:);
+Targets = repmat(repmat(dorsal',55,1), n_seeds, 1);
+Subjects = repmat(repmat(1:55,1,n_targets)', n_seeds, 1);
+targetsOrder = dorsal;
+Conn_values = [ROI_FEF(:);ROI_IFJ(:)];
+results_tab = table(Seeds,Targets,Conn_values);
+results_tab.Targets = categorical(results_tab.Targets, targetsOrder);
+figure; h_one = boxchart(results_tab.Targets, results_tab.Conn_values, 'GroupByColor', results_tab.Seeds);
+legend
+title('Dorsam Visual Stream', 'fontweight','bold', 'FontSize', 15)
+set(gcf, 'Position', get(0, 'Screensize'));
+
+clear results_tab
+
+h_one(1).SeriesIndex = 2;
+h_one(2).SeriesIndex = 1;
+h_one(1).WhiskerLineStyle = ':';
+h_one(2).WhiskerLineStyle = ':';
+h_one(1).MarkerSize = 6;
+h_one(2).MarkerSize = 6;
+
+
+xlabel('ROIs', 'fontweight','bold', 'FontSize', 12)
+ylabel('Connectivity Values', 'fontweight','bold', 'FontSize', 12)
+ax=gca;
+ax.FontSize = 12;
+
+print(gcf,'C:\Users\ASUS\Desktop\dorsal_boxchart.png','-dpng','-r300');
+
+
+%% ventral stream
+idx_ventral = 18:33;
+ventral = myLabel(idx_ventral);
+n_targets = length(ventral);
+ROI_FEF = seed1(ROIs.idx(idx_ventral),:)';
+ROI_IFJ = seed2(ROIs.idx(idx_ventral),:)';
+
+tmp_Seeds = repmat(repmat(seeds,1,1), 1, 55*n_targets)';
+Seeds = tmp_Seeds(:);
+Targets = repmat(repmat(ventral',55,1), n_seeds, 1);
+Subjects = repmat(repmat(1:55,1,n_targets)', n_seeds, 1);
+targetsOrder = ventral;
+Conn_values = [ROI_FEF(:);ROI_IFJ(:)];
+results_tab = table(Seeds,Targets,Conn_values);
+results_tab.Targets = categorical(results_tab.Targets, targetsOrder);
+figure; h_two = boxchart(results_tab.Targets, results_tab.Conn_values, 'GroupByColor', results_tab.Seeds);
+legend
+title('Ventral Visual Stream', 'fontweight','bold', 'FontSize', 15)
+set(gcf, 'Position', get(0, 'Screensize'));
+
+clear results_tab
+
+h_two(1).SeriesIndex = 2;
+h_two(2).SeriesIndex = 1;
+h_two(1).WhiskerLineStyle = ':';
+h_two(2).WhiskerLineStyle = ':';
+h_two(1).MarkerSize = 6;
+h_two(2).MarkerSize = 6;
+
+
+xlabel('ROIs', 'fontweight','bold', 'FontSize', 12)
+ylabel('Connectivity Values', 'fontweight','bold', 'FontSize', 12)
+ax=gca;
+ax.FontSize = 12;
+
+
+print(gcf,'C:\Users\ASUS\Desktop\ventral_boxchart.png','-dpng','-r300');
+
+
+end
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/helper_effectiveConn_fsaverage.m b/Visualize_Results/scripts/helper_fun/helper_effectiveConn_fsaverage.m
new file mode 100644
index 0000000..e69dff6
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_effectiveConn_fsaverage.m
@@ -0,0 +1,508 @@
+function results = helper_effectiveConn_fsaverage(cimec)
+
+inputfile_conn = cimec.inputfile_conn;
+band_name = cimec.band_name;
+seed_target = cimec.seed_target;
+conn_metric = cimec.conn_metric;
+statistics = cimec.statistics;
+colorlim_value = cimec.colorlim_value;
+flag = cimec.flag;
+
+%%
+addpath(genpath(fullfile(fileparts(fileparts(pwd)), 'helper_fun')));
+
+statistics.contrast = true;
+statistics.stat = true;
+statistics.f_stats = @signrank;
+statistics.f_correction = @fdr_bh;
+
+IFJ_merged = false;
+ROIs.do = true; % fixed
+
+colorlim = true;
+
+%%
+% fsaverage
+inflated = true;
+if strcmp(statistics.analysis_type, 'exploratory')
+ smoothing = '70'; % percent
+else
+ smoothing = '100'; % percent
+end
+inputfile_fs = fullfile(load_path('inputfile_fs'), 'fsaverage.mat');
+inputfile_fs_inflated = fullfile(load_path('inputfile_fs'), sprintf('fsaverage_inflated_%s.mat', smoothing));
+
+% seed to target
+dorsal_R = { 'R_V6_ROI R', 'R_V6A_ROI R', 'R_V7_ROI R', 'R_IPS1_ROI R', 'R_IP1_ROI R', 'R_MIP_ROI R', ...
+ 'R_VIP_ROI R', 'R_LIPd_ROI R', 'R_LIPv_ROI R', 'R_7AL_ROI R', 'R_7PC_ROI R', 'R_7PL_ROI R', ...
+ 'R_V3A_ROI R', 'R_V3B_ROI R', 'R_V3CD_ROI R', 'R_LO3_ROI R', 'R_MT_ROI R'};
+ventral_R = {'R_V8_ROI R', 'R_VMV1_ROI R', 'R_VMV2_ROI R', 'R_VMV3_ROI R', 'R_PHT_ROI R', 'R_PH_ROI R', ...
+ 'R_TE1a_ROI R', 'R_TE1m_ROI R', 'R_TE1p_ROI R', 'R_TE2a_ROI R', 'R_TE2p_ROI R', ...
+ 'R_TF_ROI R', 'R_TGv_ROI R', 'R_FFC_ROI R', 'R_PIT_ROI R', 'R_VVC_ROI R'};
+
+dorsal_L = { 'L_V6_ROI L', 'L_V6A_ROI L', 'L_V7_ROI L', 'L_IPS1_ROI L', 'L_IP1_ROI L', 'L_MIP_ROI L', ...
+ 'L_VIP_ROI L', 'L_LIPd_ROI L', 'L_LIPv_ROI L', 'L_7AL_ROI L', 'L_7PC_ROI L', 'L_7PL_ROI L', ...
+ 'L_V3A_ROI L', 'L_V3B_ROI L', 'L_V3CD_ROI L', 'L_LO3_ROI L', 'L_MT_ROI L'};
+ventral_L = {'L_V8_ROI L', 'L_VMV1_ROI L', 'L_VMV2_ROI L', 'L_VMV3_ROI L', 'L_PHT_ROI L', 'L_PH_ROI L', ...
+ 'L_TE1a_ROI L', 'L_TE1m_ROI L', 'L_TE1p_ROI L', 'L_TE2a_ROI L', 'L_TE2p_ROI L', ...
+ 'L_TF_ROI L', 'L_TGv_ROI L', 'L_FFC_ROI L', 'L_PIT_ROI L', 'L_VVC_ROI L'};
+
+
+if strcmp(seed_target, 'right-right')
+ between = {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-3 & 2-3
+ ROIs.name = ['R_FEF_ROI R', 'R_IFJa_ROI R', 'R_IFJp_ROI R', dorsal_R, ventral_R];
+elseif strcmp(seed_target, 'right-left')
+ between = {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-3 & 2-3
+ ROIs.name = ['R_FEF_ROI R', 'R_IFJa_ROI R', 'R_IFJp_ROI R', dorsal_L ventral_L];
+elseif strcmp(seed_target, 'left-left')
+ between = {'L_IFJa_ROI L', 'L_IFJp_ROI L', 'L_FEF_ROI L'}; % 1-3 & 2-3
+ ROIs.name = ['L_FEF_ROI L', 'L_IFJa_ROI L', 'L_IFJp_ROI L', dorsal_L ventral_L];
+elseif strcmp(seed_target, 'left-right')
+ between = {'L_IFJa_ROI L', 'L_IFJp_ROI L', 'L_FEF_ROI L'}; % 1-3 & 2-3
+ ROIs.name = ['L_FEF_ROI L', 'L_IFJa_ROI L', 'L_IFJp_ROI L', dorsal_R ventral_R];
+end
+
+
+%% Inputs
+cimec = struct;
+cimec.between = between;
+cimec.statistics = statistics;
+cimec.band_name = band_name;
+cimec.IFJ_merged = IFJ_merged;
+cimec.ROIs = ROIs;
+cimec.colorlim_value = colorlim_value;
+cimec.colorlim = colorlim;
+cimec.inputfile_conn = inputfile_conn;
+cimec.inputfile_fs = inputfile_fs;
+cimec.inflated = inflated;
+cimec.inputfile_fs_inflated = inputfile_fs_inflated;
+cimec.flag = flag;
+cimec.conn_metric = conn_metric;
+cimec.seed_target = seed_target;
+
+results = visualize_connectivity(cimec);
+
+%% Function
+ function results = visualize_connectivity(cimec)
+
+ %% Info about the data
+ inputfile_conn = cimec.inputfile_conn; % e.g. '...\HCP_Subjects\Outputs\connectivity_results\175237_connectivityResults__2s';
+ inputfile_fs = cimec.inputfile_fs; % e.g. '...\HCP_Subjects\Outputs\fsaverage_anatomy\175237_fsaverage';
+
+ contrast = cimec.statistics.contrast; % contrast map or not
+ between = cimec.between; % {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-2 & 1-3
+
+ stat = cimec.statistics.stat;
+ f_stats = cimec.statistics.f_stats; % e.g. @signrank
+ alpha = cimec.statistics.alpha; % e.g. 0.05
+ f_correction = cimec.statistics.f_correction; % correction method e.g. @fdr_bh
+ corrected = cimec.statistics.corrected; % e.g. true
+
+ IFJ_merged = cimec.IFJ_merged;
+
+ ROIs = cimec.ROIs;
+
+ band_name = cimec.band_name; % e.g. 'alpha';
+ colorlim_value = cimec.colorlim_value; % e.g. [0 0.10];
+ colorlim = cimec.colorlim; % e.g. true;
+
+ inflated = cimec.inflated; % e.g. true
+ inputfile_fs_inflated = cimec.inputfile_fs_inflated;
+
+ flag = cimec.flag;
+ conn_metric = cimec.conn_metric;
+ seed_target = cimec.seed_target;
+
+ %% Frequency bands
+ band_names = { 'delta' , 'theta' , 'alpha' , 'beta' , 'gamma' };
+ freq_bands = [ 1 4 ; 4 8 ; 8 13 ; 13 30 ; 30 100 ];
+
+ %% Load data
+ % avgFreq_icoh
+ load(inputfile_conn, 'group_results');
+ conn_results = group_results;
+
+ % fsaverage
+ load(inputfile_fs, 'fsaverage')
+
+ %% Prepare the anatomy
+ % Parcellation info (Brainstorm -> Fieldtrip)
+ tess_cortex_pial = fsaverage;
+
+ if inflated == true
+ fs_inflated = load(inputfile_fs_inflated);
+ tess_cortex_pial.Vertices = fs_inflated.Vertices;
+ tess_cortex_pial.Faces = fs_inflated.Faces;
+ end
+
+ Scouts = tess_cortex_pial.Atlas(end-1).Scouts;
+ Scouts_Vertices = {Scouts.Vertices}';
+ Scouts_Label = {Scouts.Label}';
+
+ parcellation = zeros(length([tess_cortex_pial.Vertices]), 1);
+ for idx = 1:length(Scouts_Vertices)
+ per_parcel = Scouts_Vertices{idx};
+
+ for ii = 1:length(per_parcel)
+ parcellation(per_parcel(ii)) = idx;
+ end
+ end
+
+ brainordinate.parcellation = parcellation;
+ brainordinate.parcellationlabel = Scouts_Label;
+ brainordinate.pos = tess_cortex_pial.Vertices;
+ brainordinate.tri = tess_cortex_pial.Faces;
+ brainordinate.brainstructure = tess_cortex_pial.SulciMap+1;
+ brainordinate.brainstructurelabel = {'CORTEX_LEFT', 'CORTEX_RIGHT'}';
+
+ %% Prepare the connectivity matrix
+ conn_mat = struct;
+ conn_mat.label = Scouts_Label;
+ conn_mat.band_names = band_name;
+ conn_mat.brainordinate = brainordinate;
+
+ idx_band = find(strcmp(band_names, band_name));
+ tmp_data = group_results(idx_band).data_perSubject;
+ tmp_data(isnan(tmp_data)) = 1;
+
+ %% seeds
+ idx_IFJa = find(strcmp(conn_mat.label, between{1}));
+ idx_IFJp = find(strcmp(conn_mat.label, between{2}));
+ idx_FEF = find(strcmp(conn_mat.label, between{3}));
+
+ IFJa_12(:, :) = tmp_data(idx_IFJa,:,:);
+ IFJp_12(:, :) = tmp_data(idx_IFJp,:,:);
+ FEF_12(:, :) = tmp_data(idx_FEF,:,:);
+ IFJa_21(:, :) = tmp_data(:,idx_IFJa,:);
+ IFJp_21(:, :) = tmp_data(:,idx_IFJp,:);
+ FEF_21(:, :) = tmp_data(:,idx_FEF,:);
+
+
+ % subtract two directions
+ % positive values mean seed region predicts the target
+ % negative values mean target is predicted by the seed region
+ IFJa(:, :) = IFJa_12 - IFJa_21;
+ IFJp(:, :) = IFJp_12 - IFJp_21;
+ FEF(:, :) = FEF_12 - FEF_21;
+
+ %% ROIs/exploratory
+ if strcmp(statistics.analysis_type, 'exploratory')
+ all_labels = conn_mat.label;
+ if strcmp(between{1}(1), 'R')
+ ROIs.name = all_labels(181:360);
+ elseif strcmp(between{1}(1), 'L')
+ ROIs.name = all_labels(1:180);
+ end
+ end
+
+ nROIs = length(ROIs.name);
+ for ii = 1:nROIs
+ ROIs.idx(ii) = find(strcmp(conn_mat.label, ROIs.name{ii}));
+ end
+
+
+ mask = zeros(360,1);
+ mask(ROIs.idx) = 1;
+
+ %% normality test
+ % stat_IFJa = IFJa;
+ % stat_IFJa(stat_IFJa(:,1)==1) = NaN;
+ % stat_FEF = FEF;
+ % stat_FEF(stat_FEF(:,1)==1) = NaN;
+ %
+ %
+ % for ii = 1:nROIs
+ % figure
+ % % histogram(atanh(stat_IFJa(ROIs.idx(ii),:)-stat_FEF(ROIs.idx(ii),:)));
+ % % histogram(stat_IFJa(ROIs.idx(ii),:)-stat_FEF(ROIs.idx(ii),:));
+ % % histogram(stat_IFJa(ROIs.idx(ii),:));
+ % histogram(atanh(stat_IFJa(ROIs.idx(ii),:)));
+ % end
+ %
+ % figure
+ % hist(atanh(stat_IFJa(ROIs.idx(33),:)-stat_FEF(ROIs.idx(33),:)));
+ % figure
+ % hist(stat_IFJa(ROIs.idx(33),:)-stat_FEF(ROIs.idx(33),:));
+
+
+ %%
+ if contrast == true
+ %% Inferential statistics
+ %% Wilcoxon signed rank test
+ if IFJ_merged == false
+ % R_IFJa
+ for ii = 1:nROIs
+ pair_1 = IFJa(ROIs.idx(ii),:)';
+ pair_2 = 0;
+
+ [P, H, ~] = f_stats(pair_1, pair_2, 'Alpha', alpha, 'Tail', 'both');
+
+ H_Wilcoxon_IFJa(ii) = H;
+ P_Wilcoxon_IFJa(ii) = P;
+ end
+
+ % R_IFJp
+ for ii = 1:nROIs
+ pair_1 = IFJp(ROIs.idx(ii),:)';
+ pair_2 = 0;
+
+ [P, H, ~] = f_stats(pair_1, pair_2, 'Alpha', alpha, 'Tail', 'both');
+
+ H_Wilcoxon_IFJp(ii) = H;
+ P_Wilcoxon_IFJp(ii) = P;
+ end
+
+ % FEF
+ for ii = 1:nROIs
+ pair_1 = FEF(ROIs.idx(ii),:)';
+ pair_2 = 0;
+
+ [P, H, ~] = f_stats(pair_1, pair_2, 'Alpha', alpha, 'Tail', 'both');
+
+ H_Wilcoxon_FEF(ii) = H;
+ P_Wilcoxon_FEF(ii) = P;
+ end
+ end
+ %% FDR correction
+ if corrected == false
+ % clear NaNs
+ H_Wilcoxon_IFJa(isnan(H_Wilcoxon_IFJa)) = 0;
+ H_Wilcoxon_IFJp(isnan(H_Wilcoxon_IFJp)) = 0;
+
+ % mask connectivity values
+ group_IFJa_contrast = mean(IFJa, 2);
+ right_group_IFJa = group_IFJa_contrast(ROIs.idx);
+ right_group_IFJa(~H_Wilcoxon_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = right_group_IFJa;
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_contrast = mean(IFJp, 2);
+ right_group_IFJp = group_IFJp_contrast(ROIs.idx);
+ right_group_IFJp(~H_Wilcoxon_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = right_group_IFJp;
+ stats_IFJp = group_IFJp;
+
+ % clear NaNs
+ H_Wilcoxon_FEF(isnan(H_Wilcoxon_FEF)) = 0;
+
+ % mask connectivity values
+ group_FEF_contrast = mean(FEF, 2);
+ right_group_FEF = group_FEF_contrast(ROIs.idx);
+ right_group_FEF(~H_Wilcoxon_FEF) = 0;
+ group_FEF = zeros(360,1);
+ group_FEF(ROIs.idx) = right_group_FEF;
+ stats_FEF = group_FEF;
+
+ elseif corrected == true
+ % FDR correction
+ P_Wilcoxon_IFJa(isnan(P_Wilcoxon_IFJa)) = 1;
+ P_Wilcoxon_IFJp(isnan(P_Wilcoxon_IFJp)) = 1;
+ P_Wilcoxon_FEF(isnan(P_Wilcoxon_FEF)) = 1;
+ [h_adj_IFJa, ~, ~, p_adj_IFJa] = f_correction(P_Wilcoxon_IFJa(~isnan(P_Wilcoxon_IFJa)), alpha, 'pdep', 'yes');
+ [h_adj_IFJp, ~, ~, p_adj_IFJp] = f_correction(P_Wilcoxon_IFJp(~isnan(P_Wilcoxon_IFJp)), alpha, 'pdep', 'yes');
+ [h_adj_FEF, ~, ~, p_adj_FEF] = f_correction(P_Wilcoxon_FEF(~isnan(P_Wilcoxon_FEF)), alpha, 'pdep', 'yes');
+
+
+ % z-score
+ % for two-tailed: abs(norminv(p/2));
+ z_adj_IFJa = abs(norminv(p_adj_IFJa/2));
+ z_adj_IFJp = abs(norminv(p_adj_IFJp/2));
+ z_adj_FEF = abs(norminv(p_adj_FEF/2));
+
+
+ group_IFJa_contrast = mean(IFJa, 2);
+ right_group_IFJa = group_IFJa_contrast(ROIs.idx);
+ right_group_IFJa(~h_adj_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = z_adj_IFJa'.*sign(right_group_IFJa);
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_contrast = mean(IFJp, 2);
+ right_group_IFJp = group_IFJp_contrast(ROIs.idx);
+ right_group_IFJp(~h_adj_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = z_adj_IFJp'.*sign(right_group_IFJp);
+ stats_IFJp = group_IFJp;
+
+ group_FEF_contrast = mean(FEF, 2);
+ right_group_FEF = group_FEF_contrast(ROIs.idx);
+ right_group_FEF(~h_adj_FEF) = 0;
+ group_FEF = zeros(360,1);
+ group_FEF(ROIs.idx) = z_adj_FEF'.*sign(right_group_FEF);
+ stats_FEF = group_FEF;
+
+ % % mask connectivity values
+ % group_IFJa_contrast = mean(IFJa, 2);
+ % right_group_IFJa = group_IFJa_contrast(ROIs.idx);
+ % right_group_IFJa(~h_adj_IFJa) = 0;
+ % group_IFJa = zeros(360,1);
+ % group_IFJa(ROIs.idx) = right_group_IFJa;
+ % stats_IFJa = group_IFJa;
+ %
+ % group_IFJp_contrast = mean(IFJp, 2);
+ % right_group_IFJp = group_IFJp_contrast(ROIs.idx);
+ % right_group_IFJp(~h_adj_IFJp) = 0;
+ % group_IFJp = zeros(360,1);
+ % group_IFJp(ROIs.idx) = right_group_IFJp;
+ % stats_IFJp = group_IFJp;
+
+% % mask connectivity values
+% group_FEF_contrast = mean(FEF, 2);
+% right_group_FEF = group_FEF_contrast(ROIs.idx);
+% right_group_FEF(~h_adj_FEF) = 0;
+% group_FEF = zeros(360,1);
+% group_FEF(ROIs.idx) = right_group_FEF;
+% stats_FEF = group_FEF;
+ end
+
+ %% Final matrix (360x360)
+ if IFJ_merged == false
+ tmp_data = diag(ones(360,1));
+
+ tmp_data(:,idx_IFJa) = stats_IFJa';
+ tmp_data(:,idx_IFJp) = stats_IFJp';
+ tmp_data(:,idx_FEF) = stats_FEF';
+ end
+
+ end
+
+ %% To make black the areas outside ROI
+ cbar = customMap_effectiveConn;
+ if strcmp(cimec.statistics.analysis_type, 'ROI')
+ n = size(cbar, 1);
+ up = cbar(1:n/2,:);
+ middle = [0.5 0.5 0.5];
+ down = cbar(n/2+1:n,:);
+ set(0, 'DefaultFigureColormap', [up;middle;down]);
+ else
+ set(0, 'DefaultFigureColormap', cbar);
+ end
+
+ if strcmp(statistics.analysis_type, 'ROI')
+ tmp_data(ROIs.idx(~h_adj_IFJa),idx_IFJa) = 0.04;
+ tmp_data(ROIs.idx(~h_adj_IFJp),idx_IFJp) = 0.04;
+ tmp_data(ROIs.idx(~h_adj_FEF),idx_FEF) = 0.04;
+ tmp_data(idx_IFJa,ROIs.idx(~h_adj_IFJa)) = 0.04;
+ tmp_data(idx_IFJp,ROIs.idx(~h_adj_IFJp)) = 0.04;
+ tmp_data(idx_FEF,ROIs.idx(~h_adj_FEF)) = 0.04;
+ end
+
+
+ %%
+ conn_mat.cohspctrm = tmp_data;
+
+ % output
+ results.helper.idx_IFJa = idx_IFJa;
+ results.helper.idx_IFJp = idx_IFJp;
+ results.helper.idx_FEF = idx_FEF;
+ results.helper.ROIs = ROIs;
+ results.helper.brainordinate = brainordinate;
+ results.conn_matrix = tmp_data;
+ results.label = conn_mat.label;
+ results.stat.h_adj_IFJa = h_adj_IFJa;
+ results.stat.h_adj_IFJp = h_adj_IFJp;
+ results.stat.h_adj_FEF = h_adj_FEF;
+
+ results.perSubject.IFJa_12 = IFJa_12;
+ results.perSubject.IFJp_12 = IFJp_12;
+ results.perSubject.FEF_12 = FEF_12;
+
+ results.perSubject.IFJa_21 = IFJa_21;
+ results.perSubject.IFJp_21 = IFJp_21;
+ results.perSubject.FEF_21 = FEF_21;
+
+ %% Visualize using the helper function
+ if flag.fsaverage == true
+ % in order to run the function
+ conn_mat.brainordinate.pos = conn_mat.brainordinate.pos*1000;
+
+ %% save the figure
+ if and(colorlim == true, flag.save_fig == true)
+
+ if seed_target(1) == 'r'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ pos2d_IFJa_R = [52.5323 -69.3638 71.0650; 52.5323 69.4183 71.0650];
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJa_R = [52.5323 -69.3638 71.0650; 52.5323 69.4183 71.0650];
+ else
+ pos2d_IFJa_R = [49.7454 -69.6590 70.1540; 49.7454 69.1230 70.1540];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_R);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJp_R = [45.6139 -69.3638 76.8706 ; 45.6139 69.4183 76.8706];
+ else
+ pos2d_IFJp_R = [44.7673 -69.6590 76.5544 ; 44.7673 69.1230 76.5544];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_R);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'FEF';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_FEF_R = [30.1309 -69.3638 103.7783 ; 30.1309 69.4183 103.7783];
+ else
+ pos2d_FEF_R = [30.8997 -69.6590 101.8004 ; 30.8997 69.1230 101.8004];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_R);
+ helper_save_figure(cimec);
+ close all;
+
+ elseif seed_target(1) == 'l'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJa_L = [50.5105 69.4183 69.5634 ; 53.1465 -69.3638 68.2860];
+ else
+ pos2d_IFJa_L = [47.6119 69.1230 68.3761 ; 47.6119 -69.6590 68.3761];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_L);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJp_L = [43.6193 69.4183 80.0619 ; 43.6193 -69.3638 80.0619];
+ else
+ pos2d_IFJp_L = [40.8559 69.1230 76.9099 ; 40.8559 -69.6590 76.9099];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_L);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'FEF';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_FEF_L = [30.6545 69.4183 105.7922 ; 30.6545 -69.3638 105.7922];
+ else
+ pos2d_FEF_L = [33.7443 69.1230 101.0893 ; 33.7443 -69.6590 101.0893];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_L);
+ helper_save_figure(cimec);
+ close all;
+ end
+
+ %% show the figure
+ elseif colorlim == true
+ tutorial_nwa_connectivityviewer(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours);
+ elseif colorlim == false
+ tutorial_nwa_connectivityviewer(conn_mat, 'cohspctrm', seed_target, flag.contours);
+ end
+
+ if contrast == false
+ colormap('parula')
+ end
+ end
+
+ end
+end
diff --git a/Visualize_Results/scripts/helper_fun/helper_functionConn_circularGraph.m b/Visualize_Results/scripts/helper_fun/helper_functionConn_circularGraph.m
new file mode 100644
index 0000000..23eab99
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_functionConn_circularGraph.m
@@ -0,0 +1,360 @@
+function helper_functionConn_circularGraph(results, fontSize, flag)
+
+if flag.contrast == true
+ figure;
+ contrast_pair = 'FEF-IFJp';
+ helper_circularGraph_contrast(results, fontSize, flag, contrast_pair)
+ contrast_pair = 'FEF-IFJa';
+ helper_circularGraph_contrast(results, fontSize, flag, contrast_pair)
+else
+ figure;
+ seed = 'FEF';
+ helper_circularGraph_notContrast(results, fontSize, flag, seed)
+ figure;
+ seed = 'IFJa';
+ helper_circularGraph_notContrast(results, fontSize, flag, seed)
+ figure;
+ seed = 'IFJp';
+ helper_circularGraph_notContrast(results, fontSize, flag, seed)
+end
+
+%%
+ function helper_circularGraph_contrast(results, fontSize, flag, pair)
+
+ tmp_mat = results.conn_matrix;
+ idx_FEF = results.helper.idx_FEF;
+ idx_IFJa = results.helper.idx_IFJa;
+ idx_IFJp = results.helper.idx_IFJp;
+ ROIs = results.helper.ROIs;
+ analysis_type = results.stat.analysis_type;
+
+ band_name = results.cimec.band_name ;
+ conn_metric = results.cimec.conn_metric;
+ seed_target = results.cimec.seed_target;
+ alpha = char(string(results.cimec.statistics.alpha));
+ correction = results.cimec.statistics.correction;
+ duration = results.cimec.flag.duration;
+
+ % https://sashamaps.net/docs/resources/20-colors/
+ % https://html-color.codes/blue
+ FEF_color_1 = [255,0,0]/255;
+ FEF_color_2 = [255,160,122]/255;
+ IFJa_color = [0,0,255]/255; %[0, 92, 171]/255;
+ IFJp_color = [173,216,230]/255; %[70, 240, 240]/255;
+
+ if strcmp(pair, 'FEF-IFJa')
+
+ %% ROI analysis
+ if strcmp(analysis_type, 'ROI')
+
+ idxs = [idx_FEF, idx_IFJa, idx_IFJp, flip(ROIs.idx)];
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+
+ % to make FEF results explicit
+ data = data*-1;
+
+ data(1,data(2,:)<0) = abs(data(2,data(2,:)<0));
+ data(2,data(2,:)<0) = 0;
+ data(:,1) = data(1,:);
+ data(:,2) = data(2,:);
+ data(:,3) = 0;
+ data(3,:) = 0;
+
+ label = results.label(idxs);
+
+ if flag.collapseTargets == true
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(3:end-6);
+ end
+ else
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+ end
+ end
+
+ % color
+ % https://sashamaps.net/docs/resources/20-colors/
+ myColorMap = repmat([1 1 1], length(idxs), 1);
+ myColorMap(1,:) = FEF_color_1;
+ myColorMap(2,:) = IFJa_color;
+
+ %% Exploratory analysis
+ elseif strcmp(analysis_type, 'exploratory')
+
+ figure;
+
+ idxs = ROIs.idx;
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+
+ % to make FEF results explicit
+ data = data*-1;
+
+ data(1,data(2,:)<0) = abs(data(2,data(2,:)<0));
+ data(2,data(2,:)<0) = 0;
+ data(:,1) = data(1,:);
+ data(:,2) = data(2,:);
+ data(:,3) = 0;
+ data(3,:) = 0;
+
+ label = results.label(idxs);
+
+ if flag.collapseTargets == true
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(3:end-6);
+ end
+ else
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+ end
+ end
+
+ % color
+ % https://sashamaps.net/docs/resources/20-colors/
+ myColorMap = repmat([1 1 1], length(idxs), 1);
+ myColorMap(idx_FEF-180,:) = FEF_color_1;
+ myColorMap(idx_IFJa-180,:) = IFJa_color;
+ end
+
+ %% Circular graph for all together
+ circularGraph(data', 'Colormap', myColorMap, 'Label', myLabel);
+ title('All Frequency Bands')
+ set(gcf, 'Position', get(0, 'Screensize'));
+
+ fg1 = gca;
+ fg2 = get(fg1, 'children');
+
+ for ii = 1:length(fg2)
+ try
+ tmp_fg = fg2(ii);
+ tmp_fg.FontSize = fontSize;
+ catch
+ fprintf('Almost ready...\n', i);
+ end
+ end
+
+ if flag.save_fig == true
+ name = [ contrast_pair '_circularGraph_' conn_metric '_' band_name '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf, [flag.dir_fig name '.png'], '-dpng', '-r300');
+ close all
+ end
+
+ elseif strcmp(pair, 'FEF-IFJp')
+ %% ROI analysis
+ if strcmp(analysis_type, 'ROI')
+
+ idxs = [idx_FEF, idx_IFJa, idx_IFJp, flip(ROIs.idx)];
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+
+ % to make FEF results explicit
+ data = data*-1;
+
+ data(1,data(3,:)<0) = abs(data(3,data(3,:)<0));
+ data(3,data(3,:)<0) = 0;
+ data(:,1) = data(1,:);
+ data(:,3) = data(3,:);
+ data(:,2) = 0;
+ data(2,:) = 0;
+
+ label = results.label(idxs);
+
+ if flag.collapseTargets == true
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(3:end-6);
+ end
+ else
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+ end
+ end
+
+ % color
+ % https://sashamaps.net/docs/resources/20-colors/
+ myColorMap = repmat([1 1 1], length(idxs), 1);
+ myColorMap(1,:) = FEF_color_2;
+ myColorMap(3,:) = IFJp_color;
+
+ %% Exploratory analysis
+ elseif strcmp(analysis_type, 'exploratory')
+
+ idxs = ROIs.idx;
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+
+ % to make FEF results explicit
+ data = data*-1;
+
+ data(1,data(3,:)<0) = abs(data(3,data(3,:)<0));
+ data(3,data(3,:)<0) = 0;
+ data(:,1) = data(1,:);
+ data(:,3) = data(3,:);
+ data(:,2) = 0;
+ data(2,:) = 0;
+
+ label = results.label(idxs);
+
+ if flag.collapseTargets == true
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(3:end-6);
+ end
+ else
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+ end
+ end
+
+ % color
+ % https://sashamaps.net/docs/resources/20-colors/
+ myColorMap = repmat([1 1 1], length(idxs), 1);
+ myColorMap(idx_FEF-180,:) = FEF_color_2;
+ myColorMap(idx_IFJp-180,:) = IFJp_color;
+ end
+ %% Circular graph for all together
+ circularGraph(data', 'Colormap', myColorMap, 'Label', myLabel);
+ title('All Frequency Bands')
+ set(gcf, 'Position', get(0, 'Screensize'));
+
+ fg1 = gca;
+ fg2 = get(fg1, 'children');
+
+ for ii = 1:length(fg2)
+ try
+ tmp_fg = fg2(ii);
+ tmp_fg.FontSize = fontSize;
+ catch
+ fprintf('Almost ready...\n', i);
+ end
+ end
+
+ if flag.save_fig == true
+ name = [contrast_pair '_circularGraph_' conn_metric '_' band_name '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf, [flag.dir_fig name '.png'], '-dpng', '-r300');
+ close all
+ end
+
+
+ end
+ end
+
+ function helper_circularGraph_notContrast(results, fontSize, flag, seed)
+
+ tmp_mat = results.conn_matrix;
+ idx_FEF = results.helper.idx_FEF;
+ idx_IFJa = results.helper.idx_IFJa;
+ idx_IFJp = results.helper.idx_IFJp;
+ ROIs = results.helper.ROIs;
+ analysis_type = results.stat.analysis_type;
+
+ band_name = results.cimec.band_name ;
+ conn_metric = results.cimec.conn_metric;
+ seed_target = results.cimec.seed_target;
+ alpha = char(string(results.cimec.statistics.alpha));
+ correction = results.cimec.statistics.correction;
+ duration = results.cimec.flag.duration;
+
+ % https://sashamaps.net/docs/resources/20-colors/
+ % https://html-color.codes/blue
+ FEF_color = [255,0,0]/255;
+ IFJa_color = [0,0,255]/255; %[0, 92, 171]/255;
+ IFJp_color = [173,216,230]/255; %[70, 240, 240]/255;
+
+ %% ROI analysis
+ if strcmp(analysis_type, 'ROI')
+
+ if strcmp(seed, 'FEF')
+ idxs = [idx_FEF, flip(ROIs.idx)];
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+ data(:,1) = data(1,:);
+ elseif strcmp(seed, 'IFJa')
+ idxs = [idx_IFJa, flip(ROIs.idx)];
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+ data(:,1) = data(1,:);
+ elseif strcmp(seed, 'IFJp')
+ idxs = [idx_IFJp, flip(ROIs.idx)];
+ data = tmp_mat(idxs, idxs);
+ data(isnan(data)) = 0;
+ data(:,1) = data(1,:);
+ end
+
+ label = results.label(idxs);
+
+ if flag.collapseTargets == true
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(3:end-6);
+ end
+ else
+ % labels
+ myLabel = cell(length(label));
+ for i = 1:length(label)
+ myLabel{i} = strrep(label{i},'_','-');
+ myLabel{i} = myLabel{i}(1:end-6);
+ end
+ end
+
+ % color
+ % https://sashamaps.net/docs/resources/20-colors/
+ myColorMap = repmat([1 1 1], length(idxs), 1);
+ if strcmp(seed, 'FEF')
+ myColorMap(1,:) = FEF_color;
+ elseif strcmp(seed, 'IFJa')
+ myColorMap(1,:) = IFJa_color;
+ elseif strcmp(seed, 'IFJp')
+ myColorMap(1,:) = IFJp_color;
+ end
+ end
+
+ %% Circular graph for all together
+ circularGraph(data', 'Colormap', myColorMap, 'Label', myLabel);
+ title('All Frequency Bands')
+ set(gcf, 'Position', get(0, 'Screensize'));
+
+ fg1 = gca;
+ fg2 = get(fg1, 'children');
+
+ for ii = 1:length(fg2)
+ try
+ tmp_fg = fg2(ii);
+ tmp_fg.FontSize = fontSize;
+ catch
+ fprintf('Almost ready...\n', i);
+ end
+ end
+
+ if flag.save_fig == true
+ name = [ seed '_circularGraph_' conn_metric '_' band_name '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf, [flag.dir_fig name '.png'], '-dpng', '-r300');
+ close all
+ end
+ end
+end
diff --git a/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage.m b/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage.m
new file mode 100644
index 0000000..642914c
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage.m
@@ -0,0 +1,639 @@
+function results = helper_functionConn_fsaverage(cimec)
+
+inputfile_conn = cimec.inputfile_conn;
+band_name = cimec.band_name;
+seed_target = cimec.seed_target;
+conn_metric = cimec.conn_metric;
+statistics = cimec.statistics;
+contrast = cimec.contrast;
+flag = cimec.flag;
+
+%%
+addpath(genpath(fullfile(fileparts(fileparts(pwd)), 'helper_fun')));
+
+statistics.contrast = contrast;
+statistics.stat = true;
+statistics.f_stats = @signrank;
+statistics.f_correction = @fdr_bh;
+
+ROIs.do = true; % fixed
+
+colorlim = true;
+
+%%
+% fsaverage
+inflated = true;
+if strcmp(statistics.analysis_type, 'exploratory')
+ smoothing = '70'; % percent
+else
+ smoothing = '100'; % percent
+end
+inputfile_fs = fullfile(load_path('inputfile_fs'), 'fsaverage.mat');
+inputfile_fs_inflated = fullfile(load_path('inputfile_fs'), sprintf('fsaverage_inflated_%s.mat', smoothing));
+
+% seed to target
+dorsal_R = { 'R_V6_ROI R', 'R_V6A_ROI R', 'R_V7_ROI R', 'R_IPS1_ROI R', 'R_IP1_ROI R', 'R_MIP_ROI R', ...
+ 'R_VIP_ROI R', 'R_LIPd_ROI R', 'R_LIPv_ROI R', 'R_7AL_ROI R', 'R_7PC_ROI R', 'R_7PL_ROI R', ...
+ 'R_V3A_ROI R', 'R_V3B_ROI R', 'R_V3CD_ROI R', 'R_LO3_ROI R', 'R_MT_ROI R'};
+ventral_R = {'R_V8_ROI R', 'R_VMV1_ROI R', 'R_VMV2_ROI R', 'R_VMV3_ROI R', 'R_PHT_ROI R', 'R_PH_ROI R', ...
+ 'R_TE1a_ROI R', 'R_TE1m_ROI R', 'R_TE1p_ROI R', 'R_TE2a_ROI R', 'R_TE2p_ROI R', ...
+ 'R_TF_ROI R', 'R_TGv_ROI R', 'R_FFC_ROI R', 'R_PIT_ROI R', 'R_VVC_ROI R'};
+
+dorsal_L = { 'L_V6_ROI L', 'L_V6A_ROI L', 'L_V7_ROI L', 'L_IPS1_ROI L', 'L_IP1_ROI L', 'L_MIP_ROI L', ...
+ 'L_VIP_ROI L', 'L_LIPd_ROI L', 'L_LIPv_ROI L', 'L_7AL_ROI L', 'L_7PC_ROI L', 'L_7PL_ROI L', ...
+ 'L_V3A_ROI L', 'L_V3B_ROI L', 'L_V3CD_ROI L', 'L_LO3_ROI L', 'L_MT_ROI L'};
+ventral_L = {'L_V8_ROI L', 'L_VMV1_ROI L', 'L_VMV2_ROI L', 'L_VMV3_ROI L', 'L_PHT_ROI L', 'L_PH_ROI L', ...
+ 'L_TE1a_ROI L', 'L_TE1m_ROI L', 'L_TE1p_ROI L', 'L_TE2a_ROI L', 'L_TE2p_ROI L', ...
+ 'L_TF_ROI L', 'L_TGv_ROI L', 'L_FFC_ROI L', 'L_PIT_ROI L', 'L_VVC_ROI L'};
+
+
+if strcmp(seed_target, 'right-right')
+ between = {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-3 & 2-3
+ ROIs.name = [dorsal_R ventral_R];
+elseif strcmp(seed_target, 'right-left')
+ between = {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-3 & 2-3
+ ROIs.name = [dorsal_L ventral_L];
+elseif strcmp(seed_target, 'left-left')
+ between = {'L_IFJa_ROI L', 'L_IFJp_ROI L', 'L_FEF_ROI L'}; % 1-3 & 2-3
+ ROIs.name = [dorsal_L ventral_L];
+elseif strcmp(seed_target, 'left-right')
+ between = {'L_IFJa_ROI L', 'L_IFJp_ROI L', 'L_FEF_ROI L'}; % 1-3 & 2-3
+ ROIs.name = [dorsal_R ventral_R];
+end
+
+
+
+%% Inputs
+cimec = struct;
+cimec.between = between;
+cimec.statistics = statistics;
+cimec.band_name = band_name;
+cimec.ROIs = ROIs;
+cimec.colorlim = colorlim;
+cimec.inputfile_conn = inputfile_conn;
+cimec.inputfile_fs = inputfile_fs;
+cimec.inflated = inflated;
+cimec.inputfile_fs_inflated = inputfile_fs_inflated;
+cimec.flag = flag;
+cimec.conn_metric = conn_metric;
+cimec.seed_target = seed_target;
+
+results = visualize_connectivity(cimec);
+
+%% Function
+ function results = visualize_connectivity(cimec)
+
+ %% Info about the data
+ inputfile_conn = cimec.inputfile_conn; % e.g. '...\HCP_Subjects\Outputs\connectivity_results\175237_connectivityResults__2s';
+ inputfile_fs = cimec.inputfile_fs; % e.g. '...\HCP_Subjects\Outputs\fsaverage_anatomy\175237_fsaverage';
+
+ contrast = cimec.statistics.contrast; % contrast map or not
+ between = cimec.between; % {'R_IFJa_ROI R', 'R_IFJp_ROI R', 'R_FEF_ROI R'}; % 1-2 & 1-3
+
+ stat = cimec.statistics.stat;
+ f_stats = cimec.statistics.f_stats; % e.g. @signrank
+ alpha = cimec.statistics.alpha; % e.g. 0.05
+ f_correction = cimec.statistics.f_correction; % correction method e.g. @fdr_bh
+ corrected = cimec.statistics.corrected; % e.g. true
+
+ ROIs = cimec.ROIs;
+
+ band_name = cimec.band_name; % e.g. 'alpha';
+ colorlim = cimec.colorlim; % e.g. true;
+
+ inflated = cimec.inflated; % e.g. true
+ inputfile_fs_inflated = cimec.inputfile_fs_inflated;
+
+ flag = cimec.flag;
+ conn_metric = cimec.conn_metric;
+ seed_target = cimec.seed_target;
+
+ %% Frequency bands
+ band_names = { 'delta' , 'theta' , 'alpha' , 'beta' , 'gamma' };
+ freq_bands = [ 1 4 ; 4 8 ; 8 13 ; 13 30 ; 30 100 ];
+
+ %% Load data
+ % avgFreq_icoh
+ load(inputfile_conn, 'group_results');
+ conn_results = group_results;
+
+ % fsaverage
+ load(inputfile_fs, 'fsaverage')
+
+ %% Prepare the anatomy
+ % Parcellation info (Brainstorm -> Fieldtrip)
+ tess_cortex_pial = fsaverage;
+
+ if inflated == true
+ fs_inflated = load(inputfile_fs_inflated);
+ tess_cortex_pial.Vertices = fs_inflated.Vertices;
+ tess_cortex_pial.Faces = fs_inflated.Faces;
+ end
+
+ Scouts = tess_cortex_pial.Atlas(end-1).Scouts;
+ Scouts_Vertices = {Scouts.Vertices}';
+ Scouts_Label = {Scouts.Label}';
+
+ parcellation = zeros(length([tess_cortex_pial.Vertices]), 1);
+ for idx = 1:length(Scouts_Vertices)
+ per_parcel = Scouts_Vertices{idx};
+
+ for ii = 1:length(per_parcel)
+ parcellation(per_parcel(ii)) = idx;
+ end
+ end
+
+ brainordinate.parcellation = parcellation;
+ brainordinate.parcellationlabel = Scouts_Label;
+ brainordinate.pos = tess_cortex_pial.Vertices;
+ brainordinate.tri = tess_cortex_pial.Faces;
+ brainordinate.brainstructure = tess_cortex_pial.SulciMap+1;
+ brainordinate.brainstructurelabel = {'CORTEX_LEFT', 'CORTEX_RIGHT'}';
+
+ %% Prepare the connectivity matrix
+
+ conn_mat = struct;
+ conn_mat.label = Scouts_Label;
+ conn_mat.band_names = band_name;
+ conn_mat.brainordinate = brainordinate;
+
+ idx_band = find(strcmp(band_names, band_name));
+ tmp_data = group_results(idx_band).data_perSubject;
+ tmp_data(isnan(tmp_data)) = 1;
+
+ %% seeds
+ idx_IFJa = find(strcmp(conn_mat.label, between{1}));
+ idx_IFJp = find(strcmp(conn_mat.label, between{2}));
+ idx_FEF = find(strcmp(conn_mat.label, between{3}));
+
+ IFJa(:, :) = tmp_data(idx_IFJa,:,:);
+ IFJp(:, :) = tmp_data(idx_IFJp,:,:);
+ FEF(:, :) = tmp_data(idx_FEF,:,:);
+
+ %% mean values for the statistical test for 'not contrast'
+ stat_against = squeeze(mean(mean(tmp_data)));
+
+ %% ROIs/exploratory
+ if strcmp(statistics.analysis_type, 'exploratory')
+ all_labels = conn_mat.label';
+ if or(strcmp(seed_target, 'right-left'), strcmp(seed_target, 'left-left'))
+ ROIs.name = all_labels(1:180);
+ elseif or(strcmp(seed_target, 'right-right'), strcmp(seed_target, 'left-right'))
+ ROIs.name = all_labels(181:360);
+ end
+ end
+
+ nROIs = length(ROIs.name);
+ for ii = 1:nROIs
+ ROIs.idx(ii) = find(strcmp(conn_mat.label, ROIs.name{ii}));
+ end
+
+ mask = zeros(360,1);
+ mask(ROIs.idx) = 1;
+
+ %% normality test
+ % stat_IFJa = IFJa;
+ % stat_IFJa(stat_IFJa(:,1)==1) = NaN;
+ % stat_FEF = FEF;
+ % stat_FEF(stat_FEF(:,1)==1) = NaN;
+ %
+ %
+ % for ii = 1:nROIs
+ % figure
+ % % histogram(atanh(stat_IFJa(ROIs.idx(ii),:)-stat_FEF(ROIs.idx(ii),:)));
+ % % histogram(stat_IFJa(ROIs.idx(ii),:)-stat_FEF(ROIs.idx(ii),:));
+ % % histogram(stat_IFJa(ROIs.idx(ii),:));
+ % histogram(atanh(stat_IFJa(ROIs.idx(ii),:)));
+ % end
+ %
+ % figure
+ % hist(atanh(stat_IFJa(ROIs.idx(33),:)-stat_FEF(ROIs.idx(33),:)));
+ % figure
+ % hist(stat_IFJa(ROIs.idx(33),:)-stat_FEF(ROIs.idx(33),:));
+
+
+ %%
+ if contrast == true
+ if stat == true
+
+ %% Inferential statistics
+ %% Wilcoxon signed rank test
+ % IFJa vs FEF
+ for ii = 1:nROIs
+ pair_1 = IFJa(ROIs.idx(ii),:)';
+ pair_2 = FEF(ROIs.idx(ii),:)';
+
+ [P, H, ~] = f_stats(pair_1, pair_2, 'Alpha', alpha, 'Tail', 'both');
+
+ H_Wilcoxon_IFJa(ii) = H;
+ P_Wilcoxon_IFJa(ii) = P;
+ end
+
+ % IFJp vs FEF
+ for ii = 1:nROIs
+ pair_1 = IFJp(ROIs.idx(ii),:)';
+ pair_2 = FEF(ROIs.idx(ii),:)';
+
+ [P, H, ~] = f_stats(pair_1, pair_2, 'Alpha', alpha, 'Tail', 'both');
+
+ H_Wilcoxon_IFJp(ii) = H;
+ P_Wilcoxon_IFJp(ii) = P;
+ end
+
+ %% FDR correction
+ if corrected == false
+ % clear NaNs
+ H_Wilcoxon_IFJa(isnan(H_Wilcoxon_IFJa)) = 0;
+ P_Wilcoxon_IFJa(isnan(P_Wilcoxon_IFJa)) = 0;
+ H_Wilcoxon_IFJp(isnan(H_Wilcoxon_IFJp)) = 0;
+ P_Wilcoxon_IFJp(isnan(P_Wilcoxon_IFJp)) = 0;
+
+ % z-score
+ % for two-tailed: abs(norminv(p/2));
+ Z_Wilcoxon_IFJa = abs(norminv(P_Wilcoxon_IFJa/2));
+ Z_Wilcoxon_IFJp = abs(norminv(P_Wilcoxon_IFJp/2));
+
+ group_IFJa_contrast = mean(FEF-IFJa, 2);
+ right_group_IFJa = group_IFJa_contrast(ROIs.idx);
+ right_group_IFJa(~H_Wilcoxon_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = Z_Wilcoxon_IFJa'.*sign(right_group_IFJa);
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_contrast = mean(FEF-IFJp, 2);
+ right_group_IFJp = group_IFJp_contrast(ROIs.idx);
+ right_group_IFJp(~H_Wilcoxon_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = Z_Wilcoxon_IFJp'.*sign(right_group_IFJp);
+ stats_IFJp = group_IFJp;
+
+ elseif corrected == true
+ % FDR correction
+ [h_adj_IFJa, ~, ~, p_adj_IFJa] = f_correction(P_Wilcoxon_IFJa(~isnan(P_Wilcoxon_IFJa)), alpha, 'pdep', 'yes');
+ [h_adj_IFJp, ~, ~, p_adj_IFJp] = f_correction(P_Wilcoxon_IFJp(~isnan(P_Wilcoxon_IFJp)), alpha, 'pdep', 'yes');
+
+ % z-score
+ % for two-tailed: abs(norminv(p/2));
+ z_adj_IFJa = abs(norminv(p_adj_IFJa/2));
+ z_adj_IFJp = abs(norminv(p_adj_IFJp/2));
+
+ % mask connectivity values
+ group_IFJa_contrast = mean(FEF-IFJa, 2);
+ right_group_IFJa = group_IFJa_contrast(ROIs.idx);
+ right_group_IFJa(~h_adj_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = z_adj_IFJa'.*sign(right_group_IFJa);
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_contrast = mean(FEF-IFJp, 2);
+ right_group_IFJp = group_IFJp_contrast(ROIs.idx);
+ right_group_IFJp(~h_adj_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = z_adj_IFJp'.*sign(right_group_IFJp);
+ stats_IFJp = group_IFJp;
+ end
+
+ %% Final matrix (360x360)
+ tmp_data = diag(ones(360,1));
+ tmp_data(idx_IFJa,:) = stats_IFJa;
+ tmp_data(idx_IFJp,:) = stats_IFJp;
+ tmp_data(:,idx_IFJa) = stats_IFJa';
+ tmp_data(:,idx_IFJp) = stats_IFJp';
+
+ else
+ tmp_data = diag(ones(360,1));
+ tmp_IFJa = mean(IFJa-FEF, 2);
+ tmp_IFJp = mean(IFJp-FEF, 2);
+
+ tmp_IFJa(~mask) = 0;
+ tmp_IFJp(~mask) = 0;
+
+ tmp_data(idx_IFJa,:) = tmp_IFJa;
+ tmp_data(idx_IFJp,:) = tmp_IFJp;
+ tmp_data(:,idx_IFJa) = tmp_IFJa';
+ tmp_data(:,idx_IFJp) = tmp_IFJp';
+ end
+
+ else % not a contrast map
+ if stat == true
+
+ %% Inferential statistics
+ %% Wilcoxon signed rank test
+ % IFJa
+ for ii = 1:nROIs
+ pair_1 = IFJa(ROIs.idx(ii),:)';
+
+ [P, H, ~] = f_stats(pair_1, stat_against, 'Alpha', alpha, 'Tail', 'right');
+
+ H_Wilcoxon_IFJa(ii) = H;
+ P_Wilcoxon_IFJa(ii) = P;
+ end
+ % IFJp
+ for ii = 1:nROIs
+ pair_1 = IFJp(ROIs.idx(ii),:)';
+
+ [P, H, ~] = f_stats(pair_1, stat_against, 'Alpha', alpha, 'Tail', 'right');
+
+ H_Wilcoxon_IFJp(ii) = H;
+ P_Wilcoxon_IFJp(ii) = P;
+ end
+ % FEF
+ for ii = 1:nROIs
+ pair_1 = FEF(ROIs.idx(ii),:)';
+
+ [P, H, ~] = f_stats(pair_1, stat_against, 'Alpha', alpha, 'Tail', 'right');
+
+ H_Wilcoxon_FEF(ii) = H;
+ P_Wilcoxon_FEF(ii) = P;
+ end
+ %% FDR correction
+ if corrected == false
+ % clear NaNs
+ H_Wilcoxon_IFJa(isnan(H_Wilcoxon_IFJa)) = 0;
+ H_Wilcoxon_IFJp(isnan(H_Wilcoxon_IFJp)) = 0;
+ H_Wilcoxon_FEF(isnan(H_Wilcoxon_FEF)) = 0;
+ P_Wilcoxon_IFJa(isnan(P_Wilcoxon_IFJa)) = 0;
+ P_Wilcoxon_IFJp(isnan(P_Wilcoxon_IFJp)) = 0;
+ P_Wilcoxon_FEF(isnan(P_Wilcoxon_FEF)) = 0;
+
+ % z-score
+ % for one-tailed: abs(norminv(p));
+ Z_Wilcoxon_IFJa = abs(norminv(P_Wilcoxon_IFJa));
+ Z_Wilcoxon_IFJp = abs(norminv(P_Wilcoxon_IFJp));
+ Z_Wilcoxon_FEF = abs(norminv(P_Wilcoxon_FEF));
+
+ % mask connectivity values
+ group_IFJa_notContrast = mean(IFJa, 2);
+ right_group_IFJa = group_IFJa_notContrast(ROIs.idx);
+ right_group_IFJa(~H_Wilcoxon_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = Z_Wilcoxon_IFJa'.*sign(right_group_IFJa);
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_notContrast = mean(IFJp, 2);
+ right_group_IFJp = group_IFJp_notContrast(ROIs.idx);
+ right_group_IFJp(~H_Wilcoxon_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = Z_Wilcoxon_IFJp'.*sign(right_group_IFJp);
+ stats_IFJp = group_IFJp;
+
+ group_FEF_notContrast = mean(FEF, 2);
+ right_group_FEF = group_FEF_notContrast(ROIs.idx);
+ right_group_FEF(~H_Wilcoxon_FEF) = 0;
+ group_FEF = zeros(360,1);
+ group_FEF(ROIs.idx) = Z_Wilcoxon_FEF'.*sign(right_group_FEF);
+ stats_FEF = group_FEF;
+
+ elseif corrected == true
+ % FDR correction
+ [h_adj_IFJa, ~, ~, p_adj_IFJa] = f_correction(P_Wilcoxon_IFJa(~isnan(P_Wilcoxon_IFJa)), alpha, 'pdep', 'yes');
+ [h_adj_IFJp, ~, ~, p_adj_IFJp] = f_correction(P_Wilcoxon_IFJp(~isnan(P_Wilcoxon_IFJp)), alpha, 'pdep', 'yes');
+ [h_adj_FEF, ~, ~, p_adj_FEF] = f_correction(P_Wilcoxon_FEF(~isnan(P_Wilcoxon_FEF)) , alpha, 'pdep', 'yes');
+
+ % z-score
+ % for one-tailed: abs(norminv(p));
+ z_adj_IFJa = abs(norminv(p_adj_IFJa));
+ z_adj_IFJp = abs(norminv(p_adj_IFJp));
+ z_adj_FEF = abs(norminv(p_adj_FEF));
+
+ % mask connectivity values
+ group_IFJa_notContrast = mean(IFJa, 2);
+ right_group_IFJa = group_IFJa_notContrast(ROIs.idx);
+ right_group_IFJa(~h_adj_IFJa) = 0;
+ group_IFJa = zeros(360,1);
+ group_IFJa(ROIs.idx) = z_adj_IFJa'.*sign(right_group_IFJa);
+ stats_IFJa = group_IFJa;
+
+ group_IFJp_notContrast = mean(IFJp, 2);
+ right_group_IFJp = group_IFJp_notContrast(ROIs.idx);
+ right_group_IFJp(~h_adj_IFJp) = 0;
+ group_IFJp = zeros(360,1);
+ group_IFJp(ROIs.idx) = z_adj_IFJp'.*sign(right_group_IFJp);
+ stats_IFJp = group_IFJp;
+
+ group_FEF_notContrast = mean(FEF, 2);
+ right_group_FEF = group_FEF_notContrast(ROIs.idx);
+ right_group_FEF(~h_adj_FEF) = 0;
+ group_FEF = zeros(360,1);
+ group_FEF(ROIs.idx) = z_adj_FEF'.*sign(right_group_FEF);
+ stats_FEF = group_FEF;
+ end
+
+ %% Final matrix (360x360)
+ tmp_data = zeros(360,360);
+ tmp_data(idx_IFJa,:) = stats_IFJa;
+ tmp_data(idx_IFJp,:) = stats_IFJp;
+ tmp_data(idx_FEF,:) = stats_FEF;
+ tmp_data(:,idx_IFJa) = stats_IFJa';
+ tmp_data(:,idx_IFJp) = stats_IFJp';
+ tmp_data(:,idx_FEF) = stats_FEF';
+
+ else
+ tmp_data = zeros(360,360);
+ tmp_IFJa = mean(IFJa, 2);
+ tmp_IFJp = mean(IFJp, 2);
+ tmp_FEF = mean(FEF, 2);
+
+ tmp_IFJa(~mask) = 0;
+ tmp_IFJp(~mask) = 0;
+ tmp_FEF(~mask) = 0;
+
+ tmp_data(idx_IFJa,:) = tmp_IFJa;
+ tmp_data(idx_IFJp,:) = tmp_IFJp;
+ tmp_data(idx_FEF,:) = tmp_FEF;
+ tmp_data(:,idx_IFJa) = tmp_IFJa';
+ tmp_data(:,idx_IFJp) = tmp_IFJp';
+ tmp_data(:,idx_FEF) = tmp_FEF';
+ end
+ end
+
+ conn_mat.cohspctrm = tmp_data;
+
+ % output
+ results.conn_matrix = tmp_data;
+ results.contrast = contrast;
+ results.helper.idx_IFJa = idx_IFJa;
+ results.helper.idx_IFJp = idx_IFJp;
+ results.helper.idx_FEF = idx_FEF;
+ results.helper.ROIs = ROIs;
+ results.helper.brainordinate = brainordinate;
+ results.label = conn_mat.label;
+ if exist('h_adj_IFJa','var'); results.stat.h_adj_IFJa = h_adj_IFJa; end
+ if exist('h_adj_IFJp','var'); results.stat.h_adj_IFJp = h_adj_IFJp; end
+ if exist('h_adj_FEF','var'); results.stat.h_adj_FEF = h_adj_FEF; end
+ results.stat.analysis_type = cimec.statistics.analysis_type;
+
+ results.perSubject.IFJa = IFJa;
+ results.perSubject.IFJp = IFJp;
+ results.perSubject.FEF = FEF;
+
+ results.cimec = cimec;
+
+ %% Visualize using the helper function
+ % for colormap scale
+ if contrast == false && stat == false
+ tmp_data(logical(eye(360))) = NaN;
+ tmp_data = tmp_data(idx_seed1,:);
+ minv = min(tmp_data);
+ maxv = max(tmp_data);
+ elseif contrast == true && stat == false
+ tmp_data(logical(eye(360))) = NaN;
+ tmp_data = tmp_data(idx_seed1,:);
+
+ tmp_data(tmp_data > 0.85) = NaN;
+ tmp_data(tmp_data < -0.85) = NaN;
+ tmp_minv = min(tmp_data);
+ tmp_maxv = max(tmp_data);
+
+ minv = -1*round((abs(tmp_minv) + tmp_maxv)/2, 3);
+ maxv = round((abs(tmp_minv) + tmp_maxv)/2, 3);
+ elseif contrast == true && stat == true
+ minv = -4;
+ maxv = 4;
+ elseif contrast == false && stat == true
+ minv = 0;
+ maxv = 6;
+ end
+ colorlim_value = [minv maxv];
+
+ if flag.fsaverage == true
+ % in order to run the function
+ conn_mat.brainordinate.pos = conn_mat.brainordinate.pos*1000;
+
+ % To make black the areas outside ROI
+ if and(contrast == true, strcmp(statistics.analysis_type, 'ROI'))
+ cbar = cmap_rbw;
+ n = size(cbar, 1);
+ up = cbar(1:n/2,:);
+ middle = [0.5 0.5 0.5];
+ down = cbar(n/2+1:n,:);
+ set(0, 'DefaultFigureColormap', [up;middle;down]);
+
+ conn_mat.cohspctrm(ROIs.idx(~h_adj_IFJa),idx_IFJa) = 0.04;
+ conn_mat.cohspctrm(ROIs.idx(~h_adj_IFJp),idx_IFJp) = 0.04;
+ conn_mat.cohspctrm(idx_IFJa,ROIs.idx(~h_adj_IFJa)) = 0.04;
+ conn_mat.cohspctrm(idx_IFJp,ROIs.idx(~h_adj_IFJp)) = 0.04;
+
+ elseif and(contrast == false, strcmp(statistics.analysis_type, 'ROI'))
+ cbar = hot;
+ base1 = [1 1 1];
+ base2 = [0.25 0.25 0.25];
+ set(0, 'DefaultFigureColormap', [base1; base2; cbar]);
+
+ conn_mat.cohspctrm(ROIs.idx(~h_adj_IFJa),idx_IFJa) = -0.06;
+ conn_mat.cohspctrm(ROIs.idx(~h_adj_IFJp),idx_IFJp) = -0.06;
+ conn_mat.cohspctrm(ROIs.idx(~h_adj_FEF),idx_FEF) = -0.06;
+ conn_mat.cohspctrm(idx_IFJa,ROIs.idx(~h_adj_IFJa)) = -0.06;
+ conn_mat.cohspctrm(idx_IFJp,ROIs.idx(~h_adj_IFJp)) = -0.06;
+ conn_mat.cohspctrm(idx_FEF,ROIs.idx(~h_adj_FEF)) = -0.06;
+
+ minv = -0.06;
+ maxv = 6;
+ colorlim_value = [minv maxv];
+ elseif contrast == false
+ set(0, 'DefaultFigureColormap', hot);
+ end
+
+ %% Save the figure
+ if flag.save_fig == true
+
+ if seed_target(1) == 'r'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJa_R = [52.5323 -69.3638 71.0650; 52.5323 69.4183 71.0650];
+ else
+ pos2d_IFJa_R = [49.7454 -69.6590 70.1540; 49.7454 69.1230 70.1540];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_R);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJp_R = [45.6139 -69.3638 76.8706 ; 45.6139 69.4183 76.8706];
+ else
+ pos2d_IFJp_R = [44.7673 -69.6590 76.5544 ; 44.7673 69.1230 76.5544];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_R);
+ helper_save_figure(cimec);
+ close all;
+
+ if contrast == false
+ seed = 'FEF';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_FEF_R = [25.8639 -69.3638 96.3111; 25.8639 69.4183 96.3111];
+ else
+ pos2d_FEF_R = [28.0551 -69.6590 101.8004 ; 28.0551 69.1230 101.8004];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_R);
+ helper_save_figure(cimec);
+ close all;
+ end
+
+ elseif seed_target(1) == 'l'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJa_L = [50.5105 69.4183 69.5634 ; 53.1465 -69.3638 68.2860];
+ else
+ pos2d_IFJa_L = [47.6119 69.1230 68.3761 ; 47.6119 -69.6590 68.3761];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_L);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_IFJp_L = [43.6193 69.4183 80.0619 ; 43.6193 -69.3638 80.0619];
+ else
+ pos2d_IFJp_L = [40.8559 69.1230 76.9099 ; 40.8559 -69.6590 76.9099];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_L);
+ helper_save_figure(cimec);
+ close all;
+
+ if contrast == false
+ seed = 'FEF';
+ cimec.seed = seed;
+ if strcmp(statistics.analysis_type, 'ROI')
+ pos2d_FEF_L = [30.9891 69.4183 105.2148 ; 34.2627 -69.3638 98.8225];
+ else
+ pos2d_FEF_L = [26.2772 69.1230 101.4449 ; 26.2772 -69.6590 101.4449];
+ end
+ tutorial_nwa_connectivityviewer_save_figures(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_L);
+ helper_save_figure(cimec);
+ close all;
+ end
+ end
+
+ %% Show the figure
+ elseif colorlim == true
+ tutorial_nwa_connectivityviewer(conn_mat, 'cohspctrm', colorlim_value, seed_target, flag.contours);
+ end
+ end
+
+ %% circularGraph
+ if flag.circular_graph == true
+
+ results.contrast = contrast;
+ results.helper.stat.analysis_type = cimec.statistics.analysis_type;
+ results.helper.stat.h_IFJa_all = h_adj_IFJa;
+ results.helper.stat.h_IFJp_all = h_adj_IFJp;
+ if exist('h_adj_FEF','var'); results.helper.stat.h_FEF_all = h_adj_FEF; end
+
+ fontSize = cimec.flag.font_size;
+ save_fig = cimec.flag.save_fig;
+ results.cimec = cimec;
+
+ flag.save_fig = save_fig;
+ flag.collapseTargets = false;
+ flag.contrast = contrast;
+ helper_functionConn_circularGraph(results, fontSize, flag);
+ end
+ end
+
+end
diff --git a/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage_freqCollapsed.m b/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage_freqCollapsed.m
new file mode 100644
index 0000000..d30c03d
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_functionConn_fsaverage_freqCollapsed.m
@@ -0,0 +1,211 @@
+function results = helper_functionConn_fsaverage_freqCollapsed(cimec)
+
+band_name = cimec.band_name;
+flag = cimec.flag;
+conn_metric = cimec.conn_metric;
+contrast = cimec.contrast;
+analysis_type = cimec.statistics.analysis_type;
+seed_target = cimec.seed_target;
+alpha_value = cimec.statistics.alpha;
+duration = cimec.flag.duration;
+correction = cimec.statistics.correction;
+corrected = cimec.statistics.corrected;
+
+%% All freq bands
+cimec.flag.circular_graph = false;
+cimec.flag.fsaverage = false;
+cimec.band_name = 'delta';
+delta = helper_functionConn_fsaverage(cimec);
+delta.conn_matrix(delta.conn_matrix == 1) = NaN;
+cimec.band_name = 'theta';
+theta = helper_functionConn_fsaverage(cimec);
+theta.conn_matrix(theta.conn_matrix == 1) = NaN;
+cimec.band_name = 'alpha';
+alpha = helper_functionConn_fsaverage(cimec);
+alpha.conn_matrix(alpha.conn_matrix == 1) = NaN;
+cimec.band_name = 'beta';
+beta = helper_functionConn_fsaverage(cimec);
+beta.conn_matrix(beta.conn_matrix == 1) = NaN;
+cimec.band_name = 'gamma';
+gamma = helper_functionConn_fsaverage(cimec);
+gamma.conn_matrix(gamma.conn_matrix == 1) = NaN;
+
+idx_IFJa = delta.helper.idx_IFJa;
+idx_IFJp = delta.helper.idx_IFJp;
+idx_FEF = delta.helper.idx_FEF;
+ROIs.idx = delta.helper.ROIs.idx;
+
+h_IFJa_all = delta.stat.h_adj_IFJa + theta.stat.h_adj_IFJa + alpha.stat.h_adj_IFJa + beta.stat.h_adj_IFJa + gamma.stat.h_adj_IFJa;
+h_IFJp_all = delta.stat.h_adj_IFJp + theta.stat.h_adj_IFJp + alpha.stat.h_adj_IFJp + beta.stat.h_adj_IFJp + gamma.stat.h_adj_IFJp;
+if contrast == false
+ h_FEF_all = delta.stat.h_adj_FEF + theta.stat.h_adj_FEF + alpha.stat.h_adj_FEF + beta.stat.h_adj_FEF + gamma.stat.h_adj_FEF;
+end
+
+
+conn_matrix = zeros(360,360);
+tmp_mat = (delta.conn_matrix + theta.conn_matrix + alpha.conn_matrix + beta.conn_matrix + gamma.conn_matrix);
+tmp_mat(idx_IFJa, ROIs.idx) = tmp_mat(idx_IFJa, ROIs.idx)./h_IFJa_all;
+tmp_mat(idx_IFJp, ROIs.idx) = tmp_mat(idx_IFJp, ROIs.idx)./h_IFJp_all;
+if contrast == false
+ tmp_mat(idx_FEF, ROIs.idx) = tmp_mat(idx_FEF, ROIs.idx)./h_FEF_all;
+end
+tmp_mat(isinf(tmp_mat)) = 0;
+tmp_mat(isnan(tmp_mat)) = 0;
+
+conn_matrix(:,idx_IFJa) = tmp_mat(idx_IFJa,:);
+conn_matrix(:,idx_IFJp) = tmp_mat(idx_IFJp,:);
+conn_matrix(idx_IFJa,:) = tmp_mat(idx_IFJa,:);
+conn_matrix(idx_IFJp,:) = tmp_mat(idx_IFJp,:);
+if contrast == false
+ conn_matrix(:,idx_FEF) = tmp_mat(idx_FEF,:);
+ conn_matrix(idx_FEF,:) = tmp_mat(idx_FEF,:);
+end
+conn_matrix(idx_IFJa, idx_IFJa) = 0;
+conn_matrix(idx_IFJp, idx_IFJp) = 0;
+conn_matrix(idx_FEF, idx_FEF) = 0;
+
+
+%% Visualize using the helper function
+if flag.fsaverage == true
+
+ allFreq.cohspctrm = conn_matrix;
+ allFreq.brainordinate = delta.helper.brainordinate;
+ % in order to run the function
+ allFreq.brainordinate.pos = allFreq.brainordinate.pos*1000;
+ if contrast == true
+ colorlim_value = [-4 4];
+ else
+ colorlim_value = [0 6];
+ end
+
+ %% To make black the areas outside ROI
+ if and(contrast == true, strcmp(analysis_type, 'ROI'))
+ cbar = cmap_rbw;
+ n = size(cbar, 1);
+ up = cbar(1:n/2,:);
+ middle = [0.5 0.5 0.5];
+ down = cbar(n/2+1:n,:);
+ set(0, 'DefaultFigureColormap', [up;middle;down]);
+
+ allFreq.cohspctrm(ROIs.idx(~h_IFJa_all),idx_IFJa) = 0.04;
+ allFreq.cohspctrm(ROIs.idx(~h_IFJp_all),idx_IFJp) = 0.04;
+ allFreq.cohspctrm(idx_IFJa,ROIs.idx(~h_IFJa_all)) = 0.04;
+ allFreq.cohspctrm(idx_IFJp,ROIs.idx(~h_IFJp_all)) = 0.04;
+
+ elseif and(contrast == false, strcmp(analysis_type, 'ROI'))
+ cbar = hot;
+ base1 = [1 1 1];
+ base2 = [0.25 0.25 0.25];
+ set(0, 'DefaultFigureColormap', [base1; base2; cbar]);
+
+ allFreq.cohspctrm(ROIs.idx(~h_IFJa_all),idx_IFJa) = -0.06;
+ allFreq.cohspctrm(ROIs.idx(~h_IFJp_all),idx_IFJp) = -0.06;
+ allFreq.cohspctrm(ROIs.idx(~h_FEF_all),idx_FEF) = -0.06;
+ allFreq.cohspctrm(idx_IFJa,ROIs.idx(~h_IFJa_all)) = -0.06;
+ allFreq.cohspctrm(idx_IFJp,ROIs.idx(~h_IFJp_all)) = -0.06;
+ allFreq.cohspctrm(idx_FEF,ROIs.idx(~h_FEF_all)) = -0.06;
+
+ minv = -0.06;
+ maxv = 6;
+ colorlim_value = [minv maxv];
+ elseif contrast == false
+ set(0, 'DefaultFigureColormap', hot);
+ end
+
+ %% save the figure
+ if flag.save_fig == true
+ cimec = struct;
+ cimec.conn_metric = conn_metric;
+ cimec.band_name = band_name;
+ cimec.seed_target = seed_target;
+ cimec.statistics.analysis_type = analysis_type;
+ cimec.statistics.alpha = alpha_value;
+ cimec.statistics.corrected = corrected;
+ cimec.statistics.correction = correction;
+ cimec.flag.duration = duration;
+ cimec.flag.dir_fig = flag.dir_fig;
+
+ if seed_target(1) == 'r'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ pos2d_IFJa_R = [52.5323 -69.3638 71.0650; 52.5323 69.4183 71.0650];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_R);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ pos2d_IFJp_R = [45.6139 -69.3638 76.8706 ; 45.6139 69.4183 76.8706];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_R);
+ helper_save_figure(cimec);
+ close all;
+
+ if contrast == false
+ seed = 'FEF';
+ cimec.seed = seed;
+ pos2d_FEF_R = [25.8639 -69.3638 96.3111; 25.8639 69.4183 96.3111];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_R);
+ helper_save_figure(cimec);
+ close all;
+ end
+
+ elseif seed_target(1) == 'l'
+ seed = 'IFJa';
+ cimec.seed = seed;
+ pos2d_IFJa_L = [50.5105 69.4183 69.5634 ; 53.1465 -69.3638 68.2860];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJa_L);
+ helper_save_figure(cimec);
+ close all;
+
+ seed = 'IFJp';
+ cimec.seed = seed;
+ pos2d_IFJp_L = [43.6193 69.4183 80.0619 ; 43.6193 -69.3638 80.0619];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_IFJp_L);
+ helper_save_figure(cimec);
+ close all;
+
+ if contrast == false
+ seed = 'FEF';
+ cimec.seed = seed;
+ pos2d_FEF_L = [30.9891 69.4183 105.2148 ; 34.2627 -69.3638 98.8225];
+ tutorial_nwa_connectivityviewer_save_figures(allFreq, 'cohspctrm', colorlim_value, seed_target, flag.contours, pos2d_FEF_L);
+ helper_save_figure(cimec);
+ close all;
+ end
+ end
+ else
+ tutorial_nwa_connectivityviewer(allFreq, 'cohspctrm', colorlim_value, cimec.seed_target, cimec.flag.contours);
+ end
+end
+
+results.conn_matrix = conn_matrix;
+results.contrast = contrast;
+results.label = delta.label;
+results.helper.brainordinate = delta.helper.brainordinate;
+results.helper.idx_FEF = delta.helper.idx_FEF;
+results.helper.idx_IFJa = delta.helper.idx_IFJa;
+results.helper.idx_IFJp = delta.helper.idx_IFJp;
+results.helper.ROIs = delta.helper.ROIs;
+results.stat.analysis_type = analysis_type;
+results.helper.band_name = band_name;
+results.stat.h_IFJa_all = h_IFJa_all;
+results.stat.h_IFJp_all = h_IFJp_all;
+if exist('h_FEF_all','var'); results.stat.h_FEF_all = h_FEF_all; end
+
+results.perSubject.IFJa = (delta.perSubject.IFJa + theta.perSubject.IFJa + alpha.perSubject.IFJa + beta.perSubject.IFJa + gamma.perSubject.IFJa)/5;
+results.perSubject.IFJp = (delta.perSubject.IFJp + theta.perSubject.IFJp + alpha.perSubject.IFJp + beta.perSubject.IFJp + gamma.perSubject.IFJp)/5;
+results.perSubject.FEF = (delta.perSubject.FEF + theta.perSubject.FEF + alpha.perSubject.FEF + beta.perSubject.FEF + gamma.perSubject.FEF)/5;
+
+cimec.band_name = band_name;
+results.cimec = cimec;
+
+%% circularGraph
+if flag.circular_graph == true
+ fontSize = flag.font_size;
+ flag.collapseTargets = false;
+ flag.contrast = contrast;
+
+ helper_functionConn_circularGraph(results, fontSize, flag);
+end
+
+end
diff --git a/Visualize_Results/scripts/helper_fun/helper_save_figure.m b/Visualize_Results/scripts/helper_fun/helper_save_figure.m
new file mode 100644
index 0000000..9136322
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_save_figure.m
@@ -0,0 +1,165 @@
+function helper_save_figure(cimec)
+%% 'target right hemisphere'
+
+conn_metric = cimec.conn_metric;
+band_name = cimec.band_name;
+seed = cimec.seed;
+seed_target = cimec.seed_target;
+analysis_type = cimec.statistics.analysis_type;
+alpha = char(string(cimec.statistics.alpha));
+correction = cimec.statistics.correction;
+flag = cimec.flag;
+duration = flag.duration;
+dir_fig = flag.dir_fig;
+
+if or(strcmp(seed_target, 'right-right'), strcmp(seed_target, 'left-right'))
+
+ try
+ if strcmp(flag.script, 'collapseTargets')
+ seed_target = char(string(join(flag.seed_targets)));
+ end
+ catch
+ fprintf('Almost ready...\n', i);
+ end
+
+ %% 0
+ view(270,360)
+ xlim([-100 100])
+ ylim([-100 0])
+ zlim([-20 150])
+ set(gcf, 'Position', get(0, 'Screensize'));
+
+ %% 1
+ % save the figure
+ lighting none
+ material dull
+ lighting phong
+ cam1 = camlight('left');
+
+ % for light
+ view(360,270)
+ cam2 = camlight('headlight');
+ view(360,360)
+ cam3 = camlight('left');
+
+ if strcmp(analysis_type, 'exploratory')
+ cam4 = camlight('right');
+
+ %% 1
+ number = '1';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 3
+ view(180,360)
+ cam3 =camlight('headlight');
+ number = '3';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+ else
+ %% 1
+ number = '1';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 2
+ view(315,5)
+ number = '2';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 3
+ view(180,360)
+ cam3 =camlight('headlight');
+ number = '3';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 4
+ if strcmp(conn_metric, 'pdc')
+ view(360,270)
+ number = '4';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+ end
+ end
+
+elseif or(strcmp(seed_target, 'right-left'), strcmp(seed_target, 'left-left'))
+
+ try
+ if strcmp(flag.script, 'collapseTargets')
+ seed_target = char(string(join(flag.seed_targets)));
+ end
+ catch
+ fprintf('Almost ready...\n', i);
+ end
+
+
+
+ %% RUN
+ %% 0
+ view(270,360)
+ xlim([-100 100])
+ ylim([0 100])
+ zlim([-20 150])
+ set(gcf, 'Position', get(0, 'Screensize'));
+
+ %% 1
+ % save the figure
+ lighting none
+ material dull
+ lighting phong
+ cam1 = camlight('right');
+
+ % for light
+ view(360,270)
+ cam2 = camlight('headlight');
+ view(180,360)
+ cam3 = camlight('right');
+
+ if strcmp(analysis_type, 'exploratory')
+ %% 1
+ cam4 = camlight('left');
+
+ number = '1';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 3
+ view(360,360)
+ cam3 =camlight('headlight');
+ number = '3';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ else
+ %% 1
+ number = '1';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 2
+ view(225,5)
+ number = '2';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 3
+ view(360,360)
+ cam3 =camlight('headlight');
+ number = '3';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+
+ %% 4
+ if strcmp(conn_metric, 'pdc')
+ view(360,270)
+ number = '4';
+ name = [number '_' conn_metric '_' band_name '_' seed '_' seed_target '_' analysis_type '_' alpha '_' correction '_' duration];
+ print(gcf,[dir_fig name '.png'],'-dpng','-r250');
+ end
+ end
+end
+
+end
+%%
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/helper_violinplot.m b/Visualize_Results/scripts/helper_fun/helper_violinplot.m
new file mode 100644
index 0000000..5bb02ce
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/helper_violinplot.m
@@ -0,0 +1,370 @@
+function helper_violinplot(outputs, conn_metric, band_name, seed_target, duration)
+
+%% Cite: https://github.com/bastibe/Violinplot-Matlab
+idx_FEF_R = 242;
+idx_IFJa_R = 251;
+idx_IFJp_R = 252;
+
+idx_FEF_L = 62;
+idx_IFJa_L = 71;
+idx_IFJp_L = 72;
+
+if strcmp(band_name, 'delta')
+ color = [240 50 230]/255;
+elseif strcmp(band_name, 'theta')
+ color = [255 225 25]/255;
+elseif strcmp(band_name, 'alpha')
+ color = [60 180 75]/255;
+elseif strcmp(band_name, 'beta')
+ color = [245 130 48]/255;
+elseif strcmp(band_name, 'gamma')
+ color = [128 128 128]/255;
+end
+
+if strcmp(band_name, 'gamma')
+ yvalues = [0 0.24];
+else
+ yvalues = [0 0.14];
+end
+
+%% 'right-right'
+if strcmp(seed_target, 'right-right')
+
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-FEF and R-IFJa'];
+ legend = {'R-FEF to R-IFJa' 'R-IFJa to R-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJa_R,:)'; seed_21(idx_IFJa_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-FEF and R-IFJp'];
+ legend = {'R-FEF to R-IFJp' 'R-IFJp to R-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_R,:)'; seed_21(idx_IFJp_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+ %%
+ seed_12 = outputs.perSubject.IFJa_12;
+ seed_21 = outputs.perSubject.IFJa_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-IFJa and R-IFJp'];
+ legend = {'R-IFJa to R-IFJp' 'R-IFJp to R-IFJa'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_R,:)'; seed_21(idx_IFJp_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+
+ %% 'left-left'
+elseif strcmp(seed_target, 'left-left')
+
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-FEF and L-IFJa'];
+ legend = {'L-FEF to L-IFJa' 'L-IFJa to L-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJa_L,:)'; seed_21(idx_IFJa_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-FEF and L-IFJp'];
+ legend = {'L-FEF to L-IFJp' 'L-IFJp to L-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_L,:)'; seed_21(idx_IFJp_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+ %%
+ seed_12 = outputs.perSubject.IFJa_12;
+ seed_21 = outputs.perSubject.IFJa_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-IFJa and L-IFJp'];
+ legend = {'L-IFJa to L-IFJp' 'L-IFJp to L-IFJa'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_L,:)'; seed_21(idx_IFJp_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+
+
+ %% 'right-left'
+elseif strcmp(seed_target, 'right-left')
+
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-FEF and L-IFJa'];
+ legend = {'R-FEF to L-IFJa' 'L-IFJa to R-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJa_L,:)'; seed_21(idx_IFJa_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-FEF and L-IFJp'];
+ legend = {'R-FEF to L-IFJp' 'L-IFJp to R-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_L,:)'; seed_21(idx_IFJp_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.IFJa_12;
+ seed_21 = outputs.perSubject.IFJa_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'R-IFJa and L-IFJp'];
+ legend = {'R-IFJa to L-IFJp' 'L-IFJp to R-IFJa'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_L,:)'; seed_21(idx_IFJp_L,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %% 'left-right'
+elseif strcmp(seed_target, 'left-right')
+
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-FEF and R-IFJa'];
+ legend = {'L-FEF to R-IFJa' 'R-IFJa to L-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJa_R,:)'; seed_21(idx_IFJa_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-FEF and R-IFJp'];
+ legend = {'L-FEF to R-IFJp' 'R-IFJp to L-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_R,:)'; seed_21(idx_IFJp_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+ %%
+ seed_12 = outputs.perSubject.IFJa_12;
+ seed_21 = outputs.perSubject.IFJa_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-IFJa and R-IFJp'];
+ legend = {'L-IFJa to R-IFJp' 'R-IFJp to L-IFJa'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_R,:)'; seed_21(idx_IFJp_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+ %% same regions L and R
+ %%
+ seed_12 = outputs.perSubject.FEF_12;
+ seed_21 = outputs.perSubject.FEF_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-FEF and R-FEF'];
+ legend = {'L-FEF to R-FEF' 'R-FEF to L-FEF'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_FEF_R,:)'; seed_21(idx_FEF_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+ %%
+ seed_12 = outputs.perSubject.IFJa_12;
+ seed_21 = outputs.perSubject.IFJa_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-IFJa and R-IFJa'];
+ legend = {'L-IFJa to R-IFJa' 'R-IFJa to L-IFJa'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJa_R,:)'; seed_21(idx_IFJa_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+ %%
+ seed_12 = outputs.perSubject.IFJp_12;
+ seed_21 = outputs.perSubject.IFJp_21;
+
+ name = [conn_metric '_' band_name '_' seed_target '_' duration '_' 'L-IFJp and R-IFJp'];
+ legend = {'L-IFJp to R-IFJp' 'R-IFJp to L-IFJp'};
+ labels = repmat(repmat(legend,55,1), 1, 1);
+ labels = labels(:);
+
+ values = [seed_12(idx_IFJp_R,:)'; seed_21(idx_IFJp_R,:)'];
+
+ figure; vs = violinplot(values, labels, 'ShowMean', true);
+
+ ylabel('Partial Directed Coherence'); ylim(yvalues);
+ title('Granger Causal Influences')
+ vs(1).ViolinColor = color;
+ vs(2).ViolinColor = color;
+
+ print(gcf,[load_path('save_fig') name '.png'],'-dpng','-r300');
+ close all;
+
+
+end
+
+
+end
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/load_path.m b/Visualize_Results/scripts/helper_fun/load_path.m
new file mode 100644
index 0000000..7e54ab6
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/load_path.m
@@ -0,0 +1,52 @@
+%% Please set the working directory first before running the scripts.
+
+function path = load_path(directory)
+
+workingDir = 'C:\Users\ASUS\Desktop\Thesis Project\';
+fieldTrip_dir = 'C:\Users\ASUS\Desktop\MATLAB\fieldtrip-20210411';
+save_fig = 'C:\Users\ASUS\Desktop\Thesis Project\Main Figures\';
+
+% restoredefaultpath % if needed
+addpath(fieldTrip_dir);
+ft_defaults
+
+if strcmp(directory, 'inputfile_fs')
+ path = fullfile(workingDir, 'Visualize results', 'fsaverage');
+elseif strcmp(directory, 'Outputs_Colclough')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_Colclough');
+elseif strcmp(directory, 'Outputs_2s_55subjs_icoh')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_icoh');
+elseif strcmp(directory, 'Outputs_2s_55subjs_wPLI')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_wPLI');
+elseif strcmp(directory, 'Outputs_2s_55subjs_dwPLI')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_dwPLI');
+elseif strcmp(directory, 'Outputs_2s_55subjs_powcorrOrtho')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_powcorrOrtho');
+elseif strcmp(directory, 'Outputs_2s_55subjs_granger')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_granger');
+elseif strcmp(directory, 'Outputs_2s_55subjs_pdc')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_2s_55subjs_pdc');
+
+elseif strcmp(directory, 'Outputs_5s_55subjs_icoh')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_5s_55subjs_icoh');
+elseif strcmp(directory, 'Outputs_5s_55subjs_wPLI')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_5s_55subjs_wPLI');
+elseif strcmp(directory, 'Outputs_5s_55subjs_powcorrOrtho')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_5s_55subjs_powcorrOrtho');
+
+elseif strcmp(directory, 'Outputs_10s_55subjs_icoh')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_10s_55subjs_icoh');
+elseif strcmp(directory, 'Outputs_10s_55subjs_powcorrOrtho')
+ path = fullfile(workingDir, 'Visualize results', 'results', 'Outputs_10s_55subjs_powcorrOrtho');
+
+elseif strcmp(directory, 'workingDir')
+ path = workingDir;
+elseif strcmp(directory, 'helper_fun')
+ path = fullfile(workingDir, 'Visualize results', 'scripts', 'helper_fun');
+elseif strcmp(directory, 'save_fig')
+ path = save_fig;
+
+
+end
+
+
\ No newline at end of file
diff --git a/Visualize_Results/scripts/helper_fun/tutorial_nwa_connectivityviewer.m b/Visualize_Results/scripts/helper_fun/tutorial_nwa_connectivityviewer.m
new file mode 100644
index 0000000..0466dfd
--- /dev/null
+++ b/Visualize_Results/scripts/helper_fun/tutorial_nwa_connectivityviewer.m
@@ -0,0 +1,325 @@
+function tutorial_nwa_connectivityviewer(data, param, colorlim, seed_target, flag)
+
+if nargin<2,
+ param = 'cohspctrm';
+end
+if nargin<3,
+ tmp = data.(param);
+ if all(tmp(:)>=0),
+ colorlim = [0 max(tmp(:))];
+ else
+ colorlim = [-1 1].*max(abs(tmp(:)));
+ end
+end
+
+if isfield(data, 'brainordinate') && ~isfield(data, 'pos')
+ % this seems to be parcellated data, 'unparcellate' on the fly
+ tmpdat = data.(param);
+ data = data.brainordinate;
+ atlas = data;
+
+ dat = zeros(size(data.pos,1));
+ for k = 1:numel(data.parcellationlabel)
+ for m = 1:numel(data.parcellationlabel)
+ dat(data.parcellation==k,data.parcellation==m) = tmpdat(k,m);
+ end
+ end
+else
+ dat = data.(param);
+ atlas = [];
+end
+
+% create sphere for location highlighting
+[x,y,z] = sphere(10);
+
+figure; hold on;
+ft_plot_mesh(data,'vertexcolor', mean(dat,2))
+h1 = gca;
+h2 = get(h1, 'children');
+if flag == false
+ h2.EdgeColor = [0.65,0.65,0.65]; %[0.80,0.80,0.80];%[0.94,0.94,0.94];
+ h2.LineStyle = ':';
+end
+h3 = surf(h1, 2*x,2*y,2*z+100, 'facecolor', 'w', 'edgecolor', 'none');
+
+% % Orhan:
+% change the view angle
+if seed_target(1) == 'r'
+ view(360,0)
+elseif seed_target(1) == 'l'
+ view(180,0)
+end
+
+set(gcf,'windowbuttondownfcn',{@fancyplotting, [h1 h2 h3], data.pos, data.tri, dat, atlas, seed_target, flag})
+% Orhan:
+cbar = colorbar;
+cbar.FontSize = 14;
+set(cbar.XLabel,{'String','Rotation','Position','FontWeight'},{'Z',0,[0.5 colorlim(1)-0.1],'bold'})
+
+caxis(colorlim);
+
+function fancyplotting(hObject, ~, axh, pos, tri, dat, atlas, seed_target, flag)
+
+% get the clicked position in axis coordinates
+pos2d = get(axh(1),'CurrentPoint');
+
+% Orhan: Delete later
+% nn = 0;
+% if mod(nn,2) == 0
+% pos2d = [ 53.9546 -69.3638 74.6208 ; 53.9546 69.4183 74.6208];
+% nn = nn+1;
+% else
+% pos2d = [51.6434 -52.0650 132.1000 ; 51.6434 -52.0650 -6.6821];
+% nn = nn+1;
+% end
+
+% get the intersection with the mesh
+[ipos, d] = intersect_line(pos, tri, pos2d(1,:), pos2d(2,:));
+[md, ix] = min(abs(d));
+
+% get the closest mesh point, and the corresponding index
+dpos = pos - ipos(ix*ones(size(pos,1),1),:);
+indx = nearest(sum(dpos.^2,2),0);
+
+x = get(axh(3),'xdata');
+x = x-mean(x(:));
+y = get(axh(3),'ydata');
+y = y-mean(y(:));
+z = get(axh(3),'zdata');
+z = z-mean(z(:));
+
+set(axh(3),'xdata', x+pos(indx,1));
+set(axh(3),'ydata', y+pos(indx,2));
+set(axh(3),'zdata', z+pos(indx,3));
+
+% update the functional data
+set(axh(2), 'facevertexcdata', dat(:, indx));
+
+% Orhan: Not used anymore, but keep it for later
+% for i = 1:numel(atlas.parcellationlabel)
+% scout_idx = (atlas.parcellation == i);
+% P = atlas.pos(scout_idx,:);
+% k = boundary(P);
+% hold on;
+% trisurf(k,P(:,1),P(:,2),P(:,3),'Facecolor','black','FaceAlpha', 0.1,'EdgeColor', 'none')
+% end
+
+% Orhan: Only for ROIs' contours; you need add 'ROI_idx' parameter to func
+% for i = 1:length(ROI_idx)
+% scout_idx = (atlas.parcellation == ROI_idx(i));
+% ft_plot_mesh(atlas, 'vertexcolor', dat(:, indx), 'contour', scout_idx, 'contourcolor', 'k', 'contourlinewidth', 0.5);
+% end
+
+% % Orhan: for contour of the parcels
+if flag == true
+ if or(strcmp(seed_target, 'right-right'), strcmp(seed_target, 'left-right'))
+ for i = 1:180
+ mask = atlas.parcellation == i+180;
+ scout_idx{i,:} = double(mask);
+ end
+ ft_plot_mesh(atlas, 'vertexcolor', dat(:, indx), 'contour', scout_idx, 'contourcolor', [185, 185, 185]/255, 'contourlinewidth', 0.5);
+ else
+ for i = 1:180
+ mask = atlas.parcellation == i;
+ scout_idx{i,:} = double(mask);
+ end
+ ft_plot_mesh(atlas, 'vertexcolor', dat(:, indx), 'contour', scout_idx, 'contourcolor', [185, 185, 185]/255, 'contourlinewidth', 0.5);
+ end
+end
+
+if isempty(atlas)
+ fprintf('you clicked on position %d with coordinates %3.2f %3.2f %3.2f\n', [indx pos(indx,:)]);
+else
+ fprintf('you clicked on parcel %s\n', atlas.parcellationlabel{atlas.parcellation(indx)});
+ title(atlas.parcellationlabel{atlas.parcellation(indx)}, 'Interpreter', 'none');
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% the code below is copied from fieldtrip/private
+
+function [points, pos, indx] = intersect_line(pnt, tri, pnt1, pnt2)
+
+% INTERSECT_LINE finds the intersection points between a mesh and a line.
+%
+% Use as:
+% [points, pos, indx] = intersect_line(pnt, tri, pnt1, pnt2)
+%
+% Where pnt (Nx3) and tri (Mx3) define the mesh, and pnt1 (1x3) and pnt2
+% (1x3) define the line. The output argument points (Px3) are the
+% intersection points, pos (Px1) the location on the line (relative to
+% pnt1) and indx is the index to the triangles of the mesh that are
+% intersected.
+%
+% This code is based from a function from the geom3d toolbox, that can be
+% found on matlab's file exchange. The original help is pasted below. The
+% original function was released under the BSD-license.
+%
+% Adapted to FieldTrip by Jan-Mathijs Schoffelen 2012
+
+%INTERSECTLINEMESH3D Intersection points of a 3D line with a mesh
+%
+% INTERS = intersectLineMesh3d(LINE, VERTICES, FACES)
+% Compute the intersection points between a 3D line and a 3D mesh defined
+% by vertices and faces.
+%
+% [INTERS POS INDS] = intersectLineMesh3d(LINE, VERTICES, FACES)
+% Also returns the position of each intersection point on the input line,
+% and the index of the intersected faces.
+% If POS > 0, the point is also on the ray corresponding to the line.
+%
+% Example
+% intersectLineMesh3d
+%
+% See also
+% meshes3d, triangulateFaces
+%
+% ------
+% Author: David Legland
+% e-mail: david.legland@grignon.inra.fr
+% Created: 2011-12-20, using Matlab 7.9.0.529 (R2009b)
+% Copyright 2011 INRA - Cepia Software Platform.
+
+
+tol = 1e-12;
+
+ntri = size(tri,1);
+
+% normals to the triangles
+n = normals(pnt, tri, 'triangle');
+
+% vectors describing the edges
+t0 = pnt(tri(:,1),:);
+u = pnt(tri(:,2),:) - t0;
+v = pnt(tri(:,3),:) - t0;
+
+% get the direction of the line
+d = pnt2 - pnt1;
+d = d/norm(d);
+
+% vector between triangle origin and line origin
+w0 = pnt1(ones(ntri,1),:) - t0;
+
+a = -sum(n.*w0, 2);
+b = n*d';
+
+valid = abs(b)>tol & sqrt(sum(n.^2,2))>tol;
+
+% compute intersection point of line with supporting plane
+% If pos < 0: point before ray
+% IF pos > |dir|: point after edge
+pos = a ./ b;
+
+% coordinates of intersection point
+points = pnt1(ones(ntri,1),:) + pos*d;
+
+% normalize direction vectors of triangle edges
+uu = sum(u.^2, 2);
+uv = sum(u.*v, 2);
+vv = sum(v.^2, 2);
+
+% coordinates of vector v in triangle basis
+w = points - t0;
+wu = sum(w.*u, 2);
+wv = sum(w.*v, 2);
+
+% normalization constant
+D = uv.^2 - uu .* vv;
+
+% test first coordinate
+s = (uv .* wv - vv .* wu) ./ D;
+ind1 = s < 0.0 | s > 1.0;
+points(ind1, :) = NaN;
+pos(ind1) = NaN;
+
+% test second coordinate, and third triangle edge
+t = (uv .* wu - uu .* wv) ./ D;
+ind2 = t < 0.0 | (s + t) > 1.0;
+points(ind2, :) = NaN;
+pos(ind2) = NaN;
+
+% keep only interesting points
+inds = ~ind1 & ~ind2 & valid;
+points = points(inds, :);
+
+pos = pos(inds);
+indx = find(inds);
+
+function [nrm] = normals(pnt, tri, opt)
+
+% NORMALS compute the surface normals of a triangular mesh
+% for each triangle or for each vertex
+%
+% [nrm] = normals(pnt, tri, opt)
+% where opt is either 'vertex' or 'triangle'
+
+% Copyright (C) 2002-2007, Robert Oostenveld
+%
+% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
+% for the documentation and details.
+%
+% FieldTrip 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.
+%
+% FieldTrip 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 FieldTrip. If not, see