Importing wpli results computed outside Brainstorm

Hello,

I am presenting this paper Friday, and would like to present some additional figure not present in the original article. The author shared their connectivity map estimated using wPLI. https://figshare.com/s/a3f3f7c95d60cb48c295?file=47381569

I am able to visualize the connectivity matrix in matlab:

How can i import this in Brainstorm ?

i know the connectivity matrix (ROi x ROI) is stored in R = sData.new_results.eeg.noIED.beta.wpli; and that the labels for the ROI are in sData.new_results.eeg.labels

Summary

i tried this, but the file cant be displayed in Brainstorm:

FileMat = db_template('timefreqmat');
FileMat.Atlas = db_template('atlas');
FileMat.Atlas.Name = 'Desikan-Killiany';
% Reshape: [nA x nB x nTime x nFreq] => [nA*nB x nTime x nFreq]
FileMat.TF = process_compress_sym('Compress', sData.new_results.eeg.noIED.beta.wpli(:));

FileMat.DisplayUnits = 'Weighted phase lag index';
FileMat.Comment      = 'wppli - beta';
FileMat.RefRowNames  = sData.new_results.eeg.labels;
FileMat.RowNames     = sData.new_results.eeg.labels;
FileMat.DataType     = 'data';
FileMat.Method       = 'corr';
FileMat.DataFile     = [];
FileMat.nAvg         = 1;

Update 1:

Summary

with the following code, i can see the matrix in Brainstorm:

sSubject    = bst_get('Subject', 'Subject01');
sCortex     = in_tess_bst(sSubject.Surface(sSubject.iCortex).FileName);
Atlas       = sCortex.Atlas(strcmp({sCortex.Atlas.Name}, 'Desikan-Killiany'));

FileMat = db_template('timefreqmat');
FileMat.Atlas = db_template('atlas');
FileMat.Atlas.Name = 'Desikan-Killiany';
% Reshape: [nA x nB x nTime x nFreq] => [nA*nB x nTime x nFreq]
FileMat.TF =  process_compress_sym('Compress', sData.new_results.eeg.noIED.beta.wpli(:)); 
FileMat.DisplayUnits = 'Weighted phase lag index';
FileMat.Comment      = 'wppli - beta';
FileMat.RefRowNames  = sData.new_results.eeg.labels;
FileMat.RowNames     = sData.new_results.eeg.labels;
FileMat.DataType     = 'data';
FileMat.Method       = 'corr';
FileMat.DataFile     = [];
FileMat.nAvg         = 1;
FileMat.Time     = [1];
FileMat.ProcessName     = '';
FileMat.Options = bst_connectivity();

But i cant visualize the graph:

Unable to perform assignment because the left and right sides have a different number of elements.

Error in figure_connect>LoadFigurePlot (line 1223)
                SelChan(iRow) = find(strcmpi({GlobalData.DataSet(iDS).Channel.Name}, RowNames{iRow}));

Error in figure_connect (line 29)
eval(macro_method);

Error in view_connect (line 284)
figure_connect('LoadFigurePlot', hFig);

Error in tree_callbacks>@(h,ev)view_connect(filenameRelative,'GraphFull') (line 2078)
                            gui_component('MenuItem', jPopup, [], 'Display as graph [NxN]',   IconLoader.ICON_CONNECTN, [], @(h,ev)view_connect(filenameRelative, 'GraphFull'));
 

Update 2: The followinf code is working:

FileMat = db_template('timefreqmat');
FileMat.Atlas = db_template('atlas');
FileMat.Atlas.Scouts =repmat(db_template('scout'), 1, 72);
ColorTable = panel_scout('GetScoutsColorTable');
for i = 1:72
    FileMat.Atlas.Scouts(i).Label = sData.new_results.eeg.labels(i);
    iColor = mod(i-1, length(ColorTable)) + 1;
    FileMat.Atlas.Scouts(i).Color =  ColorTable(iColor,:);
end

FileMat.Atlas.Name = 'Desikan-Killiany';
% Reshape: [nA x nB x nTime x nFreq] => [nA*nB x nTime x nFreq]
FileMat.TF =  process_compress_sym('Compress', sData.new_results.eeg.noIED.beta.wpli(:)); 
FileMat.DisplayUnits = 'Weighted phase lag index';
FileMat.Comment      = 'wppli - beta';
FileMat.RefRowNames  = sData.new_results.eeg.labels;
FileMat.RowNames     = sData.new_results.eeg.labels;
FileMat.DataType     = 'results';
FileMat.Method       = 'corr';
FileMat.DataFile     = [];
FileMat.nAvg         = 1;
FileMat.Time     = [1];
FileMat.ProcessName     = '';
FileMat.Options = bst_connectivity();

