1+ %
2+ % Modified on 2024/04/11 to process thrive dataset flanker data
3+ %
4+ % This script was created by George Buzzell for the NDC Lab EEG Training
5+ % Workshop on 02/22. This script uses parts of the "set up" structure from
6+ % the MADE preprocessing pipeline (Debnath, Buzzell, et. al., 2020)
7+
8+ clear % clear matlab workspace
9+ clc % clear matlab command window
10+
11+ %% Setting up other things
12+
13+ % Location of MADE and ADJUSTED-ADJUST scripts
14+ % addpath(genpath([main_dir filesep 'MADE-EEG-preprocessing-pipeline']));% enter the path of the EEGLAB folder in this line
15+ addpath(genpath(' /home/data/NDClab/tools/lab-devOps/scripts/MADE_pipeline_standard/eeg_preprocessing' ));% enter the path of the folder in this line
16+
17+ % Location of "EEG
18+ % addpath(genpath([main_dir filesep 'eeglab13_4_4b']));% enter the path of the EEGLAB folder in this line
19+ addpath(genpath(' /home/data/NDClab/tools/lab-devOps/scripts/MADE_pipeline_standard/eeglab13_4_4b' ));% enter the path of the EEGLAB folder in this line
20+
21+ % remove path to octave functions inside matlab to prevent errors when
22+ % rmpath([main_dir filesep 'eeglab13_4_4b' filesep 'functions' filesep 'octavefunc' filesep 'signal'])
23+ rmpath([' /home/data/NDClab/tools/lab-devOps/scripts/MADE_pipeline_standard/eeglab13_4_4b' filesep ' functions' filesep ' octavefunc' filesep ' signal' ])
24+
25+ %% setup; run this section before any other section below
26+
27+ % location of analysis folder
28+ % analysis_dir = '/Users/fzaki001/thrive-theta-ddm';
29+ analysis_dir = ' /home/data/NDClab/analyses/thrive-theta-ddm' ;
30+
31+ % location of dataset folder
32+ % dataset_dir = '/Users/fzaki001/thrive-theta-ddm';
33+ dataset_dir = ' /home/data/NDClab/datasets/thrive-dataset/derivatives/preprocessed/' ;
34+ % summary_csv_path = '/Users/fzaki001/thrive-theta-ddm/derivatives/behavior/summary.csv';
35+ summary_csv_path = ' /home/data/NDClab/analyses/thrive-theta-ddm/derivatives/behavior/summary-eeg.csv' ;
36+
37+ % Setting up other things
38+
39+ % 1. Enter the path of the folder that has the data to be analyzed
40+ data_location = [dataset_dir filesep ' derivatives' filesep ' preprocessed' ];
41+
42+ % 2. Enter the path of the folder where you want to save the postprocessing outputs
43+ output_location = [analysis_dir filesep ' derivatives' filesep ' preprocessed/erp_check' ];
44+
45+ % 3. this is the correct channel location file BUT INCORRECT PATH!
46+ % channel_locations = loadbvef('/Users/fzaki001/Downloads/thrive/code/CACS-128-X7-FIXED-64only.bvef');
47+ channel_locations = loadbvef(' /home/data/NDClab/tools/lab-devOps/scripts/MADE_pipeline_standard/eeg_preprocessing/chan_locs_files/electrode_locs_files/CACS-128-X7-FIXED-64only.bvef' );
48+
49+ % %specify parameters of data to process
50+
51+ % modifying above, to account for files named differently
52+ % specify parameters of data to process
53+ task = ' all' ;
54+ procStage = ' processed_data' ;
55+ visitDirName = ' s1_r1' ; % visit folder does not list "e1"
56+ visitFileName = ' s1_r1_e1' ; % file names include "e1" designation
57+
58+ % Read files to analyses
59+ datafile_info= dir([data_location filesep ' sub-*' filesep visitDirName filesep ' eeg' filesep ' sub-*_' task ' _eeg_*' procStage ' _' visitFileName ' .set' ]);
60+ datafile_info= datafile_info(~ismember({datafile_info .name },{' .' , ' ..' , ' .DS_Store' }));
61+ datafile_names= {datafile_info .name };
62+ datafile_paths= {datafile_info .folder };
63+ [filepath ,name ,ext ] = fileparts(char(datafile_names{1 }));
64+
65+ % Check whether EEGLAB and all necessary plugins are in Matlab path.
66+ if exist(' eeglab' ,' file' )==0
67+ error([' Please make sure EEGLAB is on your Matlab path. Please see EEGLAB' ...
68+ ' wiki page for download and instalation instructions' ]);
69+ end
70+
71+ % Create output folders to save data
72+ if exist(output_location , ' dir' ) == 0
73+ mkdir(output_location )
74+ end
75+
76+ %% Count trials
77+ subjects = [50 , 53 , 60 , 62 , 64 , 66 ] % these are just ids to put to the resulting csv, they are not used for computations
78+ % n_subjects = length(subjects) % this number will be used for loops because the initial subjects list may be changed based on num of trials
79+ % switch to output directory
80+ cd(output_location );
81+
82+ % %create variable names for count trials output and write to disk
83+ % outputHeader = {'id, s_resp_incon_error, s_resp_incon_corr, ns_resp_incon_error, ns_resp_incon_corr'};
84+ % dlmwrite(strcat('thrive_trialCounts_respOnly', date, '.csv'), outputHeader, 'delimiter', '', '-append');
85+
86+ for subject= 1 : length(datafile_names )
87+ EEG= [];
88+
89+ fprintf(' \n\n\n *** Processing subject %d (%s ) ***\n\n\n ' , subject , datafile_names{subject });
90+
91+ % load in raw data that is alread in eeglab (.set) format)
92+ EEG = pop_loadset( ' filename' , datafile_names{subject }, ' filepath' , datafile_paths{subject });
93+ EEG = eeg_checkset(EEG );
94+
95+ % convert subject name to number
96+ % note:would be nice to modify line below to not be hard-coded for finding
97+ % location of subject id. eg, use some combination of strtok instead
98+ subIdNum = str2double(datafile_names{subject }(5 : 11 ));
99+
100+ % remove all the non-stim-locking markers (should have done already...)
101+ EEG = pop_selectevent( EEG , ' latency' ,' -.1 <= .1' ,' deleteevents' ,' on' );
102+ EEG = eeg_checkset( EEG );
103+
104+ % latency
105+ % duration
106+ % channel
107+ % bvtime
108+ % bvmknum
109+ % visible
110+ % type
111+ % code
112+ % urevent
113+ % observation
114+ % eventType
115+ % targetDir
116+ % congruency
117+ % responded
118+ % accuracy
119+ % rt
120+ % validRt
121+ % extraResponse
122+ % validTrial
123+ % prevTargetDir
124+ % prevCongruency
125+ % prevResponded
126+ % prevAccuracy
127+ % prevRt
128+ % prevValidRt
129+ % prevExtraResponse
130+ % prevValidTrial
131+ % nextTargetDir
132+ % nextCongruency
133+ % nextResponded
134+ % nextAccuracy
135+ % nextRt
136+ % nextValidRt
137+ % nextExtraResponse
138+ % nextValidTrial
139+ % epoch
140+
141+ % count how many of each event type (combination of event types) of
142+ % interest are present
143+ s_resp_incon_error = length(find( (strcmp({EEG .event .observation }, " s" )) & (strcmp({EEG .event .eventType }, " resp" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 0 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
144+ s_resp_incon_corr = length(find( (strcmp({EEG .event .observation }, " s" )) & (strcmp({EEG .event .eventType }, " resp" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
145+ ns_resp_incon_error = length(find( (strcmp({EEG .event .observation }, " ns" )) & (strcmp({EEG .event .eventType }, " resp" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 0 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
146+ ns_resp_incon_corr = length(find( (strcmp({EEG .event .observation }, " ns" )) & (strcmp({EEG .event .eventType }, " resp" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
147+ s_stim_incon_corr = length(find( (strcmp({EEG .event .observation }, " s" )) & (strcmp({EEG .event .eventType }, " stim" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
148+ s_stim_con_corr = length(find( (strcmp({EEG .event .observation }, " s" )) & (strcmp({EEG .event .eventType }, " stim" )) & (strcmp({EEG .event .congruency }, " c" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
149+ ns_stim_incon_corr = length(find( (strcmp({EEG .event .observation }, " ns" )) & (strcmp({EEG .event .eventType }, " stim" )) & (strcmp({EEG .event .congruency }, " i" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
150+ ns_stim_con_corr = length(find( (strcmp({EEG .event .observation }, " ns" )) & (strcmp({EEG .event .eventType }, " stim" )) & (strcmp({EEG .event .congruency }, " c" )) & ([EEG .event .accuracy ] == 1 ) & ([EEG .event .responded ] == 1 ) & ([EEG .event .validRt ] == 1 ) ));
151+
152+ % Create the trial counts table for trial counts
153+ counts_table= table({datafile_names{subject }}, {s_resp_incon_error }, {s_resp_incon_corr }, {ns_resp_incon_error }, {ns_resp_incon_corr }, {s_stim_incon_corr }, {s_stim_con_corr }, {ns_stim_incon_corr }, {ns_stim_con_corr });
154+
155+ % create variable names for count trials output and write to disk
156+ counts_table.Properties.VariableNames = {' fileName' , ' s_resp_incon_error' , ' s_resp_incon_corr' , ' ns_resp_incon_error' , ' ns_resp_incon_corr' , ' s_stim_incon_corr' , ' s_stim_con_corr' , ' ns_stim_incon_corr' , ' ns_stim_con_corr' };
157+
158+ % write/append table to disk
159+ writetable(counts_table , [output_location filesep ' thrive_trialCounts_RespAndStim_' , date , ' .csv' ], " WriteMode" , " append" );
160+
161+ end
0 commit comments