Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional post-processing step for duplicate spike removal #234

Merged
merged 9 commits into from
Oct 28, 2020

Conversation

agbondy
Copy link
Contributor

@agbondy agbondy commented Sep 17, 2020

I added a function "remove_ks2_duplicate_spikes" which takes in a "rez" structure during post-processing and removes spikes that are likely double-counted, based on their spatiotemporal overlap with other spikes. Specifically, it two spikes occur within less than X ms and belong to templates with peaks less than Y um apart, the spike belonging to the smaller-amplitude template is removed. X is 0.5ms by default, and Y is 100 um by default. We have implemented this in our kilosort master script for some time and I thought it may be useful for others. Right now, it's commented out so as not to disrupt the default behavior but could be uncommented to enable it (or in future enabled programmatically with a flag of some kind).

One other minor change in this PR is the addition of a 1D drift map to the figure illustrating drift in the recording. I find it a useful visual tool in addition to the distance matrices. It plots batch position on the 1D embedding performed already by ks2.
untitled

1. remove_ks2_duplicate_spikes - removes duplicate spikes resulting from multiple templates explaining variance from a single waveform
optional (off by default) step for removing double-counted spikes
% OPTIONAL: remove double-counted spikes - solves issue in which individual spikes are assigned to multiple templates.
% See issue 29: https://github.com/MouseLand/Kilosort2/issues/29
%rez = remove_ks2_duplicate_spikes(rez);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out by default

@@ -0,0 +1,52 @@
function rez = remove_spikes(rez,remove_idx,label,varargin)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function encapsulates the code for removing spikes from a "rez" structure, so that it can easily be shared by set_cutoff.m and remove_ks2_duplicated_spikes.m. It also adds a field to the rez structure called "removed" which saves the removed spikes and provides a reason why they were removed in postprocessing.

[ccbsort, iorig] = sortBatches2(ccb0);
[ccbsort, iorig, xs] = sortBatches2(rez.ccb);
rez.iorig = gather(iorig);
rez.ccbsort = gather(ccbsort);

% some mandatory diagnostic plots to understand drift in this dataset
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plot the 1D drift map

…avior was to cause harder to decipher errors down the line).
@marius10p marius10p merged commit d703473 into MouseLand:master Oct 28, 2020
@marius10p
Copy link
Contributor

Great, thanks Adrian!

cnuahs pushed a commit to cnuahs/Kilosort that referenced this pull request Mar 9, 2024
optional post-processing step for duplicate spike removal

Former-commit-id: d703473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants