Skip to content

Instantly share code, notes, and snippets.

@h-mayorquin
Last active June 24, 2023 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-mayorquin/576e54fae7ff2cf0d1255f15fe80a20c to your computer and use it in GitHub Desktop.
Save h-mayorquin/576e54fae7ff2cf0d1255f15fe80a20c to your computer and use it in GitHub Desktop.
Stub cell explorer spikes files from matlab
% Load the file
data = load('Peter_MS22_180629_110319_concat.spikes.cellinfo.mat');
% Define the fields to be removed
fieldsToDrop = {'maxWaveformCh', 'maxWaveformCh1', 'peakVoltage', 'peakVoltage_expFitLengthConstant', 'peakVoltage_sorted', 'amplitudes', 'filtWaveform', 'filtWaveform_std', 'rawWaveform', 'rawWaveform_std', 'timeWaveform', 'maxWaveform_all', 'rawWaveform_all', 'filtWaveform_all', 'timeWaveform_all', 'channels_all'}; % Add all the fields you want to drop
% Drop the fields from 'spikes'
data.spikes = rmfield(data.spikes, intersect(fieldnames(data.spikes), fieldsToDrop));
% Fields to be ignored for modification
fieldsToIgnore = {'processinginfo', 'basename', 'numcells'};
n_cells = 3;
% Keep only the data from the first 10 units for the remaining fields
fields = setdiff(fieldnames(data.spikes), fieldsToIgnore);
for i = 1:length(fields)
if iscell(data.spikes.(fields{i})) && numel(data.spikes.(fields{i})) >= n_cells % For cell array fields
data.spikes.(fields{i}) = data.spikes.(fields{i})(1:n_cells);
elseif isvector(data.spikes.(fields{i})) && numel(data.spikes.(fields{i})) >= n_cells % For vector fields
data.spikes.(fields{i}) = data.spikes.(fields{i})(1:n_cells);
end
end
% Modify the 'numcells' field to reflect the number of units retained
data.spikes.numcells = n_cells;
% Save the modified structure
save('Peter_MS22_180629_110319_concat.spikes.cellinfo_stubbed_hdf5.mat', '-struct', 'data', '-v7.3');
save('Peter_MS22_180629_110319_concat.spikes.cellinfo_stubbed.mat', '-struct', 'data');
%%%%%%%%%%%%%%%%
% Stub session
%%%%%%%%%%%%%%%%%
% Load the file
data = load('Peter_MS22_180629_110319_concat.session.mat');
% Drop the fields from 'session'
fieldsToDrop = {''}; % Add all the fields you want to drop
data.session = rmfield(data.session, intersect(fieldnames(data.session), fieldsToDrop));
% Modify the 'nSamples' field
stub_to = 10;
data.session.extracellular.nSamples = stub_to; % Adjust this according to the actual location of the 'nSamples' field
data.session.timeSeries.dat.nSamples = stub_to;
% Save the modified structure in MATLAB's standard .mat format
save('Peter_MS22_180629_110319_concat.session_stubbed.mat', '-struct', 'data');
% Save the modified structure in HDF5 format
save('Peter_MS22_180629_110319_concat.session_stubbed_hdf5.mat', '-struct', 'data', '-v7.3');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment