-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain_dendrites_preprocessing.m
More file actions
263 lines (186 loc) · 8.72 KB
/
Copy pathMain_dendrites_preprocessing.m
File metadata and controls
263 lines (186 loc) · 8.72 KB
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
%% RUN this to load and save responses to drifting gratings (new datasets only)
clear;
addpath('C:\Users\Federico\Documents\GitHub\cameraLucida\db');
% make_db_dendrite_ablation; % master database of orientation tuning recordings
make_db_dendrite_iGluSnFR_GCaMP; % master database of orientation tuning recordings
addpath('\\zserver.cortexlab.net\Code\Neuropil Correction\');
addpath('E:\Google Drive\Science\Carandini_Lab\CarandiniLab_MATLAB\FedericoBox\2P');
addpath('E:\Google Drive\Science\Carandini_Lab\CarandiniLab_MATLAB\FedericoBox\2P\PresynapticNetwoks');
nDb = numel(db);
%% load and save 2 separate mat files in the target folder: gratings and gratings_cut
for iDb = 16
ops.saveDir = 'D:\OneDrive - University College London\Data\Dendrites';
ops.doLoad = 0;
ops.expType = '';
[resp(iDb), dF, frameTimes, recDateExp] = poolOri(db(iDb), ops);
if exist('db_abl')
ops.expType = '_abl';
if ~isempty(db_abl(iDb).animal)
[resp_abl(iDb), dF_abl, frameTimes_abl, recDateExp_abl] = poolOri(db_abl(iDb), ops);
end
end
% figure;
% subplot(2,1,1)
% F0_neu = [resp(iDb).F0_neu, resp_abl(iDb).F0_neu]; plot(F0_neu)
% subplot(2,1,2)
% F0 = [resp(iDb).F0, resp_abl(iDb).F0]; plot(F0)
end
% plotSweepResp_LFR(resp_abl(iDb).allResp(:, :,:), resp_abl(iDb).time, 2);
for iDb = 16
plotSweepResp_LFR(resp(iDb).allResp(:, :,:), resp(iDb).time, 2);
end
%% plot
maxT = max(cellfun(@max, cat(2, frameTimes_abl,frameTimes)));
maxF = max(cellfun(@max, cat(2, dF_abl,dF)));
figure;
date = unique(recDateExp, 'rows');
date_abl = unique(recDateExp_abl, 'rows');
nCol = 2; nRows = max(size(date,1), size(date_abl,1));
for iR = 1: size(date,1)
session = ismember(recDateExp, date(iR,:), 'rows');
thisF = cat(1, dF{session});
whichS = find(session);
if numel(whichS)>1
for iS = 2:numel(whichS)
frameTimes{whichS(iS)} = frameTimes{whichS(iS)} - ...
frameTimes{whichS(iS)}(1) + frameTimes{whichS(iS-1)}(end)...
+mean(diff( frameTimes{whichS(iS-1)}));
end
end
thisFrameTimes = cat(2, frameTimes{session});
subplot(nRows, nCol,(iR-1)*2 +1)
plot(thisFrameTimes, gaussFilt(calcium.highpassF(thisF, 3, 0.001),2))
xlim([50 600])
ylim([-0.5 2])
formatAxes;
title(sprintf(date(iR,:)));
end
for iR = 1: size(date_abl,1)
session = ismember(recDateExp_abl, date_abl(iR,:), 'rows');
thisF = cat(1, dF_abl{session});
whichS = find(session);
if numel(whichS)>1
for iS = 2:numel(whichS)
frameTimes_abl{whichS(iS)} = frameTimes_abl{whichS(iS)} - ...
frameTimes_abl{whichS(iS)}(1) + frameTimes_abl{whichS(iS-1)}(end)...
+mean(diff( frameTimes_abl{whichS(iS-1)}));
end
end
thisFrameTimes = cat(2, frameTimes_abl{session});
subplot(nRows, nCol,iR*2)
plot(thisFrameTimes, gaussFilt(calcium.highpassF(thisF, 3, 0.001),2))
xlim([50 600])
ylim([-0.5 2])
formatAxes;
title(sprintf(date_abl(iR,:)));
end
%% RUN this to load and save retinotopic mapping data
clear;
addpath('C:\Users\Federico\Documents\GitHub\Dbs\V1_dendrites');
dataRchive = 'D:\OneDrive - University College London\Data\Dendrites';
db_V1_dendrites;
db_den = db; clear db;
% noDir = ~isnan([dbRet_all.prefDir]);
nDb = numel(db_den);
for iDb = 18%nDb
try
% root = 'C:\Users\Federico\Google Drive\CarandiniLab\CarandiniLab_MATLAB\Data\rvRetinotopy';
% saveDir = fullfile(root, db_den(iDb).morph.expRef{1});
root ='\\zserver.cortexlab.net\Lab\Share\Naureen';
saveDir = fullfile(root, sprintf('%s_%d', db_den(iDb).animal, db_den(iDb).neuron_id));
grat = load(fullfile(saveDir,...
[sprintf('%s_%d_orientationTuning',db_den(iDb).animal, db_den(iDb).neuron_id)]),...
'responses', 'aveResp', 'seResp', 'kernelTime', 'stimDur', 'stimLabels', ...
'aveAllResPeak', 'seAllResPeak', 'aveAllResp', 'seAllResp', 'tunePars', ...
'allResp', 'allResPeak');
allResp = squeeze(grat.allResp);
allPeaks = squeeze(grat.allResPeak);
[nStim, nRep, ~] = size(allResp);
aveResp = squeeze(nanmean(allResp, 2));
seResp = squeeze(nanstd(allResp, 1,2)/sqrt(nRep));
avePeak = squeeze(mean(allPeaks, 2));
sePeak = squeeze(std(allPeaks, 1, 2)/sqrt(nRep));
time = grat.kernelTime{1};
dirs = 0:30:330;
aveOriPeak = mean(cat(2, allPeaks(1:6, :), allPeaks(7:12, :)),2);
seOriPeak = std(cat(2, allPeaks(1:6, :), allPeaks(7:12, :)),[], 2)/sqrt(nRep*2);
oris = dirs;
oris(oris>=180) = oris(oris>=180)-180;
file = sprintf('%s_%d_gratings.mat', db_den(iDb).animal, db_den(iDb).neuron_id);
targetFolder = fullfile(dataRchive, sprintf('%s_%d', db_den(iDb).animal, db_den(iDb).neuron_id));
save(fullfile(targetFolder, file),...
'aveResp', 'seResp', 'time', 'allResp', 'allPeaks', 'avePeak',...
'sePeak', 'dirs', 'oris', 'aveOriPeak', 'seOriPeak');
catch
% load(fullfile(targetFolder,'tune.mat'));
% aveResp
% seResp
% time
% allResp
% allResPeak
% avePeak
% sePeak
% dirs
% oris
% aveOriPeak
% seOriPeak
warning('%s_%d', db_den(iDb).animal, db_den(iDb).neuron_id);
end
end
%% RUN this to load and save retinotopic mapping data
clear;
addpath('C:\Users\Federico\Documents\GitHub\Dbs\V1_dendrites');
dataRchive = 'D:\OneDrive - University College London\Data\Dendrites';
db_V1_dendrites;
db_den = db; clear db;
% noDir = ~isnan([dbRet_all.prefDir]);
nDb = numel(db_den);
for iDb = 49
expID = db_den(iDb).retino.expID;
try
% root = 'C:\Users\Federico\Google Drive\CarandiniLab\CarandiniLab_MATLAB\Data\rvRetinotopy';
% retDir = fullfile(root, db_den(iDb).morph.expRef{1});
root ='\\zserver.cortexlab.net\Lab\Share\Naureen';
retDir = fullfile(root, sprintf('%s_%d', db_den(iDb).animal, db_den(iDb).neuron_id));
file = sprintf('%s_%d_neuRF_column_svd.mat', db_den(iDb).animal, db_den(iDb).neuron_id);
% retino = load(fullfile(retDir, file), 'retX', 'retY', 'micronsX', 'micronsY');
retino = load(fullfile(retDir, file));
micronsX = retino.dbVis.micronsX;
micronsY = retino.dbVis.micronsY;
retX = retino.dbVis.retX;
retY = retino.dbVis.retY;
catch
root = 'D:\OneDrive - University College London\Data\2P';
retDir = fullfile(root, db_den(iDb).retino.expRef{1}, db_den(iDb).retino.expRef{2}, num2str(db_den(iDb).retino.expRef{3}));
file = sprintf('%s_%s_%d_fovRetinotopy.mat', db_den(iDb).retino.expRef{1}, db_den(iDb).retino.expRef{2}, db_den(iDb).retino.expRef{3});
retino = load(fullfile(retDir, file), 'retX', 'retY', 'micronsX', 'micronsY');
micronsX = retino.micronsX;
micronsY = retino.micronsY;
retX = retino.retX;
retY = retino.retY;
warning('%s_%d not found in Naureen/Data', db_den(iDb).animal, db_den(iDb).neuron_id);
end
% info = ppbox.infoPopulateTempLFR(db(expID).mouse_name, db(expID).date, db(expID).expts(db(expID).expID));
% [micronsX, micronsY, ~] = ppbox.getPxXYZ(info);
file = sprintf('%s_%d_retinotopy.mat', db_den(iDb).animal, db_den(iDb).neuron_id);
targetFolder = fullfile(dataRchive, sprintf('%s_%d', db_den(iDb).animal, db_den(iDb).neuron_id));
save(fullfile(targetFolder,file), 'micronsX', 'micronsY', 'retX', 'retY');
end
%% save imaging planes of soma
clear;
addpath('C:\Users\Federico\Documents\GitHub\regIm2Vol');
addpath('C:\Users\Federico\Documents\GitHub\regIm2Vol\rigid');
addpath('C:\Users\Federico\Documents\GitHub\regIm2Vol\nonrigid');
addpath(genpath('C:\Users\Federico\Documents\GitHub\Rigbox'));
addpath('C:\Users\Federico\Documents\GitHub\Suite2P_Matlab\tiffTools\');
addpath('C:\Users\Federico\Documents\GitHub\Suite2P_Matlab\registration\');
addpath(genpath('C:\Users\Federico\Documents\GitHub\FedBox'));
addpath('C:\Users\Federico\Documents\GitHub\Suite2P_Matlab\utils')
%% expref of functional imaging planes
plane.subject = 'FR237';
plane.date = '2023-05-11'; % date of functional experiment
plane.expts = [1];% which experiment were functional imaging plane = getImgInfo(planes);
plane = populatePaths(plane);
plane = populateImgInfo(plane);
plane = loadMimgPlanes(plane);
% saveastiff(plane.mimgG, 'FR237_1_2023-05-10_1.tiff')