Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
petersenpeter committed Feb 24, 2023
1 parent cc80247 commit 93fa9f2
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 27 deletions.
53 changes: 27 additions & 26 deletions NeuroScope2.m
Original file line number Diff line number Diff line change
Expand Up @@ -4482,52 +4482,53 @@ function setSpikesGroupColors(~,~)

function setSpikesYData(~,~)
UI.settings.spikesYData = UI.panel.spikes.setSpikesYData.String{UI.panel.spikes.setSpikesYData.Value};
groups = [];
[~,sortidx] = sort(cat(1,data.spikes.times{:})); % Sorting spikes
if UI.panel.spikes.setSpikesYData.Value > 1
try
UI.settings.useSpikesYData = true;
if numel(data.spikes.times)>0
switch UI.settings.spikesYDataType{UI.panel.spikes.setSpikesYData.Value}
case 'double'
groups = [];
if numel(data.spikes.times)>0
switch UI.settings.spikesYDataType{UI.panel.spikes.setSpikesYData.Value}
case 'double'
if length(data.spikes.(UI.settings.spikesYData)) == data.spikes.numcells
[~,order1] = sort(data.spikes.(UI.settings.spikesYData),'descend');
[~,order2] = sort(order1);
for i = 1:numel(data.spikes.(UI.settings.spikesYData))
groups = [groups,order2(i)*ones(1,data.spikes.total(i))]; % from cell to array
end
[~,sortidx] = sort(cat(1,data.spikes.times{:})); % Sorting spikes
data.spikes.spindices(:,3) = groups(sortidx); % Combining spikes and sorted group ids
case 'cell'
UI.settings.useSpikesYData = true;
else
UI.settings.useSpikesYData = false;
UI.panel.spikes.setSpikesYData.Value = 1;
end
case 'cell'
try
if size(data.spikes.(UI.settings.spikesYData){1},2)==1
groups = [];
for i = 1:numel(data.spikes.(UI.settings.spikesYData))
groups = [groups,data.spikes.(UI.settings.spikesYData){i}']; % from cell to array
end
elseif size(data.spikes.(UI.settings.spikesYData){1},1)==1
groups = [];
for i = 1:numel(data.spikes.(UI.settings.spikesYData))
groups = [groups,data.spikes.(UI.settings.spikesYData){i}]; % from cell to array
end
end
[~,sortidx] = sort(cat(1,data.spikes.times{:})); % Sorting spikes
data.spikes.spindices(:,3) = groups(sortidx); % Combining spikes and sorted group ids
if contains(UI.settings.spikesYData,'phase')
idx = (data.spikes.spindices(:,3) < 0);
data.spikes.spindices(idx,3) = data.spikes.spindices(idx,3)+2*pi;
end
end
catch
UI.settings.useSpikesYData = false;
UI.panel.spikes.setSpikesYData.Value = 1;
warning('Failed to set sorting')
end
data.spikes.spindices(:,3) = groups(sortidx); % Combining spikes and sorted group ids
if contains(UI.settings.spikesYData,'phase')
idx = (data.spikes.spindices(:,3) < 0);
data.spikes.spindices(idx,3) = data.spikes.spindices(idx,3)+2*pi;
end
end

% Getting limits
UI.settings.spikes_ylim = [min(data.spikes.spindices(:,3)),max(data.spikes.spindices(:,3))];
catch
UI.settings.useSpikesYData = false;
UI.panel.spikes.setSpikesYData.Value = 1;
warning('Failed to set sorting')
end
% Getting limits
UI.settings.spikes_ylim = [min(data.spikes.spindices(:,3)),max(data.spikes.spindices(:,3))];
else
UI.settings.useSpikesYData = false;
end
initTraces
% initTraces
uiresume(UI.fig);
end

Expand Down Expand Up @@ -4627,7 +4628,7 @@ function showSpikeMatrix(~,~)
if ~isempty(UI.settings.channelTags.filter)
for j = 1:numel(UI.channels)
for i = 1:numel(UI.settings.channelTags.filter)
if isfield(data.session.channelTags.({UI.settings.channelTags.filter(i)}),'channels') && ~isempty(data.session.channelTags.(UI.channelTags{UI.settings.channelTags.filter(i)}).channels)
if isfield(data.session.channelTags.(UI.channelTags{UI.settings.channelTags.filter(i)}),'channels') && ~isempty(data.session.channelTags.(UI.channelTags{UI.settings.channelTags.filter(i)}).channels)
[~,idx] = setdiff(UI.channels{j},data.session.channelTags.(UI.channelTags{UI.settings.channelTags.filter(i)}).channels);
UI.channels{j}(idx) = [];
end
Expand Down
2 changes: 1 addition & 1 deletion ProcessCellMetrics.m
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
Theta_channel = session.channelTags.Theta.channels(1);
spikes2.ts{j} = spikes2.ts{j}(spikes{spkExclu}.times{j} < length(InstantaneousTheta.signal_phase{Theta_channel})/session.extracellular.srLfp);
spikes2.times{j} = spikes2.times{j}(spikes{spkExclu}.times{j} < length(InstantaneousTheta.signal_phase{Theta_channel})/session.extracellular.srLfp);
spikes2.ts_eeg{j} = ceil(spikes2.ts{j}/16);
spikes2.ts_eeg{j} = ceil(spikes2.ts{j}*session.extracellular.srLfp/session.extracellular.sr);
spikes2.theta_phase{j} = InstantaneousTheta.signal_phase{Theta_channel}(spikes2.ts_eeg{j});
spikes2.speed{j} = interp1(animal.time,animal.speed,spikes2.times{j});
if sum(spikes2.speed{j} > 10)> preferences.theta.min_spikes % only calculated if the unit has above min_spikes (default: 500)
Expand Down
108 changes: 108 additions & 0 deletions docs/datastructure/io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
layout: default
title: Data structure and format
parent: Data structure
nav_order: 2
---
# Data loaders
{: .no_toc}

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

## Raw data
CellExplorer supports raw binary data files (.dat files). This format is also supported by IntanTech, OpenEphys, KiloSort, Phy, NeuroSuite, Spyking Circus, NeuroSuite, Klustakwik, and many other tools.

data = LoadBinary

## LFP data
CellExplorer also uses a basename.lfp file - A low-pass filtered and down-sampled raw data file for lfp analysis (for efficient data analysis and data storage; typically down-sampled to 1250Hz). The lfp file is automatically generated in the pipeline from the raw data file - using the script ce_LFPfromDat). The sampling rate is specified in the session struct (session.extracellular.srLfp). The LFP file has the same channel count and scaling as the dat file.

