Skip to content

Commit

Permalink
Merge pull request #91 from nguyen-td/feature
Browse files Browse the repository at this point in the history
Feature
  • Loading branch information
nguyen-td authored Apr 3, 2024
2 parents e62fa83 + feca9e4 commit d0d6156
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
33 changes: 23 additions & 10 deletions pop_roi_connect.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,28 @@

rowg = [0.1 0.6 1 0.2];
% uigeom = { 1 1 rowg rowg 1 rowg rowg [0.1 0.6 0.9 0.3] 1 rowg 1 [0.5 1 0.35 0.5] [0.5 1 0.35 0.5] [0.5 1 0.35 0.5] [1] [0.9 1.2 1] };
uigeom = { [1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1] [0.2 1 0.35 0.8] [0.2 1 0.35 0.8] };
uigeom = { [1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1.2 1] [1] [0.2 1 0.35 0.8] [0.2 1 0.35 0.8] [0.2 1 0.35 0.8] [0.2 1 0.35 0.8]};
uilist = { { 'style' 'text' 'string' 'Select connectivity measures' 'fontweight' 'bold' } ...
{ 'style' 'checkbox' 'string' 'Cross-spectrum' 'tag' 'cs' 'value' 1 } {} ...
{'style' 'checkbox' 'string' '(Complex-valued) Coherency' 'tag' 'ccoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Coherence' 'tag' 'acoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Imaginary Coherency' 'tag' 'icoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Weighted Phase Lag Index' 'tag' 'wpli' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Cross-spectrum (CS)' 'tag' 'cs' 'value' 1 } {} ...
{'style' 'checkbox' 'string' '(Complex-valued) Coherency (cCOH)' 'tag' 'ccoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Coherence (aCOH)' 'tag' 'acoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Imaginary Coherency (iCOH)' 'tag' 'icoh' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Weighted Phase Lag Index (wPLI)' 'tag' 'wpli' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Granger Causality (GC)' 'tag' 'gc' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Time-reversed GC' 'tag' 'trgc' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Partial Directed Coherence (PDC)' 'tag' 'pdc' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Time-reversed PDC' 'tag' 'trpdc' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Directed Transfer Entropy (DTF)' 'tag' 'dtf' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Time-reversed DTF' 'tag' 'trdtf' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Multivariate Interaction Measure' 'tag' 'mim' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Maximized Imaginary Coherency' 'tag' 'mic' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Multivariate Interaction Measure (MIM)' 'tag' 'mim' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Maximized Imaginary Coherency (MIC)' 'tag' 'mic' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Phase-Amplitude Coupling (PAC)' 'tag' 'pac' 'value' 0 } ...
{ 'style' 'checkbox' 'string' 'Time Delay Estimation (TDE)' 'tag' 'tde' 'value' 0 } ...
{} ...
{} { 'style' 'text' 'string' 'Autoregressive model order' } { 'style' 'edit' 'string' '20' 'tag' 'morder' } {} ...
{} { 'style' 'text' 'string' 'Bootstrap if any (n)' } { 'style' 'edit' 'string' '' 'tag' 'naccu2' } {} };
{} { 'style' 'text' 'string' 'Bootstrap if any (n)' } { 'style' 'edit' 'string' '' 'tag' 'naccu2' } {} ...
{} { 'style' 'text' 'string' 'Frequency combination in Hz (for PAC) [f1 f2]' } { 'style' 'edit' 'string' '' 'tag' 'fcomb' } {} ...
{} { 'style' 'text' 'string' 'Region selection by index (for TDE) [region1 region2]' } { 'style' 'edit' 'string' '' 'tag' 'tde_regions' } {} };
...
[result,~,~,out] = inputgui('geometry', uigeom, 'uilist', uilist, 'helpcom', 'pophelp(''pop_roi_connect'')', 'title', 'pop_roiconnect - connectivity');
if isempty(result), return, end
Expand All @@ -163,10 +167,19 @@
if out.trdtf, methods = [ methods { 'TRDTF' } ]; end
if out.mim , methods = [ methods { 'MIM' } ]; end
if out.mic, methods = [ methods { 'MIC' } ]; end
if out.pac, methods = [ methods { 'PAC' } ]; end
if out.tde, methods = [ methods { 'TDE' } ]; end
options = { ...
'morder' str2num(out.morder) ...
'naccu' str2num(out.naccu2) ...
'methods' methods };
'methods' methods ...
'tde_regions' eval( [ '[' out.tde_regions ']' ] )};
if ~isempty(eval( [ '[' out.fcomb ']' ] ))
out_fcomb = eval( [ '[' out.fcomb ']' ] );
fcomb.low = out_fcomb(1);
fcomb.high = out_fcomb(2);
options = [options {'fcomb' fcomb}];
end
else
options = varargin;
end
Expand Down
30 changes: 16 additions & 14 deletions pop_roi_connectplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
splot(end ).unit = 'aCOH';
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -169,7 +169,7 @@
splot(end ).unit = 'cCOH';
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -180,7 +180,7 @@
splot(end ).unit = 'iCOH';
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -191,7 +191,7 @@
splot(end ).unit = 'GC';
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -202,7 +202,7 @@
splot(end ).unit = 'TRGC'; % not used yet
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -213,7 +213,7 @@
splot(end ).unit = 'MIC'; % not used yet
splot(end ).cortex = cortexFlag;
splot(end ).matrix = -1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -224,7 +224,7 @@
splot(end ).unit = 'MIM'; % not used yet
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -235,18 +235,18 @@
splot(end ).unit = 'PAC'; % not used yet
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

