Automation of Time segment rejection with event marker

Hi Francois.

I need help with three problems that I'm facing now. As I have 50+ raw EEG files. I need to automate certain things, before doing manual inspection of bad time segments.

  1. I need to reject/trim time segments before a certain event marker as I don't need those time segments (for example, end of practice trials marker).

  2. I have imported a raw EEG file that has certain event markers for 240 trials (for example 'S3' - Start of trial, 'S4' - Stimulus, 'S5' - Response, S6 - ITI). They occur continuously in the time series. In some time segments, as the participant missed the response the 'S5' event marker won't be there. I need to remove the other event markers ('S3', 'S4', 'S6') from those time segments.

  3. When I'm rejecting bad time segments manually, I have to keep a note of trial numbers (in the 240 trials) that are getting rejected inside those time segments. However, my event markers are not incremental to check the number of trials that I'm rejecting (S3, S4, S5, S6 getting repeated throughout the time series). Is there any way to check the number of trial I'm rejecting as I have to remove those trials from the behavioral data from NBS presentation software?. I need to either change one of the markers to increment throughout the time series (for example, changing S3 to S31, S32, S33,....) or create a separate event marker 20 ms after any one of the marker (for example, T1,T2,T3,.... 20 ms after every S3)

Sorry for the long passage,

Thanks in advance,
Sainath Murali

I don't see any way for doing this without doing this manually in a Matlab script.
You need to read the events of the files, and find the latency of the marker that indicates the beginning or end of the period of interest in the file. Then you can use this time either to:

  1. Remove all the markers outside of the time of interest from the file, and save the updated Link to raw file before epoching the data.
  2. Use the time of interest as the "time window" option, when epoching the data.
  3. Add "bad" segments outside of the periods of interest

See tutorials:

In some time segments, as the participant missed the response the 'S5' event marker won't be there. I need to remove the other event markers ('S3', 'S4', 'S6') from those time segments.

You can use the process "Combine stim/response" in order to create new categories of events (e.g. "S3_S5" or "S3_valid") that include only the events S3 that are followed by an event S5 within a given period of time.

Is there any way to check the number of trial I'm rejecting as I have to remove those trials from the behavioral data from NBS presentation software?

By "rejected trials" you mean: the epochs that are imported but tagged as bad in the database?
(as in: https://neuroimage.usc.edu/brainstorm/Tutorials/Epoching#Import_in_database)
This is information is available in the database, and therefore it can be retrieved (for example to discard them from other sources of information).

The list of bad trials for a given folder is saved in the file brainstormstudy.mat:

>> studymat = load('.../Protocol/data/Subject01/S01_AEF_20131218_01_600Hz_notch/brainstormstudy.mat')

studymat = 
  struct with fields:
    DateOfStudy: '18-Dec-2013'
           Name: 'S01_AEF_20131218_01_600Hz_notch'
      BadTrials: {1×10 cell}

You can also get this information from the database:

>> sStudy = bst_get('StudyWithCondition', 'Subject01/S01_AEF_20131218_01_600Hz_notch')

sStudy = 
  struct with fields:
                 Name: 'S01_AEF_20131218_01_600Hz_notch'
             FileName: 'Subject01/S01_AEF_20131218_01_600Hz_notch/brainstormstudy.mat'
          DateOfStudy: '18-Dec-2013'
    BrainStormSubject: 'Subject01/brainstormsubject.mat'
            Condition: {'S01_AEF_20131218_01_600Hz_notch'}
              Channel: [1×1 struct]
             iChannel: []
                 Data: [1×242 struct]
            HeadModel: [1×2 struct]
           iHeadModel: 2
               Result: [1×486 struct]
                 Stat: [0×0 struct]
                Image: [0×0 struct]
             NoiseCov: [1×1 struct]
              Dipoles: [0×0 struct]
             Timefreq: [1×4 struct]
               Matrix: [1×0 struct]

>> iBadTrials = find([sStudy.Data.BadTrial])

iBadTrials =
    21    57    70   134   135   136   138   139   151   152

This tutorial page would help: https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting