[Eeglablist] script example, to extract epochs?

Andrew Hill andrewhill at ucla.edu
Sun Jun 28 03:28:39 PDT 2009


thanks Arno,

here is my final script (that works!) to open/re-reference  
continuous .set files for 12 subjects, extract 28 groups of epochs  
from each subject, conditional on combinations of triggers, name each  
epoched .set something meaningful (to me) and save after baselining,  
ready to be set up in a Study.   the script could use refactoring (i  
am redundant with loops because of different array sizes in my  
condition/trigger combinations) but hey, it's my first one :)

i'm posting it to the list because several people emailed me with  
advice and a request to know if i got something that worked well.

for reference, this loads continuous .set files that are 250-300mb.   
the script generates 28 epoched .set files per continuous file,  
with .dats that range from 4-40mb in size (20 to 200 epochs).   the  
machine is 2.8Ghz core2duo with 4gb ram, and i can run through all 12  
subjects in about 20 minutes, without any out of memory errors.  i'm  
using Matlab r2008a and eeglab2008October01_beta.

best,
andrew

for S = [108 109 110 111 112 113 114 115 116 119 120 121];
     eeglab

     %%%% Operations on .SET file.
     % load a file, for example 108.set, which is not filtered and  
uses common vertex reference.
     EEG = pop_loadset( 'filename', [int2str(S),'.set'], 'filepath', '/ 
Users/andrew/Documents/Research/DATA/stage/');
     EEG = eeg_checkset( EEG );

     % re-reference to common average reference, excluding VEOU and VEOL
     EEG = pop_reref( EEG, [], 'refstate',0, 'exclude',[65 66] );

     % lookup Channel Locations
     EEG = pop_chanedit(EEG,  'lookup', '/Users/andrew/Documents/ 
Research/eeglab2008October01_beta/plugins/dipfit2.2/standard_BESA/ 
standard-10-5-cap385.elp');

     % store the re-referenced, channel loaded set in ALLEEG
     % row 20 used to allow up to 19 condition/trigger groups
     [ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 20);


     %%%% Extraction of epochs (using 3 different loops, as arrays of
     %%%% triggers are of different length (grouping versus single, etc)

     % Quad-trigger coded epochs (collapsed target group)
     % Epoch using c (array size), Cond as name for several trigs for  
one Condidition
     for c = [1:4];
         Cond = [ 'LVF_ConTarg_AllCue'; 'LVF_IncTarg_AllCue';  
'RVF_ConTarg_AllCue'; 'RVF_IncTarg_AllCue' ];
         trigs = [{'110', '111', '112', '113'}; {'120', '121', '122',  
'123'}; {'210', '211', '212', '213'}; {'220', '221', '222', '223'} ];
         EEG = pop_epoch(EEG, trigs(c,:), [-1 2], 'newname',  
Cond(c,:) );

         % baseline filter using pre-stimulus interval.
         % NOT working with [-1000  0] => "Wrong point range"
         EEG = pop_rmbase( EEG, [0  250] );
         [ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, c );

         % save a new set file for the extracted epochs
         EEG = pop_saveset( EEG,  'filename',  
[int2str(S),'_AVGREREF_',Cond(c,:),'.set'], 'filepath', '/Users/andrew/ 
Documents/Research/DATA/out');

         % select the unepoched, re-referenced .SET file
         [EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,20);
     end

     % Double-trigger coded epochs
     % Epoch using d (array size), Cond as name for several trigs for  
one Condidition
     for d = [1:8];
         Cond =[ 'LVF_AllTarg_No-Cue' ;'LVF_AllTarg_CenCue';  
'LVF_AllTarg_ValCue'; 'LVF_AllTarg_InvCue'; 'RVF_AllTarg_No-Cue';  
'RVF_AllTarg_CenCue'; 'RVF_AllTarg_ValCue';'RVF_AllTarg_InvCue' ];
         trigs =[{'110','120'}; {'111','121'}; {'112','122'};  
{'113','123'}; {'210','220'}; {'211','221'}; {'212','222'};  
{'213','223'} ];
         EEG = pop_epoch(EEG, trigs(d,:), [-1 2], 'newname',  
Cond(d,:) );

         % baseline filter using pre-stimulus interval.
         % NOT working with [-1000  0] => "Wrong point range"
         EEG = pop_rmbase( EEG, [0  250] );
         [ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, d );

         % save a new set file for the extracted epochs
         EEG = pop_saveset( EEG,  'filename',  
[int2str(S),'_AVGREREF_',Cond(d,:),'.set'], 'filepath', '/Users/andrew/ 
Documents/Research/DATA/out/');

         % select the unepoched, re-referenced .SET file
         [EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,20);
     end

     % Single-trigger coded epochs (split out by cues and targets)
     % Epoch using e (array size), Cond as name for several trigs for  
one Condidition
     for e = [1:16];
         Cond =['LVF_ConTarg_No-Cue'; 'LVF_ConTarg_CenCue';  
'LVF_ConTarg_ValCue'; 'LVF_ConTarg_InvCue'; 'LVF_IncTarg_No-Cue';  
'LVF_IncTarg_CenCue'; 'LVF_IncTarg_ValCue'; 'LVF_IncTarg_InvCue';  
'RVF_ConTarg_No-Cue'; 'RVF_ConTarg_CenCue'; 'RVF_ConTarg_ValCue';  
'RVF_ConTarg_InvCue'; 'RVF_IncTarg_No-Cue';  
'RVF_IncTarg_CenCue';'RVF_IncTarg_ValCue';'RVF_IncTarg_InvCue'  ];
         trigs =[{'110'}; {'111'}; {'112'}; {'113'}; {'120'}; {'121'};  
{'122'}; {'123'}; {'210'}; {'211'}; {'212'}; {'213'}; {'220'};  
{'221'}; {'222'}; {'223'} ];
         EEG = pop_epoch(EEG, trigs(e,:), [-1 2], 'newname',  
Cond(e,:) );

         % baseline filter using pre-stimulus interval.
         % NOT working with [-1000  0] => "Wrong point range"
         EEG = pop_rmbase( EEG, [0  250] );
         [ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, e );

         % save a new set file for the extracted epochs
         EEG = pop_saveset( EEG,  'filename',  
[int2str(S),'_AVGREREF_',Cond(e,:),'.set'], 'filepath', '/Users/andrew/ 
Documents/Research/DATA/out');

         % select the unepoched, re-referenced .SET file
         [EEG ALLEEG CURRENTSET] = eeg_retrieve(ALLEEG,20);
     end

   ALLEEG = pop_delset( ALLEEG, [1:20] )

end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20090628/136a8a5b/attachment.html>


More information about the eeglablist mailing list