Inserting events from TRLs into already epoched trials

Dear Brainstorm community,

I epoched a raw MEG data file keeping two events (let’s call them 20 and 21) and already reviewed and evaluated all the trials. Now I noticed that it would be convenient to have all the other events present in the raw data, which are found in a TRL file. I would want to have these events in every trial (maybe around a ‘20’ there was also a ‘45’).

Trying to import the TRL to one trial doesn’t give the wanted result because the timing of the events is referred to the raw data (which of course is hugely longer than a single trial). Is there a way to add those events at the right time (i.e. considering the position of the trial within the raw data)?

I am not sure it would work to epoch again the data keeping those events, because it would probably create new folders for everyone of them…

I hope I explained myself clearly but I am happy to do it better if needed :slight_smile:

Thank you so much!

This is not possible in the GUI. Because as you have seen the trial time 0 s is set at the occurrence of the imported event.

Adding all the events (45 and all others) in the raw file, and the importing for events 20 and 21 is the simplest way to have those additional events in the trials.

The alternative is a bit more complicated, and needs to be done by writing an Matlab script to work with Brainstorm, in brief:

  1. For an imported trial, get its position in the original raw file [A,B]
    This info can be seen in the GUI by right-click on the trial > File > View history

  2. For the same imported trial get and its minimum time C

  3. Look for events in the TRL file that are between A and B.
    Then remove C from their times, to have the event in the imported trial time

  4. Modify the event structure to add the new events.

As described above, the simplest way to get the events would be to reimport the trials.

Before re-importing the 20 and 21 events, you can rename the ones that already imported.
Either renaming the trial group (or the folder, if imported in separated folders). This will prevent the merge between the already imported trials, and the re-imported ones.

Thank you very much!