-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserKillScriptTorben.m
490 lines (423 loc) · 19.9 KB
/
UserKillScriptTorben.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
%Behavior analysis Olf2AFC
function UserKillScriptTorben
global BpodSystem
%load mail settings --> contains mail address & password & evernote e-mail address
load('MailSettings.mat');%loads MailSettings struct
%evernote mail address
MailAddress = MailSettings.EvernoteMail;
%save figure
FigureFolder = fullfile(fileparts(fileparts(BpodSystem.DataPath)),'Session Figures');
FigureHandle = BpodSystem.GUIHandles.OutcomePlot.HandleOutcome.Parent;
FigureString = get(FigureHandle,'Name');
[~, FigureName] = fileparts(BpodSystem.DataPath);
if ~isdir(FigureFolder)
mkdir(FigureFolder);
end
FigurePath = fullfile(FigureFolder,[FigureName,'.png']);
saveas(FigureHandle,FigurePath,'png');
%Analysis
try
FigAnalysis = Analysis();
FigurePathAnalysis = fullfile(FigureFolder,[FigureName,'Analysis.png']);
saveas(FigAnalysis,FigurePathAnalysis,'png');
close(FigAnalysis);
DidAnalysis = true;
catch
DidAnalysis = false;
end
%send email
[x,sessionfile] = fileparts(BpodSystem.DataPath);
[~,animal] = fileparts(fileparts(fileparts(x)));
Subject = strcat(sessionfile,'@',animal);
Body = sessionfile;
if DidAnalysis
Attachment = {FigurePath,FigurePathAnalysis};
else
Attachment = {FigurePath};
end
sent = SendMyMail(MailSettings,MailAddress,Subject,Body,Attachment);
if sent
fprintf('Figure "%s" sent to %s.\n',FigureString,MailAddress);
else
fprintf('Error:SendFigureTo:Mail could not be sent to %s.\n',MailAddress);
end
%% copy data to server
try
%%%%%
%os
os = getenv('OS');
if strcmpi(os(1:min(7,length(os))),'windows')
[~,result]=system('ipconfig');
if contains(result,'172') || contains(result,'wustl') %%-->WUSTL address space
servername = '\\172.20.22.201\home';
else %--> CSHL address space
servername = '\\uncertainty.cshl.edu\home'; %new uncertanity server (8/2018) works with home only
end
% user = strcat(getenv('username'));
user ='';
else
servername = '/media/';
user='torben';
end
[~,subject] = fileparts(fileparts(fileparts(fileparts(BpodSystem.DataPath))));
if ~isdir(fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Data'))
mkdir(fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Data'));
end
if ~isdir(fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Settings'))
mkdir(fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Settings'));
end
copyfile(BpodSystem.DataPath,fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Data'));
copyfile(BpodSystem.SettingsPath,fullfile(servername,user,'BpodData',subject,BpodSystem.CurrentProtocolName,'Session Settings'));
catch
fprintf('Error copying data to server. Files not copied!\n');
end
end
function FigHandle = Analysis()
global TaskParameters
global BpodSystem
GracePeriodsMax = TaskParameters.GUI.FeedbackDelayGrace; %assumes same for each trial
StimTime = TaskParameters.GUI.AuditoryStimulusTime; %assumes same for each trial
MinWT = TaskParameters.GUI.VevaiometricMinWT; %assumes same for each trial
MaxWT = 10;
AudBin = 8; %Bins for psychometric
AudBinWT = 6;%Bins for vevaiometric
windowCTA = 150; %window for CTA (ms)
[~,Animal]=fileparts(fileparts(fileparts(fileparts(BpodSystem.DataPath))));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nTrials=BpodSystem.Data.nTrials;
DV = BpodSystem.Data.Custom.DV(1:nTrials-1);
ChoiceLeft = BpodSystem.Data.Custom.ChoiceLeft(1:nTrials-1);
ST = BpodSystem.Data.Custom.ST(1:nTrials-1);
CatchTrial = BpodSystem.Data.Custom.CatchTrial((1:nTrials-1));
Feedback = BpodSystem.Data.Custom.Feedback(1:nTrials-1);
Correct = BpodSystem.Data.Custom.ChoiceCorrect(1:nTrials-1);
WT = BpodSystem.Data.Custom.FeedbackTime(1:nTrials-1);
if isfield(BpodSystem.Data.Custom,'LaserTrial')
LaserTrial = BpodSystem.Data.Custom.LaserTrial(1:nTrials-1);
else
LaserTrial=false(1,nTrials);
end
%define "completed trial"
% not that abvious for errors
%Correct vector is 1 for correct choice, 0 for incorrect choice, nan
%for no choice
%now: correct --> received feedback (reward)
% error --> always (if error catch)
% catch --> always (if choice happened)
CompletedTrials = (Feedback&Correct==1) | (Correct==0) | CatchTrial&~isnan(ChoiceLeft);
nTrialsCompleted = sum(CompletedTrials);
%calculate exerienced dv
ExperiencedDV=zeros(1,length(ST));
%click task
if TaskParameters.GUI.AuditoryStimulusType == 1 %click
LeftClickTrain = BpodSystem.Data.Custom.LeftClickTrain(1:nTrials-1);
RightClickTrain = BpodSystem.Data.Custom.RightClickTrain(1:nTrials-1);
for t = 1 : length(ST)
R = BpodSystem.Data.Custom.RightClickTrain{t};
L = BpodSystem.Data.Custom.LeftClickTrain{t};
Ri = sum(R<=ST(t));if Ri==0, Ri=1; end
Li = sum(L<=ST(t));if Li==0, Li=1; end
ExperiencedDV(t) = log10(Li/Ri);
% ExperiencedDV(t) = (Li-Ri)./(Li+Ri);
end
elseif TaskParameters.GUI.AuditoryStimulusType == 2 %freq
LevelsLow = 1:ceil(TaskParameters.GUI.Aud_nFreq/3);
LevelsHigh = ceil(TaskParameters.GUI.Aud_nFreq*2/3)+1:TaskParameters.GUI.Aud_nFreq;
AudCloud = BpodSystem.Data.Custom.AudCloud(1:nTrials-1);
for t = 1 : length(ST)
NLow = sum(ismember(AudCloud{t},LevelsLow)); if NLow==0, NLow=1; end
NHigh = sum(ismember(AudCloud{t},LevelsHigh)); if NHigh==0, NHigh=1; end
ExperiencedDV(t) = log10(NHigh/NLow);
end
end
%caclulate grace periods
GracePeriods=[];
GracePeriodsL=[];
GracePeriodsR=[];
for t = 1 : length(ST)
GracePeriods = [GracePeriods;BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Rin_grace(:,2)-BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Rin_grace(:,1);BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Lin_grace(:,2)-BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Lin_grace(:,1)];
if ChoiceLeft(t) == 1
GracePeriodsL = [GracePeriodsL;BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Lin_grace(:,2)-BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Lin_grace(:,1)];
elseif ChoiceLeft(t)==0
GracePeriodsR = [GracePeriodsR;BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Rin_grace(:,2)-BpodSystem.Data.RawEvents.Trial{t}.States.rewarded_Rin_grace(:,1)];
end
end
CompletedTrials = CompletedTrials==1;
CatchTrial = CatchTrial==1;
%laser trials?
if sum(LaserTrial)>0
LaserCond = [false;true];
else
LaserCond=false;
end
CondColors={[0,0,0],[.9,.1,.1]};
%%
FigHandle = figure('Position',[ 360 187 1056 598],'NumberTitle','off','Name',Animal);
% ExperiencedDV=DV;
%Psychometric
subplot(3,4,1)
hold on
for i = 1:length(LaserCond)
CompletedTrialsCond = CompletedTrials & LaserTrial == LaserCond(i);
AudDV = ExperiencedDV(CompletedTrialsCond);
if ~isempty(AudDV)
BinIdx = discretize(AudDV,linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,AudBin+1));
PsycY = grpstats(ChoiceLeft(CompletedTrialsCond),BinIdx,'mean');
PsycX = grpstats(ExperiencedDV(CompletedTrialsCond),BinIdx,'mean');
plot(PsycX,PsycY,'ok','MarkerFaceColor',CondColors{i},'MarkerEdgeColor','w','MarkerSize',6)
XFit = linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100);
YFit = glmval(glmfit(AudDV,ChoiceLeft(CompletedTrialsCond)','binomial'),linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100),'logit');
plot(XFit,YFit,'Color',CondColors{i});
xlabel('DV');ylabel('p left')
text(0.95*min(get(gca,'XLim')),0.96*max(get(gca,'YLim')),[num2str(round(nanmean(Correct(CompletedTrialsCond))*100)),'%,n=',num2str(nTrialsCompleted)]);
end
end
%conditioned psychometric
subplot(3,4,2)
hold on
%low
WTmed=median(WT(CompletedTrials&CatchTrial&WT>MinWT&WT<MaxWT));
AudDV = ExperiencedDV(CompletedTrials&CatchTrial&WT<=WTmed&WT>MinWT);
if ~isempty(AudDV)
ChoiceLeftadj = ChoiceLeft(CompletedTrials&CatchTrial&WT<=WTmed&WT>MinWT);
BinIdx = discretize(AudDV,linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,AudBin+1));
PsycY = grpstats(ChoiceLeftadj,BinIdx,'mean');
PsycX = grpstats(AudDV,BinIdx,'mean');
h1=plot(PsycX,PsycY,'ok','MarkerFaceColor',[.5,.5,.5],'MarkerEdgeColor','w','MarkerSize',6);
XFit = linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100);
YFit = glmval(glmfit(AudDV,ChoiceLeftadj','binomial'),linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100),'logit');
plot(XFit,YFit,'Color',[.5,.5,.5]);
%high
AudDV = ExperiencedDV(CompletedTrials&CatchTrial&WT>WTmed&WT<MaxWT);
ChoiceLeftadj = ChoiceLeft(CompletedTrials&CatchTrial&WT>WTmed&WT<MaxWT);
BinIdx = discretize(AudDV,linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,AudBin+1));
PsycY = grpstats(ChoiceLeftadj,BinIdx,'mean');
PsycX = grpstats(AudDV,BinIdx,'mean');
h2=plot(PsycX,PsycY,'ok','MarkerFaceColor','k','MarkerEdgeColor','w','MarkerSize',6);
XFit = linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100);
YFit = glmval(glmfit(AudDV,ChoiceLeftadj','binomial'),linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,100),'logit');
plot(XFit,YFit,'k');
xlabel('DV');ylabel('p left')
legend([h2,h1],{['WT>',num2str(round(WTmed*100)/100)],['WT<',num2str(round(WTmed*100)/100)]},'Units','normalized','Position',[0.333,0.85,0.1,0.1])
end
%calibration
subplot(3,4,3)
hold on
xlabel('Waiting time (s)');ylabel('p correct')
WTBin=5;
ColorsCorrect = {[.1,.9,.1],[.1,.8,.6]};
ColorsError = {[.9,.1,.1],[.9,.1,.6]};
for i =1:length(LaserCond)
WTCatch = WT(CompletedTrials&CatchTrial&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i));
if ~isempty(WTCatch)
BinIdx = discretize(WTCatch,linspace(min(WTCatch)-10*eps,max(WTCatch)+10*eps,WTBin+1));
WTX = grpstats(WTCatch,BinIdx,'mean');
PerfY = grpstats(Correct(CompletedTrials&CatchTrial&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i)),BinIdx,'mean');
plot(WTX,PerfY,'Color',CondColors{i},'LineWidth',2);
[r,p]=corr(WTCatch',Correct(CompletedTrials&CatchTrial&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i))','type','Spearman');
text(min(get(gca,'XLim'))+0.05,max(get(gca,'YLim'))-0.07*i,['r=',num2str(round(r*100)/100),', p=',num2str(round(p*100)/100)],'Color',CondColors{i});
end
end
%Vevaiometric
subplot(3,4,4)
hold on
xlabel('DV');ylabel('Waiting time (s)')
AudDV = ExperiencedDV(CompletedTrials&CatchTrial&WT<MaxWT&WT>MinWT);
Rcatch=cell(1,2);Pcatch=cell(1,2);Rerror=cell(1,2);Perror=cell(1,2);
%for confidence auc
auc = nan(length(LaserCond),1);
auc_sem = nan(length(LaserCond),1);
for i =1:length(LaserCond)
WTCatch = WT(CompletedTrials&CatchTrial&Correct==1&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i));
DVCatch = ExperiencedDV(CompletedTrials&CatchTrial&Correct==1&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i));
if ~isempty(DVCatch)
BinIdx = discretize(DVCatch,linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,AudBinWT+1));
if ~all(isnan(BinIdx))
WTCatchY = grpstats(WTCatch,BinIdx,'mean');
DVCatchX = grpstats(DVCatch,BinIdx,'mean');
plot(DVCatchX,WTCatchY,'Color',ColorsCorrect{i},'LineWidth',2)
end
WTError = WT(CompletedTrials&Correct==0&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i));
DVError = ExperiencedDV(CompletedTrials&Correct==0&WT>MinWT&WT<MaxWT & LaserTrial==LaserCond(i));
BinIdx = discretize(DVError,linspace(min(AudDV)-10*eps,max(AudDV)+10*eps,AudBinWT+1));
if ~all(isnan(BinIdx))
WTErrorY = grpstats(WTError,BinIdx,'mean');
DVErrorX = grpstats(DVError,BinIdx,'mean');
plot(DVErrorX,WTErrorY,'Color',ColorsError{i},'LineWidth',2)
end
plot(DVCatch,WTCatch,'o','MarkerSize',2,'MarkerFaceColor',ColorsCorrect{i},'Color',ColorsCorrect{i})
plot(DVError,WTError,'o','MarkerSize',2,'MarkerFaceColor',ColorsError{i},'Color',ColorsError{i})
legend('Correct Catch','Error','Location','best')
%evaluate vevaiometric
[Rc,Pc] = EvaluateVevaiometric(DVCatch,WTCatch);
[Re,Pe] = EvaluateVevaiometric(DVError,WTError);
Rcatch{i}=Rc;Pcatch{i}=Pc;Rerror{i}=Re;Perror{i}=Pe;
%confidence auc
[auc(i),~,auc_sem(i)] = rocarea_torben(WTCatch,WTError,'bootstrap',200);
end
end
for i =1:length(LaserCond)
if ~isempty(Rcatch{i}) && ~isempty(Pcatch{i}) && ~isempty(Rerror{i}) && ~isempty(Perror{i})
unit = max(get(gca,'YLim'))-min(get(gca,'YLim'));
text(max(get(gca,'XLim'))+0.03,max(get(gca,'YLim'))-unit*(0.1+(i-1)*.5),['r_l=',num2str(round(Rcatch{i}(1)*100)/100),' r_r=',num2str(round(Rcatch{i}(2)*100)/100)],'Color',ColorsCorrect{i});
text(max(get(gca,'XLim'))+0.03,max(get(gca,'YLim'))-unit*(0.2+(i-1)*.5),['r=',num2str(round(Rcatch{i}(3)*100)/100),', p=',num2str(round(Pcatch{i}(3)*100)/100)],'Color',ColorsCorrect{i});
text(max(get(gca,'XLim'))+0.03,max(get(gca,'YLim'))-unit*(0.3+(i-1)*.5),['r_l=',num2str(round(Rerror{i}(1)*100)/100),' r_r=',num2str(round(Rerror{i}(2)*100)/100)],'Color',ColorsError{i});
text(max(get(gca,'XLim'))+0.03,max(get(gca,'YLim'))-unit*(0.4+(i-1)*.5),['r=',num2str(round(Rerror{i}(3)*100)/100),', p=',num2str(round(Perror{i}(3)*100)/100)],'Color',ColorsError{i});
end
end
%reaction time
panel=subplot(3,4,5);
hold on
if sum(CompletedTrials)>1
center = linspace(min(ST(CompletedTrials)),max(ST(CompletedTrials)),15);
h=hist(ST(CompletedTrials),center);
if ~isempty(h)
h=h/sum(h);
% ylabel('p')
plot(abs(ExperiencedDV(CompletedTrials)),ST(CompletedTrials),'.k');
xlabel('DV');ylabel('Sampling time (s)')
ax2 = axes('Position',panel.Position);panel.Position=ax2.Position;
plot(h,center,'r','LineWidth',2,'Parent',ax2);
ax2.YAxis.Visible='off';ax2.XAxisLocation='top';ax2.Color='none';ax2.XAxis.FontSize = 8;ax2.XAxis.Color=[1,0,0];ax2.XLabel.String = 'p';ax2.XLabel.Position=[0.15,3.1,0];
[r,p]=corr(abs(ExperiencedDV(CompletedTrials&~isnan(ST)))',ST(CompletedTrials&~isnan(ST))','type','Spearman');
text(min(get(gca,'XLim'))+0.05,max(get(gca,'YLim'))-0.1,['r=',num2str(round(r*100)/100),', p=',num2str(round(p*100)/100)]);
end
end
%grace periods
subplot(3,4,6)
%remove "full" grace periods
GracePeriods(GracePeriods>=GracePeriodsMax-0.001 & GracePeriods<=GracePeriodsMax+0.001 )=[];
GracePeriodsR(GracePeriodsR>=GracePeriodsMax-0.001 & GracePeriodsR<=GracePeriodsMax+0.001 )=[];
GracePeriodsL(GracePeriodsL>=GracePeriodsMax-0.001 & GracePeriodsL<=GracePeriodsMax+0.001 )=[];
center = 0:0.025:max(GracePeriods);
if ~all(isnan(GracePeriodsL)) && numel(center) > 1 && ~all(isnan(GracePeriodsR))
g = hist(GracePeriods,center);g=g/sum(g);
gl = hist(GracePeriodsL,center);gl=gl/sum(gl);
gr = hist(GracePeriodsR,center);gr=gr/sum(gr);
hold on
plot(center,g,'k','LineWidth',2)
plot(center,gl,'m','LineWidth',1)
plot(center,gr,'c','LineWidth',1)
xlabel('Grace period (s)');ylabel('p');
text(min(get(gca,'XLim'))+0.05,max(get(gca,'YLim'))-0.05,['n=',num2str(sum(~isnan(GracePeriods))),'(',num2str(sum(~isnan(GracePeriodsL))),'/',num2str(sum(~isnan(GracePeriodsR))),')']);
end
%waiting time distributions
ColorsCond = {[.5,.5,.5],[.9,.1,.1]};
if length(LaserCond)==1
%no laser
subplot(3,4,7)
hold on
xlabel('waiting time (s)'); ylabel ('n trials');
WTnoFeedbackL = WT(~Feedback & ChoiceLeft == 1);
WTnoFeedbackR = WT(~Feedback & ChoiceLeft == 0);
histogram(WTnoFeedbackL,10,'EdgeColor','none','FaceColor',[.2,.2,1]);
histogram(WTnoFeedbackR,10,'EdgeColor','none','FaceColor',[.8,.6,.1]);
meanWTL = nanmean(WTnoFeedbackL);
meanWTR = nanmean(WTnoFeedbackR);
line([meanWTL,meanWTL],get(gca,'YLim'),'Color',[.2,.2,1]);
line([meanWTR,meanWTR],get(gca,'YLim'),'Color',[.8,.6,.1]);
text(meanWTL-1,1.05*(max(get(gca,'YLim'))-min(get(gca,'YLim'))),['m_l=',num2str(round(meanWTL*10)/10)],'Color',[.2,.2,1]);
text(meanWTL-1,1.15*(max(get(gca,'YLim'))-min(get(gca,'YLim'))),['m_r=',num2str(round(meanWTR*10)/10)],'Color',[.8,.6,.1]);
PshortWTL = sum(WTnoFeedbackL<MinWT)/sum(~isnan(WTnoFeedbackL));
PshortWTR = sum(WTnoFeedbackR<MinWT)/sum(~isnan(WTnoFeedbackR));
text(max(get(gca,'XLim'))+0.03,0.85*(max(get(gca,'YLim'))-min(get(gca,'YLim')))+min(get(gca,'YLim')),['L_{2}=',num2str(round(PshortWTL*100)/100),', R_{2}=',num2str(round(PshortWTR*100)/100)],'Color',[0,0,0]);
else%laser
subplot(3,4,7)
hold on
xlabel('waiting time (s)'); ylabel ('n trials');
subplot(3,4,8)
hold on
xlabel('waiting time (s)'); ylabel ('n trials');
PshortWTL=cell(1,2);PshortWTR=cell(1,2);
for i =1:length(LaserCond)
WTnoFeedbackL = WT(~Feedback & ChoiceLeft == 1 & LaserTrial==LaserCond(i));
WTnoFeedbackR = WT(~Feedback & ChoiceLeft == 0 & LaserTrial==LaserCond(i));
meanWTL = nanmean(WTnoFeedbackL);
meanWTR = nanmean(WTnoFeedbackR);
subplot(3,4,7)
histogram(WTnoFeedbackL,10,'EdgeColor','none','FaceColor',ColorsCond{i});
line([meanWTL,meanWTL],get(gca,'YLim'),'Color',ColorsCond{i});
text(meanWTL-1,(1.05-0.1*(i-1))*(max(get(gca,'YLim'))-min(get(gca,'YLim'))),['m_l=',num2str(round(meanWTL*10)/10)],'Color',ColorsCond{i});
subplot(3,4,8)
histogram(WTnoFeedbackR,10,'EdgeColor','none','FaceColor',ColorsCond{i});
line([meanWTR,meanWTR],get(gca,'YLim'),'Color',ColorsCond{i});
text(meanWTL-1,(1.05-0.1*(i-1))*(max(get(gca,'YLim'))-min(get(gca,'YLim'))),['m_r=',num2str(round(meanWTR*10)/10)],'Color',ColorsCond{i});
PshortWTL{i} = sum(WTnoFeedbackL<MinWT)/sum(~isnan(WTnoFeedbackL));
PshortWTR{i} = sum(WTnoFeedbackR<MinWT)/sum(~isnan(WTnoFeedbackR));
end
for i =1:length(LaserCond)
text(max(get(gca,'XLim'))+0.03,(0.85/i)*(max(get(gca,'YLim'))-min(get(gca,'YLim')))+min(get(gca,'YLim')),['L_{2}=',num2str(round(PshortWTL{i}*100)/100),', R_{2}=',num2str(round(PshortWTR{i}*100)/100)],'Color',ColorsCond{i});
end
end
%confidence index
subplot(3,4,9)
hold on
for i =1:length(LaserCond)
errorbar(1:size(auc,2),auc(i,:),auc_sem(i,:),'o','MarkerFaceColor',CondColors{i},'MarkerEdgeColor',CondColors{i},'LineWidth',2,'Color',CondColors{i})
end
xlabel('DV quantile')
ylabel('AUC')
RedoTicks(gcf);
end
function RedoTicks(h)
Chil=get(h,'Children');
for i = 1:length(Chil)
if strcmp(Chil(i).Type,'axes')
set(Chil(i),'TickDir','out','TickLength',[0.03 0.03],'box','off')
end
if strcmp(Chil(i).Type,'legend')
set(Chil(i),'box','off')
end
end
end
% sends mail from Torben's cshl gmail account
% 3 or 4 inputs: address,subject,message,cell with attachment paths
% (each as string)
function sent = SendMyMail(varargin)
sent = false;
MailSettings = varargin{1};
setpref('Internet','E_mail',MailSettings.MailFrom)
setpref('Internet','SMTP_Server','smtp.gmail.com')
setpref('Internet','SMTP_Username',MailSettings.MailFrom)
setpref('Internet','SMTP_Password',MailSettings.MailFromPassword)
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
if length(varargin)==4
try
sendmail(varargin{2},varargin{3},varargin{4})
sent=true;
catch
display('Error:SendMyMail:E-Mail could not be sent.')
end
elseif length(varargin)==5
try
%attachments need to be in full path (not ~) for linux systems
for k =1:length(varargin{5})
if strcmp(varargin{5}{k}(1),'~')
varargin{5}{k} = fullfile('/home/torben',varargin{5}{k}(2:end));
end
end
sendmail(varargin{2},varargin{3},varargin{4},varargin{5})
sent=true;
catch
display('Error:SendMyMail:E-Mail could not be sent.')
end
else
display('Error:SendMyMail:Number of input arguments wrong.')
end
end
function [R,P] = EvaluateVevaiometric(DV,WT)
R = zeros(1,3);
P=zeros(1,3);
if sum(DV<=0)>0
[R(1),P(1)] = corr(DV(DV<=0)',WT(DV<=0)','type','Spearman');
end
if sum(DV>0)>0
[R(2),P(2)] = corr(DV(DV>0)',WT(DV>0)','type','Spearman');
end
if sum(~isnan(DV))>0
[R(3),P(3)] = corr(abs(DV)',WT','type','Spearman');
end
end