if isfield(EEG.roi, 'PAC')
splot(end+1).label = 'ROI to ROI Phase-amplitude coupling';
splot(end+1).label = 'ROI to ROI Phase-amplitude coupling (antisymmetrized)';
splot(end ).labelshort = 'Phase-amplitude coupling';
splot(end ).acronym = 'PAC_anti'; % PAC based on antisymmetrized bicoherence
splot(end ).unit = 'PAC'; % not used yet
splot(end ).cortex = cortexFlag;
splot(end ).matrix = 1;
splot(end ).psd = 0;
splot(end ).psd = -1;
splot(end ).plot3d = plot3dFlag;
end

Expand All @@ -262,7 +262,7 @@
end

if isfield(EEG.roi, 'TDE')
splot(end+1).label = 'ROI to ROI Time-delay estimation';
splot(end+1).label = 'ROI to ROI Time-delay estimation (antisymmetrized)';
splot(end ).labelshort = 'Time-delay estimation';
splot(end ).acronym = 'TDE_anti'; % TDE based on antisymmetrized bispectrum
splot(end ).unit = 'TDE'; % not used yet
Expand Down Expand Up @@ -508,6 +508,7 @@
error('PAC (original bicoherence) cannot be plotted, field is missing.')
end
cortexPlot = mean(matrix, 2);
titleStr = sprintf('f1 = %1.1f Hz, f2 = %1.1f Hz', S.PAC.fcomb.low, S.PAC.fcomb.high);

case {'pac_anti'}
if isfield(S.PAC, 'b_anti_norm')
Expand All @@ -518,6 +519,7 @@
error('PAC (antisymmetrized bicoherence) cannot be plotted, field is missing.')
end
cortexPlot = mean(matrix, 2);
titleStr = sprintf('f1 = %1.1f Hz, f2 = %1.1f Hz', S.PAC.fcomb.low, S.PAC.fcomb.high);

case {'tde' 'tde_anti'}
if strcmpi(g.measure, 'tde')
Expand Down Expand Up @@ -591,7 +593,7 @@
warning('Butterfly plots (frequency x connectivity) cannot be computed for PAC because frequencies have already been specified for the computation.')
else
figure; plot(EEG.roi.freqs, butterflyplot, 'LineWidth', 1)
h = title([ 'ROI to ROI ' replace_underscores(g.measure) ' (' titleStr ')' ]);
h = title([ 'ROI to ROI ' replace_underscores(g.measure)]);
set(h, 'fontsize', 16);
xlabel('Frequency (Hz)')
ylabel([replace_underscores(g.measure) ' (a.u.)'])
Expand Down Expand Up @@ -970,8 +972,8 @@ function plot_tde(T, shift, region_X, region_Y, method)
[~, peak_idx] = max(T);
est_delay = shift(peak_idx); % in Hz

figure; plot(shift, T, 'LineWidth', 1)
xline(est_delay, '--r')
figure; plot(shift, T, 'black', 'LineWidth', 1)
xline(est_delay, '--r', 'LineWidth', 1)
xlabel('Time (s)')
ylabel('a.u.')
h = title(sprintf('%s -> %s TDE | Method %d', region_X, region_Y, method));
Expand Down
1 change: 1 addition & 0 deletions roi_pac.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
[b_orig, b_anti, b_orig_norm, b_anti_norm] = data2bs_pac(data, params);

% options which bispectral tensors to store
EEG.roi.PAC.fcomb = fcomb;
switch bs_outopts
case 2
EEG.roi.PAC.b_orig = b_orig;
Expand Down

0 comments on commit d0d6156

Please sign in to comment.