User Tools

Site Tools


Sidebar

Home

EEGLAB Hackathon
Scripts
Main Website
Contact

bastien.b1@gmail.com

eeglabsessh2b

Session Two: Post-Processing & Analysis (GUI)

Preparation of Day Crew Script for analysis in ERPLAB

As we have seen once we ran the Night Crew we get a set which contains ICA weights. At this point human supervision is unavoidable as we need to explore ICs and subtract the ones that are responsible for artefacts.

At the end of each set we will have saved a set which will not only contain ICA weights but which will have been corrected by subtracting ICs responsible for artefacts.

1. Loading ICAed set

We will not use pop_loadcnt() this time because the final set that the Night Crew created is in the EEGLAB format. To load a *.set file we use pop_loadset()

EEG = pop_loadset('filename', 503_ICAC.set);

Easy!

2. Make ERPLab happy: epoched to continuous dataset

As we saw earlier ERPLab wants a continuous set. Luckily its developers provide a function for that:

EEG = pop_epoch2continuous(EEG);

Yes! Just as easy as this!

3. Create Eventlist

The following line will create a simple event list and will convert the “mess” created by the previous function by converting the strings boundary to a numerical value -99.

EEG  = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', 'BoundaryNumeric', { -99 }, 'BoundaryString', { 'boundary' } );

4. Assign bins

Don't forget to update the path of the BDF file.

