Export multiple PLV matrices

Dear all,

any function to export multiple PLV matrices as csv-files? I only found the possibility to export single matrices and only a specific frequency range (but not e.g. several ranges such as delta, thea, alpha...).
Any help is highly appreciated...
or a working Matlab command (I am clinician)...

Best & cheers - John

Dear John,

First of all, make sure you update Brainstorm if you haven’t recently. There was a bug in the export of PLV files, it was not enforcing the extraction of a measure from the complex PLV values (phase or power), and was saving sometimes wrong values in the text/Excel files.

Unfortunately, there is no easy way to export at once multiple connectivity files that contain multiple frequency bands. You would need to write a Matlab script for this.
You can select all the files you want to export in Process1, select any process, then generate a script to get the list of filenames.
Then write a loop on these files to load each file and save it to a different format (something similar to what is function export_timefreq.m).

Francois

Dear Francois,
thank’s a lot for your quick response and for redirecting me to update my BS due to a previous bug!
I’ll try my best to script this process using Brainstorm/Matlab. If anyone else on the forum has already done this it would be very nice to provide this code.
Best - John

Dear BST community,

If anyone is looking for a script to extract the connectivity values from the .mat files stored in the brainstorm_db folder, I wrote the following script:

% Enter the list of subjects as they appear in Brainstorm
SubjectNames = {'4205', '4227', '4235', '4237', '4240', '4245', '4250', '4267', '4295', '7001', '7002', '7003', '7004', '7005', '7006', '7007', '7008', '7009', '7010', '7012', '7013', '7014', '7015', '7016', '7018', '7019', '7020', '7021', '7022', '7023', '7024', '7025', '7026', '7027', '7028', '7029', '7030', '7031', '7032', '7033', '7034', '7035', '7036', '7037', '7039', '7040', '7041', '7042', '7043', '7044', '7045', '7046', '7047', '7048', '7049', '7050', '7051', '7052', '7053', '7055', '7056', '7059', '7061', '7062', '7064', '7066', '7067', '7068', '7069', '11_4239', '12_4239'};
% Loop through all subjects
for iSubject = 1:length(SubjectNames)
d = dir(['C:\Users\User\Desktop\brainstorm_db\test2\data' num2str(SubjectNames{iSubject}) '\rest\timefreq_connectn_plv_average*.mat']); % "num2str(SubjectNames{iSubject})" allows to loop through each subject, and "*" truncates the ending characters that differ between subjects.
names = {d.name};
x = char(names)
BSTfile = load(x)
PLV = bst_memory('GetConnectMatrix', BSTfile);
PLVdelta = PLV(:,:,1) % The last number represents the frequency band (Delta:1, Theta:2, Alpha:3, Beta:4, Gamma:5).
dlmwrite(['PLVdeltarest' num2str(SubjectNames{iSubject}) '.txt'], PLVdelta,'delimiter','\t'); % Writes each subject's connectivity matrix (in only one frequency band) in a tab-delimited text file.
end

It might not be pretty but it works!

Cheers,
Simon

1 Like

Dear @Francois,

I am currently also trying to export multiple connectivity matrices for further analyses in Matlab but process1 (extract values -> measure from complex values) option seems to produce an, for both phase and power.

I was wondering if this is something that has now been implemented or will I have to run a code like the example given by Simon?

Thanks

If you need the values directly in Matlab, read them directly from the files.

process1 (extract values -> measure from complex values) option seems to produce an, for both phase and power.

The PLV values are real values, not complex.

Hi @Francois,

I have performed statistical analyses on PLV between two groups and I want to extract the resultant matrix. I thought I would be able to extract it using bst_memory('GetConnectMatrix', mtx) but realised that the final matrix has no TF field.

I want to export the "statistically significant" matrix so that I can plot it outside of bst. Could you please help me with it?

Thanks

I thought I would be able to extract it using bst_memory('GetConnectMatrix', mtx) but realised that the final matrix has no TF field.

You need to apply a specific threshold to your results:
https://neuroimage.usc.edu/brainstorm/Tutorials/Statistics#Convert_statistic_results_to_regular_files

This will give you a regular timefreq file with a field TF.

Thanks @Francois.

I have now applied a statistical threshold (0.05) and I get values ranging from -0.1 to 0.1. Can you please tell me what it reflects? Are these the p-values or t-values?

What you can find in your file is the statistic you computed (e.g. t-value) thresholded below a given p-value, with the correction for multiple comparison you selected.

Reading the Statistics tutorial from A to Z could help you understand better how Brainstorm deals with statistical testing.