Skip to content

Commit

Permalink
Changing folders
Browse files Browse the repository at this point in the history
  • Loading branch information
hmogensen committed Jan 30, 2015
1 parent 5c2b3d3 commit 09d0db4
Show file tree
Hide file tree
Showing 22 changed files with 556 additions and 21 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
Waveform detection tool:
==========================

In general terms, this is a program for postprocesing analysis of recorded data in one or several analog or digital channels.
More specifically, it has been customized to our needs (data recorded in Spike2 from electrophysiological experiments). It can be modified to be used for other purposes.
>> help sc
Normal usage:

>> sc
Eeg analysis

>> help Eeg
Folder structure:
=================

The classes in the following folders are recreated each time the program is run - no need for backwards compatibility. All files here should be called from sc.m function, otherwise they should be moved to folder /util or folder /customized. Use function customized/test_depency.m to check which files are in use.

* /channelaxes
* /enumtypes
* /functions
* /layout
* /modify_threshold
* /panelcomponents
* /panels
* /viewers

The classes in the /sensorimotor folder have to be backward and forward compatible

/third-party contains files from Mathworks file sharing site

/util contains generic functions (functions that are useful to a 'general public')

/customized contains functions that are not called by the sc.m function, but are nevertheless useful for this project - though they are not general enough to be of public use

The program has a graphical user interface so it does not require knowledge of Matlab. Start by typing sc -help in the command prompt.
Binary file removed User manual 1.0.5.rtf
Binary file not shown.
175 changes: 175 additions & 0 deletions customized/NcCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
classdef NcCell < ObjectList & NcParent
methods
function add(obj,item)
add@ObjectList(obj,item);
item.parent = obj;
end
function ret = time(obj)
if ~obj.N
ret = [];
else
ret = (0:(obj.N-1))*obj.dt;
end
end
function ret = time_binned(obj)
ret = ((0:floor((obj.N-1))/obj.binwidth)+.5)*obj.binwidth*obj.dt;
end
function ret = N(obj)
ret = 0;
for k=1:obj.n
if obj.get(k).n && obj.get(k).N
ret = obj.get(k).N;
break;
end
end
end
function ret = label_binned(obj,eegopt)
ret = {};
ind = 0;
for k=1:obj.n
child = obj.get(k);
label_binned = child.label_binned(eegopt);
inds = ind + (1:length(label_binned));
ret(inds) = label_binned;
ind = inds(end);
end
end

