====== INTs on Macaque LFPs ====== * The MATLAB script is named ACW_MacaqueLFPs.m but then I named the function appropriately playingWithLFPs lol * Takes in the task (delay or fix) * Adds appropriate paths, including the path to the raw data * Sets desired result path function playingWithLFPs(task) addpath((('/Volumes/Hera/Projects/7TBrainMech/scripts/eeg/Shane/Entropy/'))); addpath((('/Volumes/Hera/Projects/7TBrainMech/scripts/eeg/Shane/Entropy/code'))); addpath('/Volumes/Hera/Shane/LFPData-20250428T155619Z-001/LFPData/') if strcmp(task, 'delay') resultPath = '/Volumes/Hera/Projects/7TBrainMech/scripts/eeg/Shane/Entropy/Results/acw/MonkeyData/individual_files_delay'; elseif strcmp(task, 'fix') resultPath = '/Volumes/Hera/Projects/7TBrainMech/scripts/eeg/Shane/Entropy/Results/acw/MonkeyData/individual_files_fix'; end * Loads an excel file called channel_info * Within this excel is a table with 10 columns as follows * session: monkeyID and session number (i.e. QUA001_1) * Neuron_age: time (in days) between the day of recording and the subjects mature age * Neuron_area: localization of electrode within the lateral prefrontal cortex * ID: monkeys ID * group: quantization of neuron age * mature_age: post-natal, chronological age (in days) of 'mid-adolescence', defined by the bone plate closure * mature_group: quantization of mature age * age_group: quantization of (mature age + neuron age) * delay_duration: time between cue offset and go signal for the task done in that session * channel: channel number * Important: the monkeys actual age at that time of the session is neuron_age + mature_age in days channel_info = readtable('channel_info.xlsx'); get_filename = @(row) sprintf('%s_CH%d.mat', row.session{1}, row.channel); % Naming convention made up of behavior session name and electrode number cue_duration = 0.5; % seconds * For each channel, do the following * Pull out the delay_duration from the channel info, aka the time between the cue offset and go signal * Load the LFP data structure * Define the filename, monkey, behavioral session, channel for i_electrode=1:size(channel_info,1) delay_duration = channel_info.delay_duration(i_electrode); % Time between cue offset and go signal load(get_filename(channel_info(i_electrode, :)), 'LFPData'); filename = get_filename(channel_info(i_electrode, :)); monkey = filename(1:3); behavSess = filename(4:6); channel = filename(10:12); * Check if the file exists * The data is arranged into a session-class-ntr topology, where trials (ntr) in which the same stimulus was presented are grouped together (class), and the indices of the class array (1 through to 8) implicitly map onto the manipulated parameter of the stimulus, which is the polar angle of the stimulus location on the 2D plane of the monitor (0 through to 7π/4). “class_to_radian” does this conversion. * A specific period of LFP data can be extracted using the “get_lfp_slice” function. The 2nd argument t0 of the “get_lfp_slice” function specifies a time point (in seconds) around which to include LFP data points up to -t_slice(1) seconds prior to up until t_slice(2) seconds after said time point t0. The time point that we generally align each trial to is “Cue_onT” which is the start of the stimulus. To find the fixation period, we generally use t_slice = [-1, 0]; to find the delay period, we generally use t_slice = [cue_duration, cue_duration + delay_duration] (the two duration values are defined once each in the demo). * Grab sampling rate from the LFP data structure * Depending on if its delay or fix that we want, we define the target time as * Delay: target_time = [cue_duration, cue_duration+delay_duration]; % Time around cue onset from which LFP is to be aligned to * Fix: target_time = [-1, 0]; % Time around cue onset from which LFP is to be aligned to * Define a dummy slice of data that we will fill in if ~isfile([resultPath '/' monkey '_acw_' 'behavSess' behavSess '_' channel '.csv']) get_lfp_slice = @(fs, t0, t_slice) [round(t_slice(1)*fs):round(t_slice(2)*fs)] + round(t0*fs); fs = LFPData.class(1).ntr(1).Sampling_Rate; if strcmp(task, 'delay') target_time = [cue_duration, cue_duration+delay_duration]; % Time around cue onset from which LFP is to be aligned to elseif strcmp(task, 'fix') target_time = [-1, 0]; % Time around cue onset from which LFP is to be aligned to end dummy_lfp_slice = get_lfp_slice(fs, 0, target_time); t_slice = dummy_lfp_slice/fs; clear lfp_current_class lfp_by_class = cell(numel(LFPData.class), 1); % one cell per class * For each class (each stimulus that was presented to the monkeys) and each trial, grab the slice of the LFP data corresponsing to the target time (defined by either the delay or fixation block) * Store the data in one variable for i_class = 1:numel(LFPData.class) n_trials = numel(LFPData.class(i_class).ntr); lfp_trials = zeros(n_trials, numel(get_lfp_slice(fs, 0, target_time))); % preallocate per class for i_trial = 1:n_trials t_idx = get_lfp_slice(fs, LFPData.class(i_class).ntr(i_trial).Cue_onT, target_time); try lfp_trials(i_trial, :) = LFPData.class(i_class).ntr(i_trial).LFP(t_idx); catch end end lfp_by_class{i_class} = lfp_trials; % store trials (2D array) for each class end lfp_all_trials = vertcat(lfp_by_class{:}); % size: [total_trials x timepoints] % plot(t_slice, mean(lfp_all_trials,1)) % plot(t_slice, lfp_all_trials(2,:)) * Take in each trial from the LFP, resample to 150 (or whatever you want) * Define the ACWout variable * Calculate the ACW values using the acw function * Write all necessary info to a table * Save table out clear ACWout for t = 1:size(lfp_all_trials,1) lfp_down = resample(lfp_all_trials(t,:), 150, 500); ACWout{t,1} = monkey; ACWout{t,2} = behavSess; ACWout{t,3} = channel; ACWout{t,4} = t; [ACWout{t,5}, ACWout{t,6}, acf, lags] = acw(lfp_down,150, 1); end % Add the new column to the existing table subjectTable = array2table(ACWout, 'VariableNames', {'Monkey', 'BehavSess', 'Channel', 'Trial','ACW_0', 'ACW_50'}); subjectTable.NeuronArea = repmat(cell2mat(channel_info(i_electrode, :).Neuron_area), size(ACWout,1),1); subjectTable.MatureAge = repmat((channel_info(i_electrode, :).mature_age), size(ACWout,1),1); subjectTable.chronological_age = repmat((channel_info(i_electrode, :).Neuron_age + channel_info(i_electrode, :).mature_age), size(ACWout,1),1); subjectTable.group = repmat((channel_info(i_electrode, :).group), size(ACWout,1),1); subjectTable.mature_group = repmat((channel_info(i_electrode, :).mature_group), size(ACWout,1),1); subjectTable.age_group = repmat((channel_info(i_electrode, :).age_group), size(ACWout,1),1); subjectSavePath = [resultPath '/' monkey '_acw_' 'behavSess' behavSess '_' channel '.csv']; writetable(subjectTable, subjectSavePath) end end