Import events for multiple subjects

Hi,

I try to import events (4 types) for multiple subject, but when I run my pipeline, it all goes in one participant (as described here By-event import when run on multiple runs creates unique folder - #2 by Francois)).
I tried to uncheck the box "created one condition..." and then I got different subjects but created in the same subject.
Then I tried to do it with the script and a loop:


% Script generated by Brainstorm (30-Jun-2022)

% Input files
sFiles = {...
    'AF03/@rawPREDEMAUT_A03_CtF_0002_band/data_0raw_PREDEMAUT_A03_CtF_0002_band.mat', ...
    'AF04/@rawPREDEMAUT_A04_CtF_0001_band/data_0raw_PREDEMAUT_A04_CtF_0001_band.mat'};
SubjectNames = {...
    'AF03',...
    'AF04'};

% Start a new report
bst_report('Start', sFiles);

% Process: Select file names with tag: Raw | band
sFiles = bst_process('CallProcess', 'process_select_tag', sFiles, [], ...
    'tag',    'Raw | band', ...
    'search', 2, ...  % Search the file names
    'select', 1);  % Select only the files with the tag

for i = 1: length(sFiles)
% Process: Import MEG/EEG: Events
sFiles = bst_process('CallProcess', 'process_import_data_event', sFiles{i}, [], ...
    'subjectname',   SubjectNames{i}, ...
    'condition',     '', ...
    'eventname',     'F_CtF, F_FtC, N_CtF, N_FtC', ...
    'timewindow',    [], ...
    'epochtime',     [0, 2.6], ...
    'createcond',    1, ...
    'ignoreshort',   1, ...
    'usectfcomp',    1, ...
    'usessp',        1, ...
    'freq',          [], ...
    'baseline',      [1.3, 1.5], ...
    'blsensortypes', 'MEG, EEG');

end

% Process: Add time offset: -1500.00ms
sFiles = bst_process('CallProcess', 'process_timeoffset', sFiles, [], ...
    'info',      [], ...
    'offset',    -1.5, ...
    'overwrite', 1);

% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);
% bst_report('Email', ReportFile, username, to, subject, isFullReport);

But I got this erros:

Brace indexing is not supported for variables of this type.