Is there a way to have the region nicely organized ? (eg, left vs right and lobes..)

Thanks a lot

Edouard

Additional question, is there a reason the display are so different from the matrix / graph perspective ?

Both are done using, non-absolute avlue, [-max, max] but the graph seems to suggest both decrease and increase when the matrix show mainly only an increase.

Yes, with the field Region for each of the Scouts. This Region field is char vector comprised as [HEMISPHERE][LOBE]

HEMISPHERE can be L or R, for left and right respectively.

LOBE can be PF, F, C, T, P, O, L for PreFrontal, Frontal, Central, Temporal, Parietal, Occipital and Limbic receptively.

1 Like

Are both plots using the same maximum? either Global or local

@edelaire, did you figure out the difference in the plots?
If not, can you share the connectivity file? To check on our side

You can download the file from: https://figshare.com/ndownloader/files/47381551?private_link=a3f3f7c95d60cb48c295

you can then run:

sub_id = 01;

sData       = load(sprintf('26153071/sub-%02d_connectivity.mat', sub_id));
iStudy      = db_add_condition('Subject01', sprintf('Subject-%d',sub_id));
sSubject    = bst_get('Subject', 'Subject01');


FileMat = db_template('timefreqmat');
FileMat.Atlas = db_template('atlas');
FileMat.Atlas.Name = 'Desikan-Killiany';
FileMat.Atlas.Scouts =repmat(db_template('scout'), 1, 72);
ColorTable = panel_scout('GetScoutsColorTable');
for i = 1:72
    FileMat.Atlas.Scouts(i).Label = sData.new_results.eeg.labels(i);
    iColor = mod(i-1, length(ColorTable)) + 1;
    FileMat.Atlas.Scouts(i).Color =  ColorTable(iColor,:);
    FileMat.Atlas.Scouts(i).Region  = FileMat.Atlas.Scouts(i).Label{1}(1);
end

Fband       = 'alpha';
condition   = 'scalpnegIED - scalpnegIED';
contrast    = sData.new_results.eeg.scalpnegIED.(Fband).wpli - sData.new_results.eeg.noIED.(Fband).wpli;

% Reshape: [nA x nB x nTime x nFreq] => [nA*nB x nTime x nFreq]
FileMat.TF =  process_compress_sym('Compress',  contrast(:) ); 
FileMat.DisplayUnits = 'Weighted phase lag index';
FileMat.Comment      = sprintf('Connectum, %s, Band; %s', condition,  Fband);
FileMat.RefRowNames  = sData.new_results.eeg.labels;
FileMat.RowNames     = sData.new_results.eeg.labels;
FileMat.DataType     = 'results';
FileMat.Method       = 'corr';
FileMat.DataFile     = [];
FileMat.nAvg         = 1;
FileMat.Time         = [1];
FileMat.ProcessName  = '';
FileMat.Options = bst_connectivity();

[sOutputStudy] = bst_get('Study', iStudy)
NewFile = bst_process('GetNewFilename', bst_fileparts(sOutputStudy.FileName), sprintf('timefreq_connectn_wpli_sub-%d_band-%s_wpli', sub_id, Fband));
bst_save(NewFile, FileMat, 'v6');
db_add_data(iStudy, NewFile, FileMat);

Matrix view:

Graph view:

i can share a brainstorm zip with the file already imported if you prefer.

Actually, what is the difference between local and global for the graph ? there is no time so it should be the same. but its not.

Local :

Global:

If we look at a specific connection, we see the difference between what is displayed (neg link) and the actual value in the matrix (0.2):

A post was split to a new topic: Connectivity: Link connections in graph and matrix figures for NxN

ok. So the solution was to specify:

FileMat.Measure      = 'phase';

Otherwise Brainstorm is displaying the magnitude when displaying the matrix.

This works thought it is not correct.
In connectivity files:

FileMat.Measure = 'other';

The difference is that the graph and matrix are handling this field when missing in a different way (To be fixed soon).

1 Like

thanks.

Additional question: how can i apply process on those files ?

it says 0 files for every options.

There should not be (if there is no more time nor frequency points) as it is the case. As it is the case in the connectivity matrix.

It may had been for testing of the connectivity graph, but for the specific case of FileMat.Method = 'corr' (as in the imported connectivity data above), the option Maximum: Global maximum sets the limits to [0,1] (if abs values) or [-1, 1] (if not abs values). This will be also fixed shortly.

This is quite strange.
Can you reset the filters at the bottom right?

it worked. thanks.

FYI @edelaire

Solved in Commit 9851063

Solved in Commit cca1e00

1 Like

Thanks a lot !!