-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanWrapper3.m
230 lines (161 loc) · 6.38 KB
/
cleanWrapper3.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
%% Pipe wrapper3
% Change root to whatever mouse you want to run
% Check for registration issues before running these and proceeding w
% analysis
% Must have output from Suite2p to run all below functions
%% %% get dFF calculations - RUN AFTER SUITE2P + CELL CLICKING!
root ='Z:\AFdata\2p2019\Experiments\I03'; %% as character
ext = 'Fall.mat';
stimdir = findFILE(root,ext);
stimDirs=stimdir(17:end);
time_window=20;
percentile=30;
for ii=1:length(stimDirs)
dffCalc(stimDirs{ii},percentile,time_window); %%%%%%%%%%%%%dsNidaq saving 5000 fewer pulses??????????????????
end
%% Generate plots
ext = 'dff.mat';
stimdir = findFILE(root,ext);
stimDirs=stimdir(:);
for ii=1:length(stimDirs)
generateCellPlots(stimDirs{ii},5); %change to be just stim path
end
%which orientation was rewarded**
%plot line at first lick on trial by trial basis
%average licking and running rate per orientation - on graph in behavior plots?
%% find drivenness - below functions do not save output, workspace output only
ext = 'stim.mat';
stimdir = findFilePathAF(root,ext);
stimDirs=stimdir(4);
for ii=1:length(stimDirs)
[dffTrials,baselineTrials, statsT, statsW]=separateByTrials(stimDirs(ii))
end
bias200226=biasDet(dffTrials200226,baselineTrials2002226,statsW200226)
sum(suite2pData.statsT.h.Trials0)
sum(suite2pData.statsT.h.Trials90)
sum(suite2pData.statsT.h.Trials225)
root ='Z:\AFdata\2p2019\B02'; %% as character
ext = 'eye_area.mat';
stimdir = findFILE(root,ext);
eyeDirs=stimdir(:);
[allDataB02,B02,eyeDataB02,motSVDB02,x1,x2]=crossDayBehavior(eyeDirs)
% figure
% plot(allData.B02_210315_001_dsNidaq.licking)
%
% nansum(B02.B02_210315_001_dsNidaq.licking,2)
daysidx=fieldnames(B02)
for ii= 1:length(daysidx)
totalLicks(ii)=nansum(allDataB02.(daysidx{ii}).licking)
totalRunning(ii)=nansum(allDataB02.(daysidx{ii}).runVel)
for kk=1:length(B02.(daysidx{ii}).orisUsed)
tempTrialidx=B02.(daysidx{ii}).trialIdx(kk,:)'
tempTrialidx = tempTrialidx(~isnan(tempTrialidx))
% test(1:length(tempTrialidx),:)= W10.(daysidx{ii}).licking(tempTrialidx,:)
B02.(daysidx{ii}).runningByTrial(kk,1:length(tempTrialidx))=nansum(B02.(daysidx{ii}).running(tempTrialidx,:),2)
B02.(daysidx{ii}).runningbyTrialpostStim(kk,1:length(tempTrialidx))=nansum(B02.(daysidx{ii}).running(tempTrialidx,x1:end),2)
B02.(daysidx{ii}).lickingbyTrial(kk,1:length(tempTrialidx))=nansum(B02.(daysidx{ii}).licking(tempTrialidx,:),2)
B02.(daysidx{ii}).lickingbyTrialpostStim(kk,1:length(tempTrialidx))=nansum(B02.(daysidx{ii}).licking(tempTrialidx,x1:end),2)
end
end
runningbyOri=[]
lickingbyOri=[]
for ii=1:7
temp=sum(B02.(daysidx{ii}).runningByTrial,2)'
offsetRun=sum(B02.(daysidx{ii}).runningbyTrialpostStim,2)'
temp=[temp offsetRun]
runningbyOri=[runningbyOri;temp]
temp2=nansum(B02.(daysidx{ii}).lickingbyTrial,2)'
offsetRunL=nansum(B02.(daysidx{ii}).lickingbyTrialpostStim,2)'
temp2=[temp2 offsetRunL]
lickingbyOri=[lickingbyOri;temp2];
clear temp offsetRun offsetRunL temp2
end
allRun=sum(runningbyOri,2)'
restofRunning=totalRunning-(allRun)
runningbyOri=[runningbyOri restofRunning']
allLick=sum(lickingbyOri,2)'
restofLick=totalLicks-(allLick)
lickingbyOri=[lickingbyOri restofLick']
% figure
% bar(runningbyOri)
%
% bar(runningbyOri,'stacked')
totalbiasR=NaN(7,7)
totalbiasL=NaN(7,7)
totalbiasR=sum(runningbyOri(1:3,:))
totalbiasL=sum(lickingbyOri(1:3,:))
%
% totalbiasR(isnan(totalbiasR=[]))
% totalbiasR = totalbiasR(~isnan(totalbiasR))
for ii=1:length(daysidx)
for kk=1:3
runningBias(kk,ii)=runningbyOri(kk,ii)/totalLicks(ii)
lickingBias(kk,ii)=lickingbyOri(kk,ii)/totalRunning(ii)
end
end
figure
bar(lickingBias')
title('B02 lick response by stimulus')
xt = get(gca, 'XTick');
set(gca, 'XTick', xt, 'XTickLabel', {'Day 1 App' 'Day 2 App' 'Day 3 app' 'Day 4 App' 'Day 1 Av' 'Day 2 Av' 'Day3 Av' })
xtickangle(-45)
label = {'App Visstim (0deg)' 'Aversive Visstim (90deg)' 'Neutral Visstim (225deg)'};
legend(label,'FontSize',7,'Location','bestoutside')
figure
bar(
% runningBias=char(runningBias)
%
% A(strcmp(A, 'None')) = {NaN};
% cell2mat(A)
% ... and credits to Stephen Cobeldick for providing the general solution (for any string):
% A(~cellfun(@isnumeric,A)) = {NaN}
figure
sgtitle('Running and Licking Response during all Trial Types - B02')
subplot(2,1,1)
b=bar(runningbyOri)
b(1).FaceColor = [0 0 1];
b(2).FaceColor = [1 0 0];
b(3).FaceColor = [0 1 0];
b(4).FaceColor = [0 .2 .80];
b(5).FaceColor = [.80 .2 0];
b(6).FaceColor = [.1 .8 .1];
b(7).FaceColor = [.5 .5 .5];
title('total running during trial times')
xt = get(gca, 'XTick');
set(gca, 'XTick', xt, 'XTickLabel', {'Day 1 App' 'Day 2 App' 'Day 3 app' 'Day 4 App' 'Day 1 Av' 'Day 2 Av' 'Day3 Av' })
xtickangle(-45)
label = {'App Visstim (0deg)' 'Aversive Visstim (90deg)' 'Neutral Visstim (225deg)' 'App Visstim PostTrial(0deg)' 'Aversive Visstim PostTrial(90deg)' 'Neutral VisstimPostTrial (225deg)' 'Baseline/all other total response'};
legend(label,'FontSize',7,'Location','bestoutside')
subplot(2,1,2)
b2=bar(lickingbyOri)
b2(1).FaceColor = [0 0 1];
b2(2).FaceColor = [1 0 0];
b2(3).FaceColor = [0 1 0];
b2(4).FaceColor = [0 .2 .80];
b2(5).FaceColor = [.80 .2 0];
b2(6).FaceColor = [.1 .8 .1];
b2(7).FaceColor = [.5 .5 .5];title('total licking during trial times')
xt = get(gca, 'XTick');
set(gca, 'XTick', xt, 'XTickLabel', {'Day 1 App' 'Day 2 App' 'Day 3 app' 'Day 4 App' 'Day 1 Av' 'Day 2 Av' 'Day3 Av' })
xtickangle(-45)
label = {'App Visstim (0deg)' 'Aversive Visstim (90deg)' 'Neutral Visstim (225deg)' 'App Visstim PostTrial(0deg)' 'Aversive Visstim PostTrial(90deg)' 'Neutral VisstimPostTrial (225deg)' 'Baseline/all other total response'};
legend(label,'FontSize',7,'Location','bestoutside')
figure
slope of last 10 frames before onset
text(1:length(runningBias),runningBias,num2str(runningBias'),'vert','bottom','horiz','center');
box off
subplot(3,1,3)
axis off
yd = get(hBar, 'YData');
D = randi(10, 5, 3);
figure(1)
hBar = bar(D, 'stacked');
xt = get(gca, 'XTick');
set(gca, 'XTick', xt, 'XTickLabel', {'Machine 1' 'Machine 2' 'Machine 3' 'Machine 4' 'Machine 5'})
yd = get(hBar, 'YData');
yjob = {'Job A' 'Job B' 'Job C'};
barbase = cumsum([zeros(size(D,1),1) D(:,1:end-1)],2);
joblblpos = D/2 + barbase;
for k1 = 1:size(D,1)
text(xt(k1)*ones(1,size(D,2)), joblblpos(k1,:), yjob, 'HorizontalAlignment','center')
end