Skip to content

Commit

Permalink
horribly hacky fix for broken amplitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
sg-s committed Nov 3, 2014
1 parent 30c3663 commit 3c6ad8d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 13 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ Spike sorting for Kontroller

`spikesort` can read data generated by [Kontroller](https://github.com/sg-s/kontroller) and help you sort spikes from multiple neurons in a single extracellular voltage recording. This was developed for sorting the action potentials of Drosophila Olfactory Receptor Neurons, but would probably work in other contexts.

## Features

### Fast Filter and Find Spikes in trace

###

## Installation

If you have git installed:
If you have `git` installed:

````
git clone [email protected]:sg-s/spikesort.git
````

or use [this link](https://github.com/sg-s/spikesort/archive/master.zip).
Expand Down Expand Up @@ -55,7 +60,6 @@ Both types of plugins are functions that can have any inputs whatsoever -- provi

````matlab
function R = ssdm_my_awesome_plugin(V,foo,bar)
````

and `spikesort` will intelligently give your function the correct variables in the correct order (spikesort reads your function and figures this out).
Expand Down
71 changes: 61 additions & 10 deletions spikesort.m
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,55 @@ function loadfilecallback(~,~)
set(discard_control,'Enable','on');
set(menubuttons(4),'Enable','on')

% check for amplitudes
waitbar(.7,load_waitbar,'Checking to see amplitude data exists...')
% check if we have spike_amplitude data
if length(spikes)
for i = 1:length(spikes)
for j = 1:width(spikes(i).A)
haz_data = 0;
if length(spikes(i).A(j,:)) > 2
if isfield(spikes,'discard')
if length(spikes(i).discard) < j
haz_data = 1;
else
if ~spikes(i).discard(j)
haz_data = 1;
end
end
else
haz_data = 1;
end
end
if haz_data
recompute = 0;
if width(spikes(i).amplitudes_A) < j
recompute = 1;
spikes(i).amplitudes_A = [];
spikes(i).amplitudes_B = [];
elseif length(spikes(i).amplitudes_A(j,:)) < length(spikes(i).A(j,:))
spikes(i).amplitudes_A = [];
spikes(i).amplitudes_B = [];
recompute = 1;

end
if recompute
A = spikes(i).A(j,:);

spikes(i).amplitudes_A(j,:) = sparse(1,length(A));
spikes(i).amplitudes_B(j,:) = sparse(1,length(A));
V = data(i).voltage(j,:);
deltat = 1e-4; % hack, will be removed in future releases
spikes(i).amplitudes_A(j,find(A)) = ssdm_1DAmplitudes(V,deltat,find(A));
B = spikes(i).B(j,:);
spikes(i).amplitudes_B(j,find(B)) = ssdm_1DAmplitudes(V,deltat,find(B));
end
end

end
end
end

% clean up
close(load_waitbar)
end
Expand Down Expand Up @@ -901,13 +950,15 @@ function reduce_dimensions_callback(~,~)

% save them
spikes(ThisControlParadigm).A(ThisTrial,:) = sparse(1,length(time));
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = sparse(1,length(time));
spikes(ThisControlParadigm).A(ThisTrial,A) = 1;
spikes(ThisControlParadigm).B(ThisTrial,:) = sparse(1,length(time));
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = sparse(1,length(time));
spikes(ThisControlParadigm).B(ThisTrial,B) = 1;

% also save spike amplitudes
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,B);
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,A) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,B) = ssdm_1DAmplitudes(V,deltat,B);

% save them
save(strcat(PathName,FileName),'spikes','-append')
Expand Down Expand Up @@ -944,13 +995,13 @@ function modify(p)
[~,loc] = min(V(floor(p(1)-s:p(1)+s)));
spikes(ThisControlParadigm).A(ThisTrial,-s+loc+floor(p(1))) = 1;
A = find(spikes(ThisControlParadigm).A(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,A) = ssdm_1DAmplitudes(V,deltat,A);
elseif get(mode_new_B,'Value')==1
% snip out a small waveform around the point
[~,loc] = min(V(floor(p(1)-s:p(1)+s)));
spikes(ThisControlParadigm).B(ThisTrial,-s+loc+floor(p(1))) = 1;
B = find(spikes(ThisControlParadigm).B(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,B);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,B) = ssdm_1DAmplitudes(V,deltat,B);
elseif get(mode_delete,'Value')==1
% find the closest spike
Aspiketimes = find(spikes(ThisControlParadigm).A(ThisTrial,:));
Expand All @@ -964,12 +1015,12 @@ function modify(p)
[~,closest_spike] = min(dA);
spikes(ThisControlParadigm).A(ThisTrial,Aspiketimes(closest_spike)) = 0;
A = find(spikes(ThisControlParadigm).A(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,A) = ssdm_1DAmplitudes(V,deltat,A);
else
[~,closest_spike] = min(dB);
spikes(ThisControlParadigm).B(ThisTrial,Bspiketimes(closest_spike)) = 0;
B = find(spikes(ThisControlParadigm).B(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,B);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,B) = ssdm_1DAmplitudes(V,deltat,B);
end
elseif get(mode_A2B,'Value')==1
% find the closest A spike
Expand All @@ -979,9 +1030,9 @@ function modify(p)
spikes(ThisControlParadigm).A(ThisTrial,Aspiketimes(closest_spike)) = 0;
spikes(ThisControlParadigm).B(ThisTrial,Aspiketimes(closest_spike)) = 1;
A = find(spikes(ThisControlParadigm).A(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,A) = ssdm_1DAmplitudes(V,deltat,A);
B = find(spikes(ThisControlParadigm).B(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,B);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,B) = ssdm_1DAmplitudes(V,deltat,B);

elseif get(mode_B2A,'Value')==1
% find the closest B spike
Expand All @@ -991,9 +1042,9 @@ function modify(p)
spikes(ThisControlParadigm).A(ThisTrial,Bspiketimes(closest_spike)) = 1;
spikes(ThisControlParadigm).B(ThisTrial,Bspiketimes(closest_spike)) = 0;
A = find(spikes(ThisControlParadigm).A(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,A);
spikes(ThisControlParadigm).amplitudes_A(ThisTrial,A) = ssdm_1DAmplitudes(V,deltat,A);
B = find(spikes(ThisControlParadigm).B(ThisTrial,:));
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,:) = ssdm_1DAmplitudes(V,deltat,B);
spikes(ThisControlParadigm).amplitudes_B(ThisTrial,B) = ssdm_1DAmplitudes(V,deltat,B);
end

% update plot
Expand Down

0 comments on commit 3c6ad8d

Please sign in to comment.