data = LoadBinary

## General functions
loadStruct

saveStruct
saveStruct(chanCoords,'channelInfo','session',session);


## Analog traces

loadIntanAnalog

## Digital data

loadIntanDigital

loadOpenEphysDigital
## Session metadata
sessionTemplate
loadSession
gui_session


The session struct can be generated using the sessionTemplate.m and inspected with gui_session.m. The basename.session.mat files should be stored in the basepath. It is structured as defined below:


## Spikes
A MATLAB struct spikes stored in a .mat file: basename.spikes.cellinfo.mat. It can be generated with loadSpikes.m. The processing module ProcessCellMetrics.m used the script loadSpikes.m, to automatically load spike-data from either KiloSort, Phy or Neurosuite and saves it to a spikes struct. basename.spikes.cellinfo.mat is saved to the basepath. The struct has the following fields:

loadSpikes.m
spikes = loadSpikes('session',session);
spikes = getWaveformsFromDat(spikes,session);


Load spikes takes spike sorted formats from various algorithms:

## Monosynaptic connections
mono_res = ce_MonoSynConvClick(spikes,'includeInhibitoryConnections',true/false); % detects the monosynaptic connections
gui_MonoSyn(mono_res) % Shows the GUI for manual curation


## Cell metrics
loadCellMetrics

bsasepaths = {'sessionName1','sessionName2','sessionName3'};
cell_metrics = loadCellMetricsBatch('basepaths',bsasepaths);

nwb = saveCellMetrics2nwb(cell_metrics,nwb_file);

saveCellMetrics(cell_metrics,nwb_file)

cell_metrics = ProcessCellMetrics('session', session);


## Events
This is a data container for event data. A MATLAB struct eventName stored in a .mat file: basename.eventName.events.mat with the following fields:

loadEvents

## Manipulations


## Channels

## Time series

StateExplorer

## States

## Behavior
This is a data container for behavioral tracking data. A MATLAB struct behaviorName stored in a .mat file: basename.behaviorName.behavior.mat with the following fields:

loadOptitrack

## Trials
A MATLAB struct trials stored in a .mat file: basename.trials.behavior.mat. The trials struct is a special behavior struct centered around behavioral trials. trials has the following fields:


## Firing rate maps
This is a data container for firing rate map data. A MATLAB struct ratemap containing 1D or linearized firing rat maps, stored in a .mat file: basename.ratemap.firingRateMap.mat. The firing rate maps have the following fields:

## Intracellular time series
This is a data container for intracellular recordings. Any MATLAB struct intracellularName containing intracellular data would be stored in a .mat file: basename.intracellularName.intracellular.mat. It contains fields inherited from timeSeries with the following fields

0 comments on commit 93fa9f2

Please sign in to comment.