function plotdata(obj,removeartifacts,eegopt)
for k=1:obj.n
figure(k)
clf
obj.get(k).plotdata(removeartifacts,eegopt);
set(gcf,'Color',[1 1 1])
set(gcf,'Name',obj.get(k).label);
end
end
function plotall(obj,removeartifacts,eegopt)
clf
for k=1:obj.n
sc_square_subplot(obj.n,k)
cla
nn = obj.get(k).plotall(removeartifacts,eegopt);
set(gca,'FontSize',14)
axis tight
title(sprintf('%s (N = %i)',obj.get(k).label,nn));
end
set(gcf,'Color',[1 1 1])
end
function plotavg(obj,removeartifacts,eegopt)
clf
hold on
for k=1:obj.n
obj.get(k).plotavg(removeartifacts,eegopt);
end
axis tight
legend(obj.vals('label'));
set(gcf,'Color',[1 1 1])
set(gca,'FontSize',14)
title('Average membrane potential')
xlabel('Time [s]');
ylabel('Voltage [mV]')
end
function binwiseanova(obj,removeartifacts,eegopt)
switch eegopt
case 'all'
keepsweeps = true(size(obj.rising_edge));
case 'rising'
keepsweeps = obj.rising_edge;
case 'no_rising'
keepsweeps = ~obj.rising_edge;
otherwise
error('Uknown option: %s\n',eegopt);
end
if ~removeartifacts
keeptimes = true(size(obj.time_binned));
else
keeptimes = ~any(cell2mat(obj.vals('artifacts_binned')'));
end
time_binned = obj.time_binned;
p = nan(size(time_binned(keeptimes)));
v_binned = obj.v_binned(keeptimes,keepsweeps);
label_binned = obj.label_binned(eegopt);
for k=1:length(p)
p(k) = anova1(v_binned(k,:),label_binned,'off');
end
semilogy(1e3*time_binned(keeptimes),p,'s');
set(gcf,'Color',[1 1 1])
set(gca,'FontSize',14)
xlabel('Time(ms)');
ylabel('p-value');
title(sprintf('P-value for ANOVA, N = %i',nnz(keepsweeps)));
yl = ylim;
ylim([yl(1) 1]);
end
function doclassify(obj,removeartifacts,eegopt)
if ~removeartifacts
keeptimes = true(size(obj.time_binned));
else
keeptimes = ~any(cell2mat(obj.vals('artifacts_binned')'));
end
times = obj.time_binned;
times = times(keeptimes);
keeptimes = find(keeptimes);
correct = zeros(size(keeptimes));
for k=1:length(times)
fprintf('%i out of %i\n',k,length(times));
sample = [];
training = [];
group = [];
correct_answer = {};
for j=1:obj.n
type = obj.get(j);
switch eegopt
case 'all'
keepsweeps = true(size(type.rising_edge));
case 'rising'
keepsweeps = type.rising_edge;
case 'no_rising'
keepsweeps = ~type.rising_edge;
otherwise
error('Uknown option: %s\n',eegopt);
end
v_binned = type.v_binned();
v_binned = v_binned(keeptimes(1:k),keepsweeps);
labels = type.label_binned(eegopt);
n = size(v_binned,2);
indexes = randperm(n);
top = ceil(5*n/6);
training_ind = indexes(1:top);
sample_ind = indexes(top+1:end);
if isempty(sample_ind)
error('No sample set')
end
training = [training; v_binned(:,training_ind)'];
group = [group; labels(training_ind)'];
sample = [sample; v_binned(:,sample_ind)'];
correct_answer = [correct_answer; labels(sample_ind)'];
end
class = classify(sample,training,group,'quadratic');
nbr = 0;
for j=1:length(sample)
if strcmp(class{j},correct_answer{j})
nbr = nbr+1;
end
end
correct(k) = nbr/length(sample);
end
clf
plot(1e3*times,100*correct,'Marker','+')
set(gcf,'Color',[1 1 1])
set(gca,'FontSize',14)
xlabel('Time (ms)');
ylabel('% correct classification')
end
function ret = dt(~)
ret = 1e-5;
end
function ret = binwidth(~)
ret = 1e2;
end
function ret = rising_edge(obj)
ret = cell2mat(obj.vals('rising_edge'));
end
end
end
22 changes: 22 additions & 0 deletions customized/NcChild.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
classdef NcChild < handle
properties
parent
end
properties (Dependent)
time
end
methods
function ret = get.time(obj)
ret = obj.parent.time;
end
function ret = time_binned(obj)
ret = obj.parent.time_binned;
end
function ret = binwidth(obj)
ret = obj.parent.binwidth;
end
function ret = dt(obj)
ret = obj.parent.dt;
end
end
end
14 changes: 14 additions & 0 deletions customized/NcParent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef NcParent < handle
methods (Abstract)
ret = vals(obj,property)
end
properties (Dependent)
v_binned
end
methods
function ret = get.v_binned(obj)
ret = cell2mat(obj.vals('v_binned'));
end

end
end
18 changes: 18 additions & 0 deletions customized/NcSweep.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
classdef NcSweep < NcChild
properties
v
rising_edge
end
properties (Dependent)
v_binned
end
methods
function ret = get.v_binned(obj)
n = length(obj.time_binned);
ret = zeros(n,1);
for k=1:n
ret(k) = mean(obj.v((k-1)*obj.binwidth+(1:obj.binwidth)));
end
end
end
end
Loading

0 comments on commit 09d0db4

Please sign in to comment.