forked from lauradriscoll/pre_process_shared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_percent_correct.m
60 lines (50 loc) · 2.29 KB
/
calc_percent_correct.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
%% ATK 220205
% pull out behavioral performance scores for fig
%masterPath = "/media/atk13/Aaron's 5TB HD/ppc/2P_data/";
masterPath = "/Volumes/Aaron's PPC/ppc/2P_data/";
mouse = 'LD187';
mySessions = {'LD187_141216','LD187_141215','LD187_141214','LD187_141213','LD187_141212',...
'LD187_141211','LD187_141210','LD187_141209','LD187_141208','LD187_141207','LD187_141206'};
%mySessions = {'LD187_141211'};
trialTypes = {'newL_trials','bR_trials','wL_trials','newR_trials'};
trialCorrect = struct;
for i = 1:length(mySessions)
session = cell2mat(mySessions(i));
disp(session)
trialCorrect.(session) = struct;
trialCorrect.(session).trialTypes = trialTypes;
% Load trial aligned data
syncedDataDir = fullfile(masterPath, 'code_workspace',mouse,'syncedData');
trialAlignedData = open(fullfile(syncedDataDir,[session '.mat'])).trialAlignedData;
% Calculate success rates
cueType = trialAlignedData.cueType;
choice = trialAlignedData.choice;
isCorrect = trialAlignedData.isCorrect;
for j = 1:length(trialTypes)
numTrials = sum(cueType == j);
numCorrect = sum(isCorrect(cueType == j));
trialCorrect.(session).numTrials(j) = numTrials;
trialCorrect.(session).numCorrect(j) = numCorrect;
if numTrials > 0
trialCorrect.(session).fracCorrect(j) = numCorrect/numTrials;
else
trialCorrect.(session).fracCorrect(j) = nan;
end
end
trialCorrect.(session).allFracCorrect = sum(trialCorrect.(session).numCorrect)/...
sum(trialCorrect.(session).numTrials);
trialCorrect.(session).BWfracCorrect = sum(trialCorrect.(session).numCorrect(2:3))/...
sum(trialCorrect.(session).numTrials(2:3));
end
%% Export data as .mat
output_dir = fullfile('/Users/akuan/Dropbox (HMS)/htem_team/projects/PPC_project/LDMS2_19_r47');
save(fullfile(output_dir,'trialCorrect.mat'),'trialCorrect','-v7.3');
%%
for i = 1:length(mySessions)
session = cell2mat(mySessions(i));
allNumTrials(i, :) = trialCorrect.(session).numTrials;
BWnumTrials(i, :) = sum(trialCorrect.(session).numTrials(2:3));
allNumCorrect(i, :) = trialCorrect.(session).numCorrect;
allFracCorrect(i) = trialCorrect.(session).allFracCorrect;
BWfracCorrect(i) = trialCorrect.(session).BWfracCorrect;
end