Skip to content

Commit

Permalink
Uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
PerezOrtegaJ committed May 2, 2019
1 parent e3f7de9 commit 52056be
Show file tree
Hide file tree
Showing 101 changed files with 7,332 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions CCidx2_JP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
% Cluster Connectivity index 2
% Get cluster connectivity index of neuronal groups of peaks.
% Mean of the groups' connectivity index
% (This is an idea of Jesús E. Pérez-Ortega, José Bargas, et al.)
%
% [CCI] = CCidx2_JP(g,Xp,idx)
%
% Inputs
% g = number of groups
% Xp = binary data as matrix PxC (P = #peaks, C = #cells)
% idx = indexes of group to which each data point belongs
%
% Outputs
% CCI = Connectivity index
%
% ..:: by Jesús E. Pérez-Ortega ::.. Mar-2012

function [CCI] = CCidx2_JP(g,Xp,idx)

P=size(Xp,1);
C_intra=zeros(g,1); % connectivity inter-group
single=0; % single neuronal vector
for i=1:g
clust = find(idx==i);
PM=Xp(clust,:);
idxPM=find(sum(PM,1));
PM=PM(:,idxPM);
if size(PM,1)==1 % if single not be taken into account
C_intra(i,1)=0; % unlike with the first version: 1 instead of 0
single=single+1;
else
C_intra(i,1)=CI_JP(PM);
end
end
% disp(C_intra)
CCI=sum(C_intra)/g; % unlike with the first version: g instead of (g-single)



15 changes: 15 additions & 0 deletions Change_Names_MEA_Channels.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
% Exclusivo para MEAs de 128 canales

function new_channels = Change_Names_MEA_Channels(channels)

ch=channels(:,1);
ends=[find(diff(ch)~=0); length(ch)];
inis=[1; ends(1:end-1)+1];

for i=1:length(inis)
new(inis(i):ends(i))=i;
end

channels(:,1)=new;
new_channels=channels;
end
13 changes: 13 additions & 0 deletions Circle_Mask.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function mask = Circle_Mask(image_size,xy_center,radius)
% Create a circle mask
%
% Jesus Perez-Ortega, [email protected]
% March, 2019

% Get size of image
h = image_size(1);
w = image_size(2);
[x,y] = meshgrid(1:w,1:h);

% Get mask
mask = sqrt((x-xy_center(1)).^2 + (y-xy_center(2)).^2) < radius;
62 changes: 62 additions & 0 deletions ClustIdx_JP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
% Clustering indexes
% Get indexes for evaluating clustering from hierarchical cluster tree
%
% [ClustIdx g] = ClustIdx_JP(Tree, SimOrXpeaks, Metric, numFig)
%
% Inputs
% Tree = hierarchical cluster tree
% SimOrXpeaks = Sim, similarity as matrix PxP (P=#peaks) for metrics Dunn &
% Contrast; Xpeaks, peaks vectors as matrix PxC for metrics
% Connectivity & Davies
% (P = #peaks; C=#cells)
% Metric = index to compute ('Dunn','Connectivity','Davies','Contrast')
% numFig = number of the figure to plot
%
% Output
% ClustIdx = clustering indexes of 'Metric' from 2 to 10 groups
% g = best number of groups according to the index selected
%
% ..:: by Jesús E. Pérez-Ortega ::.. Jun-2012
% modified March-2018

function [ClustIdx g] = ClustIdx_JP(tree_or_data,similitud,method,num_fig, clust_method,groups)

if(nargin==5)
groups=2:30;
end

dist=1-similitud;
j=1;
for i=groups
switch(clust_method)
case 'hierarchical'
T = cluster(tree_or_data,'maxclust',i);
case 'kmeans'
T = kmeans(tree_or_data,i);
end
g=max(T);

switch(method)
case 'Dunn'
ClustIdx(j)=DunnIdx_JP(g,dist,T);
case 'Connectivity'
ClustIdx(j)=CCidx2_JP(g,similitud,T);
case 'Davies'
ClustIdx(j)=DaviesIdx_JP(g,similitud,T);
case 'Contrast'
ClustIdx(j)=ContrastIdx_JP(g,similitud,T);
otherwise
method='Dunn';
ClustIdx(j)=DunnIdx_JP(g,dist,T);
end
j=j+1;
end
figure(num_fig)
plot(groups,ClustIdx)
hold on

[gIdx,g]=max(ClustIdx);

plot(groups(g),gIdx,'*r')
hold off
title([method '''s index (' num2str(groups(g)) ' groups recommended)'])
89 changes: 89 additions & 0 deletions Compare_Times.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
% Times comparison Manual VS Auto

function [coincidence,diffs] = Compare_Times(times_1,times_2,coactivity)
if(nargin==2)
coactivity=[];
end

n_1=size(times_1,1);
n_2=size(times_2,1);
Times_1=times_1(:);
Times_2=times_2(:);

Y_manual=1.5*ones(length(Times_1),1);
Y_auto=1.5*ones(length(Times_2),1);

% Comparison
n_coincidence=0;
auto_extra=0;
manual_extra=0;
auto_actual=1;
coincidence=[];
for i=1:n_1
i_m=times_1(i,1);
f_m=times_1(i,2);

for j=auto_actual:n_2
i_a=times_2(j,1);
f_a=times_2(j,2);

% If data is in the same place
%if(i_m>=i_a && i_m<=f_a || f_m>=i_a && f_m<=f_a || i_m<=i_a && f_m>=f_a)
if abs(i_m-i_a)<100
diff_i=i_a-i_m;
diff_f=f_a-f_m;
n_coincidence=n_coincidence+1;
coincidence(n_coincidence,:)=[i_m i_a f_m f_a];
diffs(n_coincidence,:)=[diff_i diff_f];
auto_actual=j+1;
break;
% If are differents
elseif(i_m>f_a)
auto_extra=auto_extra+1;
elseif(f_m<i_a)
manual_extra=manual_extra+1;
auto_actual=j;
break;
end
end
end

% Set_Figure('Errors in initial and final times',[0 0 1000 600]);
% subplot(2,1,1)
% hist(diffs(:,1))
% xlabel('time (ms)')
% title(['Error distribution in initial times (mean ' num2str(mean(diffs(:,1)))...
% ' std ' num2str(std(diffs(:,1))) ')'])
% subplot(2,1,2)
% hist(diffs(:,2))
% xlabel('time (ms)')
% title(['Error distribution in final times (mean ' num2str(mean(diffs(:,2)))...
% ' std ' num2str(std(diffs(:,2))) ')'])

% s=hgexport('readstyle','A_default');
% s.Format = 'png';
% hgexport(gcf,'Histograms.png',s);

if (coactivity)
% Plot
Set_Figure('Coactivity with initial and final times',[0 0 1000 300]);
plot(coactivity,'k'); hold on
plot(Times_1,Y_manual,'or')
plot(Times_2,Y_auto,'xb')
legend({'Coactivity','manual','auto'})

Y_coincidence=2.5*ones(n_coincidence,1);
% Plot manual
plot(coincidence(:,1),Y_coincidence,'og')
plot(coincidence(:,3),Y_coincidence,'og')
% Plot auto
plot(coincidence(:,2),Y_coincidence,'xg')
plot(coincidence(:,4),Y_coincidence,'xg')

title(['manual: ' num2str(length(times_1)) ' ( ' num2str(manual_extra) ' extras) - auto: ' num2str(length(times_2)) ' ( ' num2str(auto_extra) ' extras)'])

% s=hgexport('readstyle','A_default');
% s.Format = 'png';
% hgexport(gcf,'Coactivity with times.png',s);
end
end
38 changes: 38 additions & 0 deletions ContrastIdx_JP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
% Contrast index
% Get the Contrast index for g groups given a similarity matrix.
% (Michelson contrast 1927, Plenz 2004)
%
% [CstIdx] = ContrastIdx_JP(g,sim,idx)
%
% Inputs
% g = number of groups
% sim = similarity as matrix PxP (P = #peaks)
% idx = indexes of group to which each data point belongs
%
% Outputs
% CstIdx = Contrast index

% ..:: by Jesús E. Pérez-Ortega ::.. April-2012

function [CstIdx] = ContrastIdx_JP(g,sim,idx)

simC=sim-diag(diag(sim));

s_i=0;
s_o=0;
p_i=0;
p_o=0;
for i=1:g
g_i=find(idx==i);
g_o=find(idx~=i);

s_i=s_i+sum(sum(simC(g_i,g_i))); % sum intra-group
s_o=s_o+sum(sum(simC(g_i,g_o))); % sum others

p_i=p_i+numel(g_i)^2;
p_o=p_o+numel(g_i)*numel(g_o);
end
Di=s_i/p_i;
Do=s_o/p_o;

CstIdx=(Di-Do)/(Di+Do);
45 changes: 45 additions & 0 deletions DaviesIdx_JP.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
% Davies-Bouldin Index
% Get the Davies-Bouldin Index for g groups given a distance matrix.
%
% [DBI] = DaviesIdx_JP(g,dist,idx)
%
% Inputs
% g = number of groups
% Xp = binary data as matrix PxC (P = #peaks, C = #cells)
% dis = square distance matrix
% idx = indexes of group to which each data point belongs
%
% Outputs
% DBI = Davies-Bouldin index
%
% ..:: by Jesús E. Pérez-Ortega ::.. Mar-2012

function [DBI] = DaviesIdx_JP(g,Xp,idx)

db=zeros(g);
for i=1:g-1

g_i=find(idx==i); % index of ith group
c_i=mean(Xp(g_i,:),1); % centroid of ith group

c_i_rep=repmat(c_i,numel(g_i),1);
s_i=mean(sqrt(sum((c_i_rep-Xp(g_i,:)).^2,2))); % standard deviation of ith group

for j=i+1:g

g_j=find(idx==j); % index of jth group
c_j=mean(Xp(g_j,:)); % centroid of ith group
c_j_rep=repmat(c_j,numel(g_j),1);
s_j=mean(sqrt(sum((c_j_rep-Xp(g_j,:)).^2,2))); % standard deviation of ith group

d_ij=sqrt(sum((c_i-c_j).^2)); % Distance Between centroids

db(i,j)=(s_i+s_j)/d_ij;
db(j,i)=(s_i+s_j)/d_ij;
end
end

DBI=sum(max(db))/g;



15 changes: 15 additions & 0 deletions Delete_Consecutive_Coactivation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
% Delete consecutive coactivation patterns from raster
%
% By Jesús E. Pérez-Ortega Aug-2018

function [short_raster indices]= Delete_Consecutive_Coactivation(raster)
same=squareform(pdist(double(raster'),'hamming'),'tomatrix')==0;
d=diff(same);
j=1; indices=1;
while(~isempty(j))
idx=find(d(j:end,j)==-1,1,'first');
j=j+idx;
indices=[indices j];
end
short_raster=raster(:,indices);
end
15 changes: 15 additions & 0 deletions Delete_Raster_Activity_Between_Trials.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
% Get the raster without spurious activity (between trials)
%
% Pérez-Ortega Jesús - July 2018

function raster_corrected = Delete_Raster_Activity_Between_Trials(raster,offset,time,trials)

trial_time=time+offset;
offset=offset+1;
idx=[];
for i=1:trials
idx=[idx (offset:trial_time)+trial_time*(i-1)];
end
raster_corrected=raster(:,idx);

end
25 changes: 25 additions & 0 deletions Divide_Peaks.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% Divide peak indices in bin
%
% By Jesús Pérez-Ortega april-2018

function peak_indices_divided = Divide_Peaks(peak_indices, bin)
peak_indices_divided=peak_indices;
peaks=max(peak_indices);
peak_i=1;
for i=1:peaks
peak=find(peak_indices==i);
if(~isempty(peak))
n_divs=ceil(length(peak)/bin);
for j=1:n_divs
ini=peak((j-1)*bin+1);
if(j==n_divs)
fin=peak(end);
else
fin=peak(j*bin);
end
peak_indices_divided(ini:fin)=peak_i;
peak_i=peak_i+1;
end
end
end
end
Loading

0 comments on commit 52056be

Please sign in to comment.