Error in import (line 22)
sFiles = bst_process('CallProcess', 'process_import_data_event', sFiles{i}, [], ...

What's wrong? And how can I have my different events in each subject?

Thanks

Hello,

Can you check what is the value of sFiles after calling process_select_tag ? Also i think the issue might be that you are overwritting sFiles when calling process_import_data_event. so it works for i = 1; but then cannot find sFiles{2}.
So you should give another name to the output of process_import_data_event.

Maybe something like this should work:

sFileOut = {};
for i = 1: length(sFiles)
sFileOut{end+1} = bst_process('CallProcess', 'process_import_data_event', sFiles{i} ...

end

HS: how do you put code in the forum?

Thanks for your reply.
I tried to modify the code and have some progress (I have been able to import events and save them in different subjects), with your help and by changing the brackets, but was unable to include the second part of the loop(add time DC offset) in the loop. (I don't know matlab at all so it's quite complicated for me to implement changes)

here is my new code:

% Script generated by Brainstorm (30-Jun-2022)

% Input files
sFiles = {...
    'AF03/@rawPREDEMAUT_A03_CtF_0002_band/data_0raw_PREDEMAUT_A03_CtF_0002_band.mat', ...
    'AF04/@rawPREDEMAUT_A04_CtF_0001_band/data_0raw_PREDEMAUT_A04_CtF_0001_band.mat'};
SubjectNames = {...
    'AF03',...
    'AF04'};

% Start a new report
bst_report('Start', sFiles);

% Process: Select file names with tag: Raw | band
sFiles = bst_process('CallProcess', 'process_select_tag', sFiles, [], ...
    'tag',    'Raw | band', ...
    'search', 2, ...  % Search the file names
    'select', 1);  % Select only the files with the tag

sFileOut={};
sFileOut2={};
for i = 1: length(sFiles)
% Process: Import MEG/EEG: Events
sFileOut{i} = bst_process('CallProcess', 'process_import_data_event', sFiles(i), [], ...
    'subjectname',   SubjectNames{i}, ...
    'condition',     '', ...
    'eventname',     'F_CtF, F_FtC, N_CtF, N_FtC', ...
    'timewindow',    [], ...
    'epochtime',     [0, 2.6], ...
    'createcond',    1, ...
    'ignoreshort',   1, ...
    'usectfcomp',    1, ...
    'usessp',        1, ...
    'freq',          [], ...
    'baseline',      [1.3, 1.5], ...
    'blsensortypes', 'MEG, EEG');


% Process: Add time offset: -1500.00ms
sFileOut2{i} = bst_process('CallProcess', 'process_timeoffset', sFileOut(i), [], ...
    'info',      [], ...
    'offset',    -1.5, ...
    'overwrite', 1);

% Save and display report
ReportFile = bst_report('Save', sFileOut2(i));
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);
% bst_report('Email', ReportFile, username, to, subject, isFullReport);

end 

and what I got now:

>> import
BST> Emptying temporary directory...
Warning: Inputs must be character vectors, cell arrays of character vectors, or string arrays. 
> In bst_process>@(c)strrep(c,[ProtocolInfo.STUDIES,filesep],'') (line 1498)
  In bst_process>GetInputStruct (line 1498)
  In bst_process>CallProcess (line 2224)
  In bst_process (line 38)
  In import (line 41)
 
Error using strrep
Conversion to double from struct is not possible.

Error in bst_process>@(c)strrep(c,[ProtocolInfo.STUDIES,filesep],'') (line 1498)
    FileNames = cellfun(@(c)strrep(c, [ProtocolInfo.STUDIES, filesep], ''), FileNames, 'UniformOutput', 0);

Error in bst_process>GetInputStruct (line 1498)
    FileNames = cellfun(@(c)strrep(c, [ProtocolInfo.STUDIES, filesep], ''), FileNames, 'UniformOutput', 0);

Error in bst_process>CallProcess (line 2224)
        sInputs = GetInputStruct(sInputs);

Error in bst_process (line 38)
eval(macro_method);

Error in import (line 41)
sFileOut2{i} = bst_process('CallProcess', 'process_timeoffset', sFileOut(i), [], ...
 
Warning: Function import has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. 
>> 

(for the code, I use ``` before and after the code)

I think your problem is that you are passing cell-array of structures to bst_process, i.e. using sFileOut(i) instead of sFileOut(i).

I don't know matlab at all so it's quite complicated for me to implement changes

Unfortunately, you may not manage to write fully working scripts without spending some extra time before in learning some basic Matlab programming. You should at least master the difference between the basic data types and the different ways to index content into them (cell, matrix, struct, array of struct). This includes understanding clearly the difference between sFileOut(i) and sFileOut{i}.

Thank you for your reply. I should have written that I just have few bases (instead of none), but you're right that I don't master them. I totally agree that I should, and I plan to (but I just have one month left to finish my thesis and during my thesis, I spent quite a lot of time on learning statistics and learning R and did not had time yet for matlab unfortunately...). I will look more in details to what you pointed (I tried quite a lot of different things before posting and got some improvement, even if it still does not work. I will try to better understand what happens).

Just in case it might be useful for other, I think I finally solve my problem with the following code:


sFiles = {...
    'AF03/@rawPREDEMAUT_A03_CtF_0002_band/data_0raw_PREDEMAUT_A03_CtF_0002_band.mat', ...
    'AF04/@rawPREDEMAUT_A04_CtF_0001_band/data_0raw_PREDEMAUT_A04_CtF_0001_band.mat'};
SubjectNames = {...
    'AF03',...
    'AF04'};

bst_report('Start', sFiles);

for i = 1: length(sFiles)

% Process: Import MEG/EEG: Events
sFileOut = bst_process('CallProcess', 'process_import_data_event', sFiles{i}, [], ...
    'subjectname',   SubjectNames{i}, ...
    'condition',     '', ...
    'eventname',     'F_CtF, F_FtC, N_CtF, N_FtC', ...
    'timewindow',    [], ...
    'epochtime',     [0, 2.6], ...
    'createcond',    1, ...
    'ignoreshort',   1, ...
    'usectfcomp',    1, ...
    'usessp',        1, ...
    'freq',          [], ...
    'baseline',      [1.3, 1.5], ...
    'blsensortypes', 'MEG, EEG');


% Process: Add time offset: -1500.00ms
sFileOut = bst_process('CallProcess', 'process_timeoffset', sFileOut, [], ...
    'info',      [], ...
    'offset',    -1.5, ...
    'overwrite', 1);

end 

% Save and display report
ReportFile = bst_report('Save', sFiles);
bst_report('Open', ReportFile);
% bst_report('Export', ReportFile, ExportDir);
% bst_report('Email', ReportFile, username, to, subject, isFullReport);


1 Like

It looks better, indeed.
Thanks for posting your solution!