/
cell_type_proportions.m
94 lines (82 loc) · 4.07 KB
/
cell_type_proportions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [S1, S2, ID1, ID2] = cell_type_proportions(vpcells, animals, celltype, resdir, sourcedir)
%CELL_TYPE_PROPORTIONS Proportion of bursting and rhythmic neurons in individual animals.
% CELL_TYPE_PROPORTIONS(ANIMALS, CELLTYPE, RESDIR, SOURCEDIR) shows the proportion
% of bursting (CELLTYPE = 'bursting') or rhythmic (CETTYPE = 'rhythmic')
% neurons in cell populations recorded from ANIMALS. Source data is loaded from subfolders of
% SOURCEDIR. Results are visualized on a pie chart. Results are saved in RESDIR.
%
% See also CELLID2TAGS and PIE.
% Panna Hegedus, Balazs Hangya
% Institute of Experimental Medicine
% hangya.balazs@koki.mta.hu
% Code review: BH 10/16/20
% Directories
if ~isfolder(resdir)
mkdir(resdir);
end
switch celltype % select neurons
case 'bursting' % select bursting neurons
load(fullfile(sourcedir, '\ACG_matrices.mat')); % load ACG matrices (generated by vpacg.m)
type_cells = cellids(BurstIndex>0.2); % bursting neurons
nontype_cells = cellids(BurstIndex<=0.2); % nonbursting neurons
labels = {'bursting', 'non-bursting'}; % label for later plotting
case 'rhythmic' % select rhythmic neurons
resdir_acg_rhythmic = fullfile(getpref('cellbase','datapath'),'figS4','acg_rhythmic'); % save acg
resdir2 = fullfile(getpref('cellbase','datapath'),'figS4','acg_nonrhythmic'); % save acg
resdir3 = fullfile(getpref('cellbase','datapath'),'figS4','psth_rhythmic'); % for testing
acgdir = fullfile([getpref('cellbase','datapath') '\_paper_figs\code_review3\'],'vpacg');
responsedir = fullfile(getpref('cellbase','datapath'),'VP','vpresponsesorter5');
% Rhytmicity - calculate Beta and Gamma Index
[phasic_cells, BetaIndex, GammaIndex, isbeta, isgamma] = pr_freq_detection_VP(vpcells,resdir_acg_rhythmic,resdir2,resdir3,acgdir,responsedir);
beta_cells = phasic_cells(isbeta==1); % beta cells
gamma_cells = phasic_cells(isgamma==1); % gamma cells
type_cells = [beta_cells gamma_cells]; % rhythmic neurons
type_cells = unique(type_cells); % beta/gamma may overlap
nontype_cells = setdiff(vpcells,type_cells); % non-rhythmic VP neurons
labels = {'rhythmic', 'non-rhythmic'}; % label for later plotting
case 'sync'
resdir = sourcedir; % directory for generated images
ccg_resdir = fullfile(resdir,'vpccg'); % results directory
[type_cells, nontype_cells] = sync_pair_responses(vpcells,ccg_resdir); % synchronous and nonsynchronous cell groups (for pie chart)
labels = {'synchronous', 'asynchronous'}; % label for later plotting
end
[type_cells_per_animal, nontype_cells_per_animal] = deal(nan(1,length(animals)));
for a = 1:length(animals)
aID = animals{a};
ID1.(aID) = [];
ID2.(aID) = [];
type_cellcount = 0;
for b = 1:length(type_cells) % count bursting neurons per animal
[ratname,~,~,~] = cellid2tags(type_cells{b});
if strcmp(ratname,aID)
type_cellcount = type_cellcount + 1;
ID1.(aID) = [ID1.(aID) {type_cells{b}}];
end
end
type_cells_per_animal(a) = type_cellcount;
S1.(aID) = type_cellcount;
nontype_cellcount = 0;
for c = 1:length(nontype_cells) % count nonbursting neurons per animal
[ratname,~,~,~] = cellid2tags(nontype_cells{c});
if strcmp(ratname,aID)
nontype_cellcount = nontype_cellcount+1;
ID2.(aID) = [ID2.(aID) {nontype_cells{c}}];
end
end
nontype_cells_per_animal(a) = nontype_cellcount;
S2.(aID) = nontype_cellcount;
end
% Plot pie charts
for p = 1:length(animals)
subplot(2,3,p)
X = [type_cells_per_animal(p) nontype_cells_per_animal(p)];
pie_handle = pie(X, labels);
title(animals{p});
end
% Save pie chart
fnm = fullfile(resdir,[celltype '_pie_chart.jpg']); % jpg
fnm2 = fullfile(resdir,[celltype '_pie_chart.fig']); % fig
saveas(gcf,fnm);
set(gcf, 'renderer', 'painters')
saveas(gcf,fnm2);
close(gcf)