EEG  = pop_binlister( EEG , 'BDF', '/Path/Of/BDFFile', 'ExportEL', 503_bin.txt', 'IndexEL',  1, 'SendEL2', 'All', 'UpdateEEG', 'on', 'Voutput', 'EEG' );

5. Extract bin-based epochs (& baseline correct)

Does what it says on the tin. Specify limits of epoch window. Third argument sets the baseline correction (here pre for pre-stimulus interval)

EEG = pop_epochbin(EEG , [-100  1000], 'pre');

6. Detect & Mark Artefacts for rejection

  • Specify channel array, in that example we excluded VEOG & HEOG
  • Flag 1, dictates how the artefacted epoch is labeled. Here it will have a flag value of 1 but could be set tp another number (say because we want to perform other types of artefacts detections)
  • Threshold, min max array.
  • Time window, min max array
EEG  = pop_artextval( EEG , 'Channel', [1:65 67], 'Flag',  1, 'Threshold', [-75 75], 'Twindow',...
 [-100 1000] );

7. Averaging

  • Criterion:
    • 1=Exclude trials labelled as artefacts
    • 0=Include all trials
    • 2=Only trials with artefacts
    • SEM here will be calculated.
ERP = pop_averager(EEG , 'Criterion', 1, 'SEM', 'on');

NOTE: The result from the averaging is now assigned to a new object called ERP!

7. Saving ERP set

At this point we will want to save the result of our batch. While for all other previous steps we use the pop_saveset() command, because we are now dealing with and ERP set, we need another command to save this ERPset:

ERP = pop_savemyerp(ERP, 'erpname', 503_ERP , 'filename', 503_ERPs.erp');

8. Save a summary of artefact detection

It may come in handy to save a summary of the Artefact Detection for each subject so you can review it once you come back to your computer. Here's how to do that:

pop_summary_AR_eeg_detection(EEG, 503_AR_Summary.txt');

HACK #6



Just as we did for the Night Crew, your task now is to prepare a DayCrew that will take the ICA corrected set and bring it to an ERP set analysable by ERPLab.

For extra luxury we may want to have our script perform the following:

  • that it saves the a set after just before averaging
  • make sure your loop doesn't get stuck because of a buggy dataset.
  • save final dataset. (NOTE. when saving datasets you might want to think of a way to name the dataset with the subject information).

For REAL luxury

  • make matlab create the destination directory. Maybe you want to keep your ERPsets in a different folder from the other EEGLAB-type sets? If you feel brave think about this too.
DayCrew_ERPLAB.m
% This script runs the second set of pre-processing up to averaging. 
% it is designed to prepare the data for analysis in ERPLAB!
% Datasets created as the output of this scrip are only going to be
% compatible for analysis in ERPLAB
%
%%%%%%%%%%% IMPORTANT NOTE: Until further notice this routine should be
% ran on an installation of ERPLAB within a version of EEGLAB no 
% higher than 12 as the epoching routine creates a bug in EEGLAB 13.
% developers of ERPLAB are working on a fix and should release it in 
% further versions.
%
% Author: Bastien Boutonnet, bastien.b@icloud.com
 
 
subject={'505'};
 
pathname_read='/Users/Shared/HackathonFiles/TutorialData/EEGLABHack2/2PostICACorr/';
pathname_writePostProc='/Users/Shared/HackathonFiles/TutorialData/EEGLABHack2/2PostICACorr/PostProc/';
pathname_writeERPSets='/Users/Shared/HackathonFiles/TutorialData/EEGLABHack2/2PostICACorr/ERPSets/';
 
for i=1:length(subject)
   fprintf('Processing Subject #%g : %s...\n', i, subject{i});
 
%creates the destination folders assuming you have not created it manually before
%if test makes sure the folder only gets created once.
    if isequal(exist(pathname_writePostProc, 'dir'),7) %7 = directory
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder exists. All Good to go!');
    else
        [mdirstatus, mdirmessage]=mkdir(pathname_writePostProc);
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder does not exist. Chillax! Will be created');
    end
 
     if isequal(exist(pathname_writeERPSets, 'dir'),7) %7 = directory
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder exists. All Good to go!');
    else
        [mdirstatus, mdirmessage]=mkdir(pathname_writeERPSets);
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder does not exist. Chillax! Will be created');
    end
 
    %try
 
    %Loads ICA corrected set
    EEG = pop_loadset('filename', [pathname_read subject{i} 'RRCOREPFICAC.set']);
 
    %epoched to continuous set
    EEG = pop_epoch2continuous(EEG);
 
    %create basic eventlist
    EEG  = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', 'Newboundary', { -99 }, 'Stringboundary', { 'boundary' }, 'Warning', 'on' );
 
    %assign bins
    EEG  = pop_binlister( EEG , 'BDF', '/Users/Shared/HackathonFiles/TutorialData/bindesc.txt', 'ExportEL', [pathname_writePostProc subject{i} '_bins.txt'], 'IndexEL',  'no', 'SendEL2', 'Workspace&EEG', 'UpdateEEG', 'on');
 
    %extract bin-based epochs & baseline correct
    EEG = pop_epochbin(EEG , [-100  1000], 'pre');
 
    %Artefact detection, save summary, save set
    EEG  = pop_artextval(EEG,'Channel',[1:65 67],'Flag',1,'Threshold',[-75 75],'Twindow',[-100 1000]);
    pop_summary_AR_eeg_detection(EEG, [pathname_writePostProc subject{i} '_AR_Summary.txt']);
    EEG = pop_saveset(EEG,'filename',[pathname_writePostProc subject{i} '_RREPFICACAR.set']);
    EEG = eeg_checkset(EEG);
 
    %Average
    ERP = pop_averager(EEG ,'Criterion',1,'SEM','on');
    ERP = pop_savemyerp(ERP,'erpname',[subject{i} '_ERPs'],'filename',[pathname_writeERPSets subject{i} '_ERPs.erp']);
 
    %Once you have fully debugged your script and that you know it goes
    %through without problems (Due to scripting) uncomment the following
    %lines. It allows you to jump participants if the sets are buggy but
    %won't give you error messages.
 
    %catch
    %   disp(['%%%%%%%%%%%%%%%%%%%%%%%%%Something went wrong with participant ' subject{i} ' :'( Skipping to next participant %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%']);
    %end
 
end

DISCLAIMER: The tutorials provided on this wiki are not intended to compete with the tutorials written by the EEGLAB's (and other toolboxes) developers (EEGLAB website). It intends to be a condensed version for educational/reference purposes for members of the lab/department to which this workshop was given.

eeglabsessh2b.txt · Last modified: 2014/10/08 03:14 (external edit)