Exporting data to SPM before source reconstruction

Hi Francois,
this is Rocco, one of the Italian guys that attended Brainstorm course at McGill in March. Hope you are doing good!

I was wondering if there will be at a certain point a way to export pre-processed data (before source reconstruction) from Brainstorm to a SPM compatible format. I would be curious to use SPM beamforming methods. Maybe it is already there and I don’t see it .

Otherwise, when do you think that beamforming methods will be available on Brainstorm?

Thank you very much,

Rocco

Hi Rocco,

I don’t know what SPM accepts in input for the recordings. Everything in Brainstorm is saved in .mat files, so you can read them in any Matlab script (using the “load” or “in_bst_data” functions).
We added recently converters to FieldTrip structures, in case SPM can work with this (functions “out_fieldtrip_*.m” in brainstorm3/toolbox/io/)

About the beamformer in Brainstorm, we are waiting for an update from John Mosher.
Maybe he can give you an estimated timeline.

Cheers,
Francois

Hi Francois,
thank you very much for your quick reply. I will try with fieldtrip structure.

Best

Rocco

Hi Francois,
so, I tried to export Brainstorm data to Fieldtrip. It works pretty well, but I have one concern.

My goal was to obtain epoched data at the sensors level, in a fieldtrip format.

After preprocessing and epoching raw data in Brainstorm, I imported all the epochs in the database. Then, using out_fieldtrip_data in a for loop, I exported every epoch in a single matlab structure.
I added a trial definition, required by fieldtrip, containing 4 columns:

1- starting point of each trial
2- end point of each trial
3- stimulus occurrence
4- a number coding for the experimental condition associated to that trial

Then, if I average and plot all the epochs separately for each experimental condition, both in Brainstorm and in fieldtrip, the averages seem to correspond pretty well.

  • Do you think that this is a proper way to export from brainstorm to fieltrip? (I mean, is this a proper way to use out_fieldtrip_data?)
  • Would you say that, if the trial definition is correctly written, the exported data are reliable?
  • Do you think that the out_fieldtrip_data function could be developed to include a trial definition by default?

I include the script I wrote to do what I described (sorry, it is probably badly written, I am not a programmer)

Cheers,

Rocco

%% Converting epoched data from Brainstorm to Fieldtrip

cond = {‘Cond_A’; ‘Cond_B’; ‘Cond_C’}; % condition names will be associated with a number (first cond = 1, second = 2, …)
ftData=[];
ep_data = [];

for kk = 1:length(sFiles)

ftData=[];

[ftData, ~, ~] = out_fieldtrip_data (sFiles(kk).FileName, sFiles(kk).ChannelFile,[],0);

% This section works and provides a trial definition - For sure it may be coded better
 qq= [ftData.time{1,1}];

 if kk == 1
     prevendtrial = 0;
 else prevendtrial = ep_data.cfg.trl((kk-1),2);
 end

 [~,endtrial] = size(ftData.time{1,1});

 ep_data.cfg.trl(kk,2) = endtrial+prevendtrial; % ending point of each trial
 ep_data.cfg.trl(kk,1) = prevendtrial+1; % starting point of each trial
 ep_data.cfg.trl(kk,3) = (round(abs(qq(1)*(length(qq)/(abs(qq(1))+qq(end))))))+1+prevendtrial; % stimulus occurence

 % Assigning the number of the condition to each trial

 for ww = 1:length(cond)
    if strcmp(sFiles(kk).Condition,cond(ww))
    ep_data.cfg.trl(kk,4) = ww;
    end
 end

% Saving each epoch in the same ep_data file
 ep_data.time(1,kk) = ftData.time(1,1);
 ep_data.trial(1,kk) = ftData.trial(1,1);
 ep_data.grad = ftData.grad;
 ep_data.label = ftData.label;
 ep_data.dimord = ftData.dimord;

end

%% Check - Averaging, saving avg in ft format, plotting condition avg

for yy = 1 : length(cond)
cfg = [];
cfg.layout = ep_data.grad;
cfg.trials = find(ep_data.cfg.trl(:,4)==yy);
avgCond{yy} = ft_timelockanalysis(cfg, ep_data);

cfg = [];
figure(yy); ft_multiplotER(cfg,avgCond{yy}); colorbar;

end

Hi Rocco,

This looks like an interesting idea.
Unfortunately I am not very familiar with the FieldTrip structures, I’m sorry I cannot validate what you’re doing here.

I currently don’t have the resources necessary to implement your suggestion, but I added it to the to-do list:
http://neuroimage.usc.edu/brainstorm/Next

Cheers,
Francois

Thanks for the reply.
So, you mean that at the moment the only validated uses of out_fieldtrip_data are to export non-epoched raw data and averaged data? is this correct?

Cheers,

Rocco

The function out_fieldtrip_data can be used to export single trials or epoched files (see the code of the function for more details).
It is made to export epoched trials, but with no support for the trial definition (= with no tagging of the different conditions).

Ok I got it!

Thanks

Hi all,

It's been a few years since this post was created, but I was wondering if there are any news regaridng this. I've tried several data formats to export epoched data from brainstorm into DCM module of SPM. Specifically, I tried out_fopen_spm function from brainstorm with no luck. I am trying to imitate precisely the data structure of maeMdfspm8_subject1.mat/dat files attached (from DCM tutorial) using my brainstorm data, and I believe the files named test6 are identical, yet I cannot read the file in DCM module.

Any help would be much appreciated, thanks in advance

Fran

test6.dat (85.0 KB) test6.mat (5.9 KB) maeMdfspm8_subject1.dat (102.6 KB) maeMdfspm8_subject1.mat (1.3 MB)

Specifically, I tried out_fopen_spm function from brainstorm with no luck.

It is complicated to use this function directly.
Have you tried using export_data.m instead (the function called when you right-click on an epoch > File > Export to file).

The files you posted have very different sizes, so they obviously don't contain the same information.
Maybe you could ask on the SPM mailing list how to create manually the files you need?

Thank you Francois,

Yes, the export_data.m calls out_fopen which in turn calls out_fopen_spm. That is how I got to that one. I asked SPM community with no luck so far, but I'll keep trying.

Thanks again,

Fran

Hi FranLop89,

Did you manage to export your epoched data from brainstorm to the DCM module of SPM? An if yes, how did you do? (I would like to do that but I am stuck atm).

Cheers,

Adeline