-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunQCsummary.m
297 lines (266 loc) · 10.5 KB
/
runQCsummary.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
function runQCsummary(path)
%Produces several plots to visualize parameters and outcomes of the quality
%control done by runPipeline()
%
% Inputs:
%
% path - string or character array specifiying location at which files
% and folders were generated by runPipeline()
%
% Creates following figures in the QC subfolder:
%
% QC_RMSE - First four subplots compares RMSE values pre vs.
% post-stimulus in certain sweeps across the recording.
% The remaing plots show long term RMSE in dependence of
% the short term RMSE
%
% QC_XX_histograms - Relative frequency histograms for all QC parameter
% in addition capacitance compensation
%
% QCheatmap - Greyscale heatmap of relative frequency of sweep
% removal by the sweep wise QC broken down by QC criteria
%
%% Start
run(fullfile(path,'loadParams.m')); p= ans; tables = struct();
path=(fullfile(path,'output'));
files = dir(fullfile(path,'QC'));
files = {files(contains({files.name}, 'values')).name};
for c = 1:length(files)
tables.(['T', num2str(c)]) = readtable(fullfile(path,'QC', files{c}));
if any(tables.(['T', num2str(c)]).bridge_balance_abs > 100)
tables.(['T', num2str(c)]).bridge_balance_abs = tables.(['T', num2str(c)]).bridge_balance_abs/1e6;
end
if any(tables.(['T', num2str(c)]).CapaComp <1 & tables.(['T', num2str(c)]).CapaComp~=0)
tables.(['T', num2str(c)]).CapaComp = tables.(['T', num2str(c)]).CapaComp*1e12;
end
end
cellTabs = fieldnames(tables);
%% QC_RMSE part 1: Pre vs Post
figure('Position',[622 462 996 445])
subplot(2,4,1)
hold on
for n = 1:length(cellTabs)
plot([1 2],[tables.(['T', num2str(n)]).ltRMSE_pre(find(...
~contains(tables.(['T', num2str(n)]).Protocol,"unknown"),1,'first')) ...
tables.(['T', num2str(n)]).ltRMSE_post(find(~contains(...
tables.(['T', num2str(n)]).Protocol,"unknown"),1,'first'))],'k','linewidth',0.25)
end
plot([1 2],[p.RMSElt p.RMSElt],'r-.','linewidth',1)
xlabel('1st sweep')
ylabel('RMS (long term)')
xticks(1:2)
ylim([0 2.25])
xticklabels({'pre','post'})
subplot(2,4,2)
hold on
for n = 1:length(cellTabs)
Idx = find(~contains(tables.(['T', num2str(n)]).Protocol,"unknown"));
plot([1 2],[tables.(['T', num2str(n)]).ltRMSE_pre(Idx(5)) ...
tables.(['T', num2str(n)]).ltRMSE_post(Idx(5))],'k','linewidth',0.25)
end
plot([1 2],[p.RMSElt p.RMSElt],'r-.','linewidth',1)
xlabel('5th sweep')
ylabel('RMS (long term)')
xticks(1:2)
ylim([0 2.25])
xticklabels({'pre','post'})
subplot(2,4,3)
hold on
for n = 1:length(cellTabs)
Idx = find(~contains(tables.(['T', num2str(n)]).Protocol,"unknown"));
plot([1 2],[tables.(['T', num2str(n)]).ltRMSE_pre(Idx(8)) ...
tables.(['T', num2str(n)]).ltRMSE_post(Idx(8))],'k','linewidth',0.25)
end
plot([1 2],[p.RMSElt p.RMSElt],'r-.','linewidth',1)
xlabel('10th sweep')
ylabel('RMS (long term)')
xticks(1:2)
ylim([0 2.25])
xticklabels({'pre','post'})
subplot(2,4,4)
hold on
for n = 1:length(cellTabs)
Idx = find(~contains(tables.(['T', num2str(n)]).Protocol,"unknown"));
if length(Idx)>=20
plot([1 2],[tables.(['T', num2str(n)]).ltRMSE_pre(Idx(20)) ...
tables.(['T', num2str(n)]).ltRMSE_post(Idx(20))],'k','linewidth',0.25)
end
end
plot([1 2],[p.RMSElt p.RMSElt],'r-.','linewidth',1)
xlabel('20th sweep')
ylabel('RMS (long term)')
xticks(1:2)
ylim([0 2.25])
xticklabels({'pre','post'})
%% %% QC_RMSE part 2: Scatter plots
subplot(2,4,[5,6])
hold on
for n = 1:length(cellTabs)
scatter(tables.(['T', num2str(n)]).stRMSE_pre, ...
tables.(['T', num2str(n)]).ltRMSE_pre,[],[0.5 0.5 0.5], 'MarkerEdgeAlpha',.2)
end
xlim([0 0.25])
ylim([0 0.25])
xlabel('pre RMSE (short term)')
ylabel('pre RMSE (long term)')
subplot(2,4,[7,8])
hold on
for n = 1:length(cellTabs)
scatter(tables.(['T', num2str(n)]).stRMSE_post, ...
tables.(['T', num2str(n)]).ltRMSE_post,[], [0.5 0.5 0.5], 'MarkerEdgeAlpha',.2)
end
xlim([0 0.25])
ylim([0 0.25])
xlabel('post RMSE (short term)')
ylabel('post RMSE (long term)')
exportgraphics(gcf,fullfile(path, 'QC', 'QC_RMSEplots.png'))
%%
RigTags = unique(cellfun(@(x) x(5:6), files,'UniformOutput',false));
if length(RigTags) < 10
RigTags{length(RigTags)+1} = 'Total';
RigQC = struct();
Allen = false;
else
RigTags = {'Total'};
Allen = true;
end
for r=1:length(RigTags)
RigQC.(char(RigTags(r))) = table();
RigQC.([char(RigTags(r)),'_I']) = [];
RigQC.([char(RigTags(r)),'_BB']) = [];
RigQC.([char(RigTags(r)),'_CC']) = [];
end
for t = 1:length(cellTabs)
RigQC.Total = [RigQC.Total; tables.(['T', num2str(t)])];
RigQC.Total_I = [RigQC.Total_I; max(tables.(['T', num2str(t)]).holdingI)];
RigQC.Total_BB =[RigQC.Total_BB; max(tables.(['T', num2str(t)]).bridge_balance_abs)];
RigQC.Total_CC = [RigQC.Total_CC; max(tables.(['T', num2str(t)]).CapaComp)];
if ~Allen
RigQC.(files{t}(5:6)) = [RigQC.(files{t}(5:6)); tables.(['T', num2str(t)])];
RigQC.([files{t}(5:6), '_I']) = [RigQC.([files{t}(5:6), '_I']); ...
max(tables.(['T', num2str(t)]).holdingI)];
RigQC.([files{t}(5:6), '_BB']) = [RigQC.([files{t}(5:6), '_BB']); ...
max(tables.(['T', num2str(t)]).bridge_balance_abs)];
RigQC.([files{t}(5:6), '_CC']) = [RigQC.([files{t}(5:6), '_CC']); ...
max(tables.(['T', num2str(t)]).CapaComp)];
end
end
for r=1:length(RigTags)
figure('Position',[50 50 1600 900]); set(gcf,'color','w');
subplot(3,4,1)
histogram(RigQC.(char(RigTags(r))).ltRMSE_pre(~isnan(RigQC.(char(RigTags(r))).ltRMSE_pre)),[0:0.1:2],'FaceColor','k','Normalization','probability');
l1 = line([p.RMSElt,p.RMSElt],[0,0.4],'color','r','linewidth',1,'linestyle','--');
l2 = line([0.5,0.5],[0,0.4],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('lt RMS pre-stim')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,2)
histogram(RigQC.(char(RigTags(r))).ltRMSE_post(~isnan(RigQC.(char(RigTags(r))).ltRMSE_post)),[0:0.1:2],'FaceColor','k','Normalization','probability');
l1 = line([p.RMSElt,p.RMSElt],[0,0.4],'color','r','linewidth',1,'linestyle','--');
l2 = line([0.5,0.5],[0,0.4],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('lt RMS post-stim')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,3)
histogram(RigQC.(char(RigTags(r))).stRMSE_pre(~isnan(RigQC.(char(RigTags(r))).stRMSE_pre)),[0:0.025:0.4],'FaceColor','k','Normalization','probability');
l1 = line([p.RMSEst,p.RMSEst],[0,0.7],'color','r','linewidth',1,'linestyle','--');
l2 = line([0.07,0.07],[0,0.7],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('st RMS pre-stim')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,4)
histogram(RigQC.(char(RigTags(r))).stRMSE_post(~isnan(RigQC.(char(RigTags(r))).stRMSE_post)),[0:0.025:0.4],'FaceColor','k','Normalization','probability');
l1 = line([p.RMSEst,p.RMSEst],[0,0.7],'color','r','linewidth',1,'linestyle','--');
l2 = line([0.07,0.07],[0,0.7],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('st RMS post-stim')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,5)
histogram(RigQC.(char(RigTags(r))).diffVrest(~isnan(RigQC.(char(RigTags(r))).diffVrest)),[0:0.25:7],'FaceColor','k','Normalization','probability');
l1 = line([p.maxDiffBwBeginEnd,p.maxDiffBwBeginEnd],[0,0.4],'color','r','linewidth',1,'linestyle','--');
l2 = line([1,1],[0,0.4],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('V rest pre vs post')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4, 6)
histogram(RigQC.([char(RigTags(r)),'_I']),[0:5:120],'FaceColor','k','Normalization','probability');
l1 = line([p.holdingI,p.holdingI],[0,0.7],'color','r','linewidth',1,'linestyle','--');
l2 = line([100,100],[0,0.7],'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('max holding I (pA)')
axis tight
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,7)
histogram(RigQC.(char(RigTags(r))).Vrest(~isnan(RigQC.(char(RigTags(r))).Vrest)),[-90:2:-42],'FaceColor','k','Normalization','probability');
l1 = line([p.maxCellBasLinPot,p.maxCellBasLinPot],[0,0.4],'color','r','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('baseline Vrest (mV)')
axis tight
box off
legend([l1],{'CurrentRun'})
subplot(3,4,8)
histogram(RigQC.(char(RigTags(r))).betweenSweep(~isnan(RigQC.(char(RigTags(r))).betweenSweep)),[-6:0.5:6],'FaceColor','k','Normalization','probability');
l1 = line([p.BwSweepMax,p.BwSweepMax],[0,0.4],'color','r','linewidth',1,'linestyle','--');
l1 = line([-p.BwSweepMax,-p.BwSweepMax],[0,0.4],'color','r','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('Between sweep difference (mV)')
axis tight
box off
legend([l1],{'CurrentRun'})
subplot(3,4,9)
histogram(RigQC.([char(RigTags(r)),'_BB']),[0:1:25],'FaceColor','k','Normalization','probability');
l1 = line([p.bridge_balance,p.bridge_balance],[0,0.3], 'color','r','linewidth',1,'linestyle','--');
l2 = line([20,20],[0,0.3], 'color','b','linewidth',1,'linestyle','--');
ylabel('probability')
xlabel('max bridge ballance')
axis tight
xlim([5 30])
box off
legend([l1, l2],{'CurrentRun', 'AIBS'})
subplot(3,4,10)
histogram(RigQC.([char(RigTags(r)),'_CC']),[0:0.4:10],'FaceColor','k','Normalization','probability');
ylabel('probability')
xlabel('max capacitance neutralization')
axis tight
box off
exportgraphics(gcf,fullfile(path, 'QC', [char(RigTags(r)), 'histograms.png']))
end
%%
files = dir(fullfile(path,'QC'));
files = {files(contains({files.name}, 'pass')).name};
logic_matrix= zeros(length(files),12);
for c = 1:length(files)
tables.(['T', num2str(c)]) = readtable(fullfile(path,'QC', files{c}));
[row, column] = find(ismissing(tables.(['T', num2str(c)])));
for r = 1:length(row)
tables.(['T', num2str(c)])(row(r),column(r)) = {0};
end
NrSweeps = sum(~any(ismissing(tables.(['T', num2str(c)])(:,4:end)),2));
logic_matrix(c,:) = 1-(sum(table2array(...
tables.(['T', num2str(c)])(:,4:end)))/NrSweeps);
end
figure('Position',[0 0 300 1000]);
imagesc(logic_matrix);set(gcf,'color','w');
xlabel('QC criteria')
xticks(1:11)
xticklabels({'stRMSE pre' 'stRMSE post' 'ltRMSE pre' 'ltRMSE post' 'diffVrest' ...
'Vrest abs' 'holdingI' 'betweenSweep' 'bridge_balance_abs' ...
'bridge_balance_rela' 'bad spikes' 'man TP review'})
xtickangle(45)
colorbar
colormap('gray');
box off
exportgraphics(gcf,fullfile(path, 'QC', 'QCheatmap.png'))